Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
Implement `oscal info for oscal:component-definition files
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Jan 20, 2020
1 parent f5f6e2d commit 5f14c1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ var Info = cli.Command{
fmt.Println("ID:\t", o.SystemSecurityPlan.Id)
printMetadata(o.SystemSecurityPlan.Metadata)
return nil
case constants.ComponentDocument:
fmt.Println("OSCAL Component Definition")
printMetadata(o.Component.Metadata)
return nil
case constants.ProfileDocument:
fmt.Println("OSCAL Profile (represents subset of controls from OSCAL catalog(s))")
fmt.Println("ID:\t", o.Profile.Id)
Expand Down
1 change: 1 addition & 0 deletions pkg/oscal/constants/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ const (
CatalogDocument
ProfileDocument
SSPDocument
ComponentDocument
)
11 changes: 11 additions & 0 deletions types/oscal/oscal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/docker/oscalkit/pkg/oscal/constants"
"github.com/docker/oscalkit/types/oscal/catalog"
"github.com/docker/oscalkit/types/oscal/component_definition"
"github.com/docker/oscalkit/types/oscal/profile"
ssp "github.com/docker/oscalkit/types/oscal/system_security_plan"
yaml "gopkg.in/yaml.v2"
Expand All @@ -19,6 +20,7 @@ const (
catalogRootElement = "catalog"
profileRootElement = "profile"
sspRootElement = "system-security-plan"
componentElement = "component-definition"
)

// OSCAL contains specific OSCAL components
Expand All @@ -28,6 +30,7 @@ type OSCAL struct {
// Declarations *Declarations `json:"declarations,omitempty" yaml:"declarations,omitempty"`
Profile *profile.Profile `json:"profile,omitempty" yaml:"profile,omitempty"`
*ssp.SystemSecurityPlan
Component *component_definition.ComponentDefinition
documentType constants.DocumentType
}

Expand All @@ -38,6 +41,8 @@ func (o *OSCAL) DocumentType() constants.DocumentType {
return constants.ProfileDocument
} else if o.SystemSecurityPlan != nil {
return constants.SSPDocument
} else if o.Component != nil {
return constants.ComponentDocument
} else {
return constants.UnknownDocument
}
Expand Down Expand Up @@ -153,6 +158,12 @@ func New(r io.Reader) (*OSCAL, error) {
return nil, err
}
return &OSCAL{SystemSecurityPlan: &ssp}, nil
case componentElement:
var component component_definition.ComponentDefinition
if err := d.DecodeElement(&component, &startElement); err != nil {
return nil, err
}
return &OSCAL{Component: &component}, nil
}
}
}
Expand Down

0 comments on commit 5f14c1d

Please sign in to comment.