This repository was archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Revamp project to work with latest OSCAL #88
Merged
anweiss
merged 110 commits into
docker-archive:master
from
isimluk:fix-metachema-generation
Feb 5, 2020
Merged
Changes from all commits
Commits
Show all changes
110 commits
Select commit
Hold shift + click to select a range
09190f0
Fix metaschema generation capabilities
isimluk 67d76da
Improve error message
isimluk 09a858f
Allow multiple import elements in metaschema XML
isimluk d992881
Allow multiple import in Metaschema struct
isimluk 84a169a
Performance: Use shallow clone of OSCAL.git to speed-up things a bit
isimluk 2a6614e
Avoid using '-' character in go package name
isimluk e5a5981
Parse @ref attribute from field
isimluk 69dcbc0
Implement indirection from field to define-field
isimluk 71c49b8
Remove Assemblies metaschema element
isimluk aac0300
Parse @ref attribute from assembly
isimluk b2a8bc1
Refactor: Use existing method instead of expanding it
isimluk ebb1e54
Implement indirection from assembly to define-assembly
isimluk 2b57abb
Implement plural of assemblies
isimluk d4592a6
Refactor: Extract method: RepresentsRootElement
isimluk 70b63d3
Depend on encoding/xml only when file contains final root element
isimluk b3ea5a7
Refactor: Extract method: RequiresPointer
isimluk 337c1d3
Refactor: Avoid unnecessary indirection
isimluk 1ad7f08
Implement plural of define-fields
isimluk 19ec205
Remove support for <fields> elements in OSCAL schema
isimluk 0b474ab
Refactor: Pass whole metaschema to the helper method
isimluk 425cdd8
Refactor: Extract method: GetDefineFlag
isimluk bfd0453
Fill in metaschema model tree with references to the particular eleme…
isimluk def7ed2
Fix broken comments for flag values
isimluk 7643bb4
Provide go comments also for field and assembly elements
isimluk a83d9d3
Remove unnecessary complexity around go comments
isimluk df0cacc
Drop dependency on github.com/mitchellh/go-wordwrap
isimluk b236af2
Fix, simplify and make more rubust datatype handling
isimluk a227c8e
Fix missing flag name
isimluk 12e1ae8
Formatting
isimluk 83b6eaa
Generate go code for oscal_metadata_metaschema.xml
isimluk b74fb7a
Publish up errors that occurred during document linking
isimluk 54a373e
Recurse into imported metaschemas when seeing unresolved reference.
isimluk 0ce377d
Get a rid of requiresPointer method
isimluk dc398b8
Implement model/choice/field processing + fix & refactor along the way
isimluk 55ea4bd
Implement model/choice/assembly processing + fix & refactor along the…
isimluk a5bdb66
Refactor: Extract method: GoPackageName
isimluk 0c051fd
Make PackageName resolution more robust
isimluk 917b56b
Generate nominal_catalog codebase from oscal_control-common_metaschem…
isimluk 613a6fb
Fix missing xmlName in case of indirection
isimluk 2489e95
Do not override xml root
isimluk b0a71f7
Re-generate catalog.go based on latest OSCAL
isimluk fa035b2
Handle multi-line comments well
isimluk 9486666
Regenerate profile.go based on latest oscal_profile_metaschema.xml
isimluk 4e24577
Fix things for SSP oscal handling (oscal_ssp_metaschema.xml)
isimluk c826450
Generate SSP go types out of OSCAL/src/metaschema/oscal_ssp_metaschem…
isimluk 8afa5f7
Remove previous ssp go files
isimluk f69d6c9
Always use original xml name to name struct items in go
isimluk 86fffa4
Refactor: Extract method: linkAssemblies
isimluk efe2a9c
Refactor: Extract method: linkFields
isimluk f871cf9
Refactor: Extract method: linkFlags
isimluk 63e02e1
Import types to catalog, profile, and SSP files
isimluk 2e474c9
r/Subcontrol/Control/g
isimluk 138fbfd
Remove dead code
isimluk ba7a7e4
Replace <as> element with @as-type attribute on define-field
isimluk 483a3a3
Prose should be Markup instead of simple string
isimluk 8f4f307
Fix compilation issues around Prose handling
isimluk 8d6164e
Markup field has to be referred to by pointer
isimluk 62816f7
Fix compilation - SetParam has been renamed to Param
isimluk 82b52e5
Fix compilation - Href is no longer struct
isimluk ba40798
Fix compilation - ParamSettings has been renamed to Settings within M…
isimluk 456a679
Fix compilation - SetParam has been renamed to Set
isimluk dd92442
Fix compilation - misc fixes
isimluk 3a60dfa
Remove hard-coded over abundant items
isimluk 52b8ce9
Provide initial `oscalkit info` command
isimluk 512f550
Print out metadata information about profiles and catalogs
isimluk 0d63e6a
Refactor: Extract helper conduit: oscal_source
isimluk b765050
Remove pkgName that is unused
isimluk dc18037
Refactor: Extract constants
isimluk d56c6c5
Support parsing SSPs
isimluk d049c32
Do not bind plural method to metaschema template
isimluk 5074661
Refactor: Extract methods: JsonName
isimluk 466ffe2
Drop dependency on github.com/jinzhu/inflection
isimluk f48dc7d
Do not pluralize names of the XML elements
isimluk 9d80bd3
Fix golang camelCase naming
isimluk 84b265a
Refactor: Extract method DocumentType()
isimluk 7815d74
Introduce `oscal convert html`
isimluk dd0e05e
Remove bundled FedRAMP profiles
isimluk 67d3d3d
Remove bundled NIST profiles
isimluk e2c58b1
Remove NIST bundled catalog
isimluk c1d0dc1
Refactor: Extract xmllint manipulation to separate file
isimluk b1a1510
Handle the validation errors more diligently
isimluk 32258f3
Do not check file existence before validation
isimluk 16caf97
Drop oscalLoader workaround
isimluk 68033c7
Refactor: Extract json schema manipulation to separate module
isimluk 2391a0e
OscalSource should be able to tell format of the given resource
isimluk a919816
Refactor: Extract DocumentFormat to separate constants module
isimluk afce7d0
Refactor: DocumentType to separate constants module
isimluk 436c745
Improve `oscalkit validate` to automatically select relevant OSCAL sc…
isimluk fdc40ac
Generate Go code from oscal_implementation-common_metaschema.xml meta…
isimluk 3998c70
Do not hardcode "validation_common_root" package to be skipped
isimluk 1a0e853
Make sure that order of auto-generated imports is stable
isimluk 134ef80
Generate schema for component files
isimluk f1e498f
Implement `oscal info for oscal:component-definition files
isimluk 885f07a
Implement oscalkit validate for oscal:component-definition files
isimluk dcee3d4
oscal:system-security-plan is root element
isimluk efa43df
Convert Opencontrols to OSCAL
isimluk 82a5a36
Marshall Markup correctly
isimluk 088a963
More metadata for the oscal:ssp generated out of opencontrol
isimluk 4b614d5
Spill out proper <implemented-requirement/> elements
isimluk 1283ae8
Add Fedramp implementation status to the SSPs generated
isimluk 5ea6957
Notify user of which filename is actually malformed
isimluk 9f15df5
Refactor: Extract method: MarkupFromPlain
isimluk e12fdd8
XML encode any <>& characters that may be found in the open control data
isimluk 7cb53d0
Convert control responses from opencontrol to oscal
isimluk bd69de9
Update README.md
isimluk f7163f0
Force use golang 1.13 container instead of golang 1.11 container
isimluk 5c1cade
Remove previous version of opencontrol2oscal generator
isimluk 41bf562
Remove unused opencontrol stucts
isimluk 6699b3c
Re-generate types from the latest metaschema
isimluk 97c7ad1
Fix build failures after latest refresh of the OSCAL repository
isimluk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| FROM golang:1.11-alpine | ||
| FROM golang:1.13-alpine | ||
| RUN apk add --no-cache git | ||
| WORKDIR /go/src/github.com/docker/oscalkit/metaschema |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package convert | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/docker/oscalkit/pkg/oscal_source" | ||
| "github.com/urfave/cli" | ||
| "os" | ||
| ) | ||
|
|
||
| // ConvertHTML ... | ||
| var ConvertHTML = cli.Command{ | ||
| Name: "html", | ||
| Usage: "convert OSCAL file to human readable HTML", | ||
| Description: `The command accepts source file and generates HTML representation of given file`, | ||
| ArgsUsage: "[source-file]", | ||
| Flags: []cli.Flag{ | ||
| cli.StringFlag{ | ||
| Name: "output-path, o", | ||
| Usage: "Output path for converted file(s). Defaults to current working directory", | ||
| Destination: &outputPath, | ||
| }, | ||
| }, | ||
| Before: func(c *cli.Context) error { | ||
| if c.NArg() != 1 { | ||
| // Check for stdin | ||
| stat, _ := os.Stdin.Stat() | ||
| if (stat.Mode() & os.ModeCharDevice) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| return cli.NewExitError("oscalkit convert html requires at one argument", 1) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| Action: func(c *cli.Context) error { | ||
| for _, sourcePath := range c.Args() { | ||
| source, err := oscal_source.Open(sourcePath) | ||
| if err != nil { | ||
| return cli.NewExitError(fmt.Sprintf("could not load input file: %s", err), 1) | ||
| } | ||
| defer source.Close() | ||
|
|
||
| buffer, err := source.HTML() | ||
| if err != nil { | ||
| return cli.NewExitError(fmt.Sprintf("could convert to HTML: %s", err), 1) | ||
| } | ||
| if outputPath == "" { | ||
| fmt.Println(buffer.String()) | ||
| return nil | ||
| } | ||
|
|
||
| f, err := os.Create(outputPath) | ||
| if err != nil { | ||
| return cli.NewExitError(fmt.Sprintf("could write to file: %s", err), 1) | ||
| } | ||
| _, err = f.WriteString(buffer.String()) | ||
| if err != nil { | ||
| return cli.NewExitError(fmt.Sprintf("could write to file: %s", err), 1) | ||
| } | ||
| err = f.Close() | ||
| if err != nil { | ||
| return cli.NewExitError(fmt.Sprintf("failed to close file: %s", err), 1) | ||
| } | ||
| } | ||
| return nil | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,28 @@ | ||
| package convert | ||
|
|
||
| var includeXML bool | ||
| import ( | ||
| "github.com/docker/oscalkit/pkg/oc2oscal" | ||
| "github.com/urfave/cli" | ||
| ) | ||
|
|
||
| // ConvertOpenControl ... | ||
| // var ConvertOpenControl = cli.Command{ | ||
| // Name: "opencontrol", | ||
| // Usage: `convert from OpenControl format to OSCAL "implementation" format`, | ||
| // Description: `Convert OpenControl-formatted "component" and "opencontrol" YAML into | ||
| // OSCAL-formatted "implementation" layer JSON`, | ||
| // ArgsUsage: "[opencontrol.yaml-filepath] [opencontrols-dir-path]", | ||
| // Flags: []cli.Flag{ | ||
| // cli.BoolFlag{ | ||
| // Name: "yaml, y", | ||
| // Usage: "Generate YAML in addition to JSON", | ||
| // Destination: &yaml, | ||
| // }, | ||
| // cli.BoolFlag{ | ||
| // Name: "xml, x", | ||
| // Usage: "Generate XML in addition to JSON", | ||
| // Destination: &includeXML, | ||
| // }, | ||
| // }, | ||
| // Before: func(c *cli.Context) error { | ||
| // if c.NArg() != 2 { | ||
| // return cli.NewExitError("Missing opencontrol.yaml file and path to opencontrols/ directory", 1) | ||
| // } | ||
|
|
||
| // return nil | ||
| // }, | ||
| // Action: func(c *cli.Context) error { | ||
| // ocOSCAL, err := oscal.NewFromOC(oscal.OpenControlOptions{ | ||
| // OpenControlYAMLFilepath: c.Args().First(), | ||
| // OpenControlsDir: c.Args()[1], | ||
| // }) | ||
| // if err != nil { | ||
| // return cli.NewExitError(err, 1) | ||
| // } | ||
|
|
||
| // if includeXML { | ||
| // rawXMLOCOSCAL, err := ocOSCAL.XML(true) | ||
| // if err != nil { | ||
| // return cli.NewExitError(fmt.Sprintf("Error producing raw XML: %s", err), 1) | ||
| // } | ||
| // if err := ioutil.WriteFile("opencontrol-oscal.xml", rawXMLOCOSCAL, 0644); err != nil { | ||
| // return cli.NewExitError(err, 1) | ||
| // } | ||
| // } | ||
|
|
||
| // if yaml { | ||
| // rawYAMLOCOSCAL, err := ocOSCAL.YAML() | ||
| // if err != nil { | ||
| // return cli.NewExitError(err, 1) | ||
| // } | ||
| // if err := ioutil.WriteFile("opencontrol-oscal.yaml", rawYAMLOCOSCAL, 0644); err != nil { | ||
| // return cli.NewExitError(err, 1) | ||
| // } | ||
| // } | ||
|
|
||
| // rawOCOSCAL, err := ocOSCAL.JSON(true) | ||
| // if err != nil { | ||
| // return cli.NewExitError(err, 1) | ||
| // } | ||
|
|
||
| // if err := ioutil.WriteFile("opencontrol-oscal.json", rawOCOSCAL, 0644); err != nil { | ||
| // return cli.NewExitError(err, 1) | ||
| // } | ||
|
|
||
| // return nil | ||
| // }, | ||
| // } | ||
| var ConvertOpenControl = cli.Command{ | ||
| Name: "opencontrol", | ||
| Usage: `convert from OpenControl format to OSCAL "implementation" format`, | ||
| Description: `Convert OpenControl masonry repository into OSCAL directory`, | ||
| ArgsUsage: "[masonry-repository] [output-directory]", | ||
| Before: func(c *cli.Context) error { | ||
| if c.NArg() != 2 { | ||
| return cli.NewExitError("Missing masonry repository or output directory", 1) | ||
| } | ||
| return nil | ||
| }, | ||
| Action: func(c *cli.Context) error { | ||
| err := oc2oscal.Convert(c.Args()[0], c.Args()[1]) | ||
| if err != nil { | ||
| return cli.NewExitError(err, 1) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/docker/oscalkit/pkg/oscal/constants" | ||
| "github.com/docker/oscalkit/pkg/oscal_source" | ||
| "github.com/docker/oscalkit/types/oscal/catalog" | ||
| "github.com/urfave/cli" | ||
| ) | ||
|
|
||
| // Catalog generates json/xml catalogs | ||
| var Info = cli.Command{ | ||
| Name: "info", | ||
| Usage: "Provides information about particular OSCAL resource", | ||
| ArgsUsage: "[file]", | ||
| Action: func(c *cli.Context) error { | ||
| for _, filePath := range c.Args() { | ||
| os, err := oscal_source.Open(filePath) | ||
| if err != nil { | ||
| return cli.NewExitError(fmt.Sprintf("Could not open oscal file: %v", err), 1) | ||
| } | ||
| defer os.Close() | ||
|
|
||
| o := os.OSCAL() | ||
| switch o.DocumentType() { | ||
| case constants.SSPDocument: | ||
| fmt.Println("OSCAL System Security Plan") | ||
| fmt.Println("ID:\t", o.SystemSecurityPlan.Id) | ||
| printMetadata(o.SystemSecurityPlan.Metadata) | ||
| return nil | ||
| case constants.ComponentDocument: | ||
| fmt.Println("OSCAL Component (represents information about particular software asset/component)") | ||
| 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) | ||
| printMetadata(o.Profile.Metadata) | ||
| return nil | ||
| case constants.CatalogDocument: | ||
| fmt.Println("OSCAL Catalog (represents library of control assessment objectives and activities)") | ||
| fmt.Println("ID:\t", o.Catalog.Id) | ||
| printMetadata(o.Catalog.Metadata) | ||
| return nil | ||
| } | ||
| return cli.NewExitError("Unrecognized OSCAL resource", 1) | ||
| } | ||
| return cli.NewExitError("No file provided", 1) | ||
| }, | ||
| } | ||
|
|
||
| func printMetadata(m *catalog.Metadata) { | ||
| if m == nil { | ||
| return | ||
| } | ||
| fmt.Println("Metadata:") | ||
| fmt.Println("\tTitle:\t\t\t", m.Title) | ||
| if m.Published != "" { | ||
| fmt.Println("\tPublished:\t\t", m.Published) | ||
| } | ||
| if m.LastModified != "" { | ||
| fmt.Println("\tLast Modified:\t\t", m.LastModified) | ||
| } | ||
| if m.Version != "" { | ||
| fmt.Println("\tDocument Version:\t", m.Version) | ||
| } | ||
| if m.OscalVersion != "" { | ||
| fmt.Println("\tOSCAL Version:\t\t", m.OscalVersion) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.