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

Revamp project to work with latest OSCAL #88

Merged
merged 110 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
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 Dec 16, 2019
67d76da
Improve error message
isimluk Dec 16, 2019
09a858f
Allow multiple import elements in metaschema XML
isimluk Dec 16, 2019
d992881
Allow multiple import in Metaschema struct
isimluk Dec 16, 2019
84a169a
Performance: Use shallow clone of OSCAL.git to speed-up things a bit
isimluk Dec 16, 2019
2a6614e
Avoid using '-' character in go package name
isimluk Dec 16, 2019
e5a5981
Parse @ref attribute from field
isimluk Dec 18, 2019
69dcbc0
Implement indirection from field to define-field
isimluk Dec 18, 2019
71c49b8
Remove Assemblies metaschema element
isimluk Dec 18, 2019
aac0300
Parse @ref attribute from assembly
isimluk Dec 18, 2019
b2a8bc1
Refactor: Use existing method instead of expanding it
isimluk Dec 18, 2019
ebb1e54
Implement indirection from assembly to define-assembly
isimluk Dec 18, 2019
2b57abb
Implement plural of assemblies
isimluk Dec 18, 2019
d4592a6
Refactor: Extract method: RepresentsRootElement
isimluk Dec 18, 2019
70b63d3
Depend on encoding/xml only when file contains final root element
isimluk Dec 18, 2019
b3ea5a7
Refactor: Extract method: RequiresPointer
isimluk Dec 18, 2019
337c1d3
Refactor: Avoid unnecessary indirection
isimluk Dec 18, 2019
1ad7f08
Implement plural of define-fields
isimluk Dec 18, 2019
19ec205
Remove support for <fields> elements in OSCAL schema
isimluk Dec 18, 2019
0b474ab
Refactor: Pass whole metaschema to the helper method
isimluk Dec 18, 2019
425cdd8
Refactor: Extract method: GetDefineFlag
isimluk Dec 18, 2019
bfd0453
Fill in metaschema model tree with references to the particular eleme…
isimluk Dec 18, 2019
def7ed2
Fix broken comments for flag values
isimluk Dec 18, 2019
7643bb4
Provide go comments also for field and assembly elements
isimluk Dec 18, 2019
a83d9d3
Remove unnecessary complexity around go comments
isimluk Dec 18, 2019
df0cacc
Drop dependency on github.com/mitchellh/go-wordwrap
isimluk Dec 18, 2019
b236af2
Fix, simplify and make more rubust datatype handling
isimluk Dec 18, 2019
a227c8e
Fix missing flag name
isimluk Dec 18, 2019
12e1ae8
Formatting
isimluk Dec 18, 2019
83b6eaa
Generate go code for oscal_metadata_metaschema.xml
isimluk Dec 18, 2019
b74fb7a
Publish up errors that occurred during document linking
isimluk Dec 18, 2019
54a373e
Recurse into imported metaschemas when seeing unresolved reference.
isimluk Dec 18, 2019
0ce377d
Get a rid of requiresPointer method
isimluk Dec 18, 2019
dc398b8
Implement model/choice/field processing + fix & refactor along the way
isimluk Dec 18, 2019
55ea4bd
Implement model/choice/assembly processing + fix & refactor along the…
isimluk Dec 18, 2019
a5bdb66
Refactor: Extract method: GoPackageName
isimluk Dec 19, 2019
0c051fd
Make PackageName resolution more robust
isimluk Dec 19, 2019
917b56b
Generate nominal_catalog codebase from oscal_control-common_metaschem…
isimluk Dec 19, 2019
613a6fb
Fix missing xmlName in case of indirection
isimluk Dec 19, 2019
2489e95
Do not override xml root
isimluk Dec 19, 2019
b0a71f7
Re-generate catalog.go based on latest OSCAL
isimluk Dec 19, 2019
fa035b2
Handle multi-line comments well
isimluk Dec 19, 2019
9486666
Regenerate profile.go based on latest oscal_profile_metaschema.xml
isimluk Dec 19, 2019
4e24577
Fix things for SSP oscal handling (oscal_ssp_metaschema.xml)
isimluk Dec 19, 2019
c826450
Generate SSP go types out of OSCAL/src/metaschema/oscal_ssp_metaschem…
isimluk Dec 19, 2019
8afa5f7
Remove previous ssp go files
isimluk Dec 19, 2019
f69d6c9
Always use original xml name to name struct items in go
isimluk Dec 20, 2019
86fffa4
Refactor: Extract method: linkAssemblies
isimluk Dec 20, 2019
efe2a9c
Refactor: Extract method: linkFields
isimluk Dec 20, 2019
f871cf9
Refactor: Extract method: linkFlags
isimluk Dec 20, 2019
63e02e1
Import types to catalog, profile, and SSP files
isimluk Dec 23, 2019
2e474c9
r/Subcontrol/Control/g
isimluk Jan 11, 2020
138fbfd
Remove dead code
isimluk Jan 11, 2020
ba7a7e4
Replace <as> element with @as-type attribute on define-field
isimluk Jan 11, 2020
483a3a3
Prose should be Markup instead of simple string
isimluk Jan 11, 2020
8f4f307
Fix compilation issues around Prose handling
isimluk Jan 13, 2020
8d6164e
Markup field has to be referred to by pointer
isimluk Jan 13, 2020
62816f7
Fix compilation - SetParam has been renamed to Param
isimluk Jan 13, 2020
82b52e5
Fix compilation - Href is no longer struct
isimluk Jan 13, 2020
ba40798
Fix compilation - ParamSettings has been renamed to Settings within M…
isimluk Jan 13, 2020
456a679
Fix compilation - SetParam has been renamed to Set
isimluk Jan 13, 2020
dd92442
Fix compilation - misc fixes
isimluk Jan 13, 2020
3a60dfa
Remove hard-coded over abundant items
isimluk Jan 13, 2020
52b8ce9
Provide initial `oscalkit info` command
isimluk Jan 14, 2020
512f550
Print out metadata information about profiles and catalogs
isimluk Jan 14, 2020
0d63e6a
Refactor: Extract helper conduit: oscal_source
isimluk Jan 14, 2020
b765050
Remove pkgName that is unused
isimluk Jan 14, 2020
dc18037
Refactor: Extract constants
isimluk Jan 14, 2020
d56c6c5
Support parsing SSPs
isimluk Jan 14, 2020
d049c32
Do not bind plural method to metaschema template
isimluk Jan 14, 2020
5074661
Refactor: Extract methods: JsonName
isimluk Jan 14, 2020
466ffe2
Drop dependency on github.com/jinzhu/inflection
isimluk Jan 14, 2020
f48dc7d
Do not pluralize names of the XML elements
isimluk Jan 14, 2020
9d80bd3
Fix golang camelCase naming
isimluk Jan 15, 2020
84b265a
Refactor: Extract method DocumentType()
isimluk Jan 15, 2020
7815d74
Introduce `oscal convert html`
isimluk Jan 15, 2020
dd0e05e
Remove bundled FedRAMP profiles
isimluk Jan 16, 2020
67d3d3d
Remove bundled NIST profiles
isimluk Jan 16, 2020
e2c58b1
Remove NIST bundled catalog
isimluk Jan 16, 2020
c1d0dc1
Refactor: Extract xmllint manipulation to separate file
isimluk Jan 16, 2020
b1a1510
Handle the validation errors more diligently
isimluk Jan 16, 2020
32258f3
Do not check file existence before validation
isimluk Jan 16, 2020
16caf97
Drop oscalLoader workaround
isimluk Jan 16, 2020
68033c7
Refactor: Extract json schema manipulation to separate module
isimluk Jan 16, 2020
2391a0e
OscalSource should be able to tell format of the given resource
isimluk Jan 16, 2020
a919816
Refactor: Extract DocumentFormat to separate constants module
isimluk Jan 16, 2020
afce7d0
Refactor: DocumentType to separate constants module
isimluk Jan 16, 2020
436c745
Improve `oscalkit validate` to automatically select relevant OSCAL sc…
isimluk Jan 17, 2020
fdc40ac
Generate Go code from oscal_implementation-common_metaschema.xml meta…
isimluk Jan 17, 2020
3998c70
Do not hardcode "validation_common_root" package to be skipped
isimluk Jan 20, 2020
1a0e853
Make sure that order of auto-generated imports is stable
isimluk Jan 20, 2020
134ef80
Generate schema for component files
isimluk Jan 20, 2020
f1e498f
Implement `oscal info for oscal:component-definition files
isimluk Jan 20, 2020
885f07a
Implement oscalkit validate for oscal:component-definition files
isimluk Jan 20, 2020
dcee3d4
oscal:system-security-plan is root element
isimluk Jan 21, 2020
efa43df
Convert Opencontrols to OSCAL
isimluk Jan 21, 2020
82a5a36
Marshall Markup correctly
isimluk Jan 24, 2020
088a963
More metadata for the oscal:ssp generated out of opencontrol
isimluk Jan 24, 2020
4b614d5
Spill out proper <implemented-requirement/> elements
isimluk Jan 25, 2020
1283ae8
Add Fedramp implementation status to the SSPs generated
isimluk Jan 25, 2020
5ea6957
Notify user of which filename is actually malformed
isimluk Jan 25, 2020
9f15df5
Refactor: Extract method: MarkupFromPlain
isimluk Jan 25, 2020
e12fdd8
XML encode any <>& characters that may be found in the open control data
isimluk Jan 25, 2020
7cb53d0
Convert control responses from opencontrol to oscal
isimluk Jan 26, 2020
bd69de9
Update README.md
isimluk Jan 28, 2020
f7163f0
Force use golang 1.13 container instead of golang 1.11 container
isimluk Feb 4, 2020
5c1cade
Remove previous version of opencontrol2oscal generator
isimluk Feb 4, 2020
41bf562
Remove unused opencontrol stucts
isimluk Feb 4, 2020
6699b3c
Re-generate types from the latest metaschema
isimluk Feb 5, 2020
97c7ad1
Fix build failures after latest refresh of the OSCAL repository
isimluk Feb 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11-alpine AS builder
FROM golang:1.13-alpine AS builder
WORKDIR /go/src/github.com/docker/oscalkit
ARG VERSION
ARG BUILD
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.11 AS race-detector
FROM golang:1.13 AS race-detector
anweiss marked this conversation as resolved.
Show resolved Hide resolved
WORKDIR /go/src/github.com/docker/oscalkit
COPY . .
WORKDIR /go/src/github.com/docker/oscalkit/cli
RUN go build -race

FROM golang:1.11
FROM golang:1.13
ARG GOOS
ARG GOARCH
ARG VERSION
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.generate
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
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ generate:

test:
@echo "Running Oscalkit test Utility"
@sh test_util/RunTest.sh -p test_util/artifacts/NIST_SP-800-53_rev4_HIGH-baseline_profile.xml
@sh test_util/RunTest.sh -p test_util/artifacts/NIST_SP-800-53_rev4_MODERATE-baseline_profile.xml
@sh test_util/RunTest.sh -p test_util/artifacts/NIST_SP-800-53_rev4_LOW-baseline_profile.xml
@sh test_util/RunTest.sh -p test_util/artifacts/FedRAMP_HIGH-baseline_profile.xml
@sh test_util/RunTest.sh -p test_util/artifacts/FedRAMP_MODERATE-baseline_profile.xml
@sh test_util/RunTest.sh -p test_util/artifacts/FedRAMP_LOW-baseline_profile.xml
@echo "Running remaining tests"
@go test -race -coverprofile=coverage.txt -covermode=atomic -v $(shell go list ./... | grep -v "/vendor/\|/test_util/src")

Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Convert OpenControl project to OSCAL-formatted JSON:

### Validate against XML and JSON schemas

The tool supports validation of OSCAL-formatted XML and JSON files against the corresponding OSCAL XML schemas (.xsd) and JSON schemas. XML schema validation requires the `xmllint` tool on the local machine (included with macOS and Linux. Windows installation instructions [here](https://stackoverflow.com/a/21227833))
The tool supports validation of OSCAL-formatted XML and JSON files against the corresponding OSCAL XML schemas (.xsd) and JSON schemas. Schemas are packaged with the tool and found automatically based on the type of OSCAL file. XML schema validation requires the `xmllint` tool on the local machine (included with macOS and Linux. Windows installation instructions [here](https://stackoverflow.com/a/21227833))

```
NAME:
Expand All @@ -171,9 +171,6 @@ USAGE:
DESCRIPTION:
Validate OSCAL-formatted XML files against a specific XML schema (.xsd)
or OSCAL-formatted JSON files against a specific JSON schema

