This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from isimluk/fix-metachema-generation
Revamp project to work with latest OSCAL
- Loading branch information
Showing
84 changed files
with
3,169 additions
and
69,604 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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.