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

Commit

Permalink
Merge pull request #3 from anweiss/schema-updates
Browse files Browse the repository at this point in the history
Automatically generate types based on OSCAL metaschemas
  • Loading branch information
anweiss committed Oct 2, 2018
2 parents 58c8b0d + 558b725 commit 0bca4c9
Show file tree
Hide file tree
Showing 37 changed files with 1,540 additions and 1,847 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# You should have received a copy of the CC0 Public Domain Dedication along with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

FROM golang:1.10-alpine AS builder
FROM golang:1.11-alpine AS builder
WORKDIR /go/src/github.com/opencontrol/oscalkit
COPY . .
WORKDIR /go/src/github.com/opencontrol/oscalkit/cli
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile.generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM golang:1.11-alpine
RUN apk add --no-cache git
WORKDIR /go/src/github.com/opencontrol/oscalkit/metaschema
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,39 @@
GOOS ?= darwin
GOARCH ?= amd64
LDFLAGS=-ldflags "-s -w"
NAMESPACE ?= opencontrol
NAMESPACE ?= opencontrolorg
REPO ?= oscalkit
BUILD ?= dev
BINARY=oscalkit_$(GOOS)_$(GOARCH)

.DEFAULT_GOAL := $(BINARY)
.PHONY: test build-docker push $(BINARY) clean

test:
generate:
docker build -t $(NAMESPACE)/$(REPO):generate -f Dockerfile.generate .
docker container run \
-v $$PWD:/go/src/github.com/opencontrol/oscalkit \
$(NAMESPACE)/$(REPO):generate \
sh -c "go generate"

test: generate
docker container run \
-v $$PWD:/go/src/github.com/opencontrol/oscalkit \
-w /go/src/github.com/opencontrol/oscalkit \
golang:1.10 \
golang:1.11 \
sh -c "go test \$$(go list ./... | grep -v /vendor/)"

build-docker:
docker image build -t $(NAMESPACE)/$(REPO):$(BUILD) .

push: build-docker
docker image push opencontrolorg/oscalkit:latest
docker image push $(NAMESPACE)/$(REPO):$(BUILD)

$(BINARY):
$(BINARY): generate
docker container run --rm \
-v $$PWD:/go/src/github.com/opencontrol/oscalkit \
-w /go/src/github.com/opencontrol/oscalkit/cli \
golang:1.10-alpine \
golang:1.11-alpine \
sh -c 'GOOS=${GOOS} GOARCH=${GOARCH} go build -v ${LDFLAGS} -o ../${BINARY}'

clean:
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ var Convert = cli.Command{
Usage: "convert between one or more OSCAL file formats and from OpenControl format",
Subcommands: []cli.Command{
ConvertOSCAL,
ConvertOpenControl,
// ConvertOpenControl,
},
}
128 changes: 60 additions & 68 deletions cli/cmd/convert/opencontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,72 @@

package convert

import (
"fmt"
"io/ioutil"

"github.com/opencontrol/oscalkit/types/oscal"
"github.com/urfave/cli"
)

var includeXML bool

// 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)
}
// 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)
}
// 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.RawXML(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 includeXML {
// rawXMLOCOSCAL, err := ocOSCAL.RawXML(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.RawYAML()
if err != nil {
return cli.NewExitError(err, 1)
}
if err := ioutil.WriteFile("opencontrol-oscal.yaml", rawYAMLOCOSCAL, 0644); err != nil {
return cli.NewExitError(err, 1)
}
}
// if yaml {
// rawYAMLOCOSCAL, err := ocOSCAL.RawYAML()
// 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.RawJSON(true)
if err != nil {
return cli.NewExitError(err, 1)
}
// rawOCOSCAL, err := ocOSCAL.RawJSON(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)
}
// if err := ioutil.WriteFile("opencontrol-oscal.json", rawOCOSCAL, 0644); err != nil {
// return cli.NewExitError(err, 1)
// }

return nil
},
}
// return nil
// },
// }
Loading

0 comments on commit 0bca4c9

Please sign in to comment.