OPTIONS:
--schema value, -s value schema file to validate against
```

#### Examples
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func Execute() error {
return nil
}
app.Commands = []cli.Command{
Info,
convert.Convert,
Validate,
Sign,
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var Convert = cli.Command{
Usage: "convert between one or more OSCAL file formats and from OpenControl format",
Subcommands: []cli.Command{
ConvertOSCAL,
// ConvertOpenControl,
ConvertHTML,
ConvertOpenControl,
},
}
68 changes: 68 additions & 0 deletions cli/cmd/convert/html.go
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
},
}
91 changes: 24 additions & 67 deletions cli/cmd/convert/opencontrol.go
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
},
}
18 changes: 4 additions & 14 deletions cli/cmd/generate/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"

"github.com/sirupsen/logrus"

"github.com/docker/oscalkit/generator"
"github.com/docker/oscalkit/pkg/oscal_source"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -45,23 +45,13 @@ var Catalog = cli.Command{
return nil
},
Action: func(c *cli.Context) error {

profilePath, err := generator.GetAbsolutePath(profilePath)
if err != nil {
return cli.NewExitError(fmt.Sprintf("cannot get absolute path, err: %v", err), 1)
}

_, err = os.Stat(profilePath)
if err != nil {
return cli.NewExitError(fmt.Sprintf("cannot fetch file, err %v", err), 1)
}
f, err := os.Open(profilePath)
os, err := oscal_source.Open(profilePath)
if err != nil {
return cli.NewExitError(err, 1)
}
defer f.Close()
defer os.Close()

profile, err := generator.ReadProfile(f)
profile, err := generator.ReadProfile(os.OSCAL())
if err != nil {
return cli.NewExitError(err, 1)
}
Expand Down
16 changes: 4 additions & 12 deletions cli/cmd/generate/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"regexp"

"github.com/docker/oscalkit/generator"
"github.com/docker/oscalkit/pkg/oscal_source"
"github.com/docker/oscalkit/templates"
"github.com/docker/oscalkit/types/oscal/catalog"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -53,22 +54,13 @@ var Code = cli.Command{
return cli.NewExitError(err, 1)
}

profilePath, err := generator.GetAbsolutePath(profilePath)
if err != nil {
return cli.NewExitError(fmt.Sprintf("cannot get absolute path, err: %v", err), 1)
}

_, err = os.Stat(profilePath)
if err != nil {
return cli.NewExitError(fmt.Sprintf("cannot fetch file, err %v", err), 1)
}
f, err := os.Open(profilePath)
osource, err := oscal_source.Open(profilePath)
if err != nil {
return cli.NewExitError(err, 1)
}
defer f.Close()
defer osource.Close()

profile, err := generator.ReadProfile(f)
profile, err := generator.ReadProfile(osource.OSCAL())
if err != nil {
return cli.NewExitError(err, 1)
}
Expand Down
71 changes: 71 additions & 0 deletions cli/cmd/info.go
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)
}
}
Loading