Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lula tools command #128

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ module github.com/defenseunicorns/lula
go 1.21.4

require (
github.com/defenseunicorns/go-oscal v0.0.0-20231026225204-93f4762ee7f0
github.com/google/uuid v1.4.0
github.com/defenseunicorns/go-oscal v0.0.0-20231129232619-92e255935b65
github.com/mitchellh/mapstructure v1.5.0
github.com/open-policy-agent/opa v0.58.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.28.4
Expand Down Expand Up @@ -40,6 +38,7 @@ require (
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -57,7 +56,10 @@ require (
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/swaggest/jsonschema-go v0.3.62 // indirect
github.com/swaggest/refl v1.3.0 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
github.com/vladimirvivien/gexe v0.2.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/defenseunicorns/go-oscal v0.0.0-20231026225204-93f4762ee7f0 h1:q5Hrt56mFiaKqFpNAFZHVSi5AeC/MJojLq6Q4E80z8U=
github.com/defenseunicorns/go-oscal v0.0.0-20231026225204-93f4762ee7f0/go.mod h1:CCf9ThsY2TxMyoDA7mKCClHlfwWwydGwJQjf/tNpjAs=
github.com/defenseunicorns/go-oscal v0.0.0-20231128213232-09d26c5ca19a h1:EVwCGOmUWwTKn1mzX1klJNisCyy04b/4SjNRb+qtemE=
github.com/defenseunicorns/go-oscal v0.0.0-20231128213232-09d26c5ca19a/go.mod h1:UUR/pniY546gMFPErXPr6IC8uXWTAr36x4+1Qs/gMjM=
github.com/defenseunicorns/go-oscal v0.0.0-20231129232619-92e255935b65 h1:vU0e27ixll6NfLHbxWL3xqpvqDeGwI1BvWEkj5M1u5A=
github.com/defenseunicorns/go-oscal v0.0.0-20231129232619-92e255935b65/go.mod h1:dqp3TvIHFukcwyxJ/DyaohLHgoy5LqWSSZQzyxxt/bw=
github.com/dgraph-io/badger/v3 v3.2103.5 h1:ylPa6qzbjYRQMU6jokoj4wzcaweHylt//CH0AKt0akg=
github.com/dgraph-io/badger/v3 v3.2103.5/go.mod h1:4MPiseMeDQ3FNCYwRbbcBOGJLf5jsE0PPFzRiKjtcdw=
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
Expand Down Expand Up @@ -176,6 +178,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/swaggest/jsonschema-go v0.3.62 h1:eIE0aRklWa2eLJg2L/zqyWpKvgUPbq2oKOtrJGJkPH0=
github.com/swaggest/jsonschema-go v0.3.62/go.mod h1:DYuKqdpms/edvywsX6p1zHXCZkdwB28wRaBdFCe3Duw=
github.com/swaggest/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I=
github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg=
github.com/tchap/go-patricia/v2 v2.3.1 h1:6rQp39lgIYZ+MHmdEq4xzuk1t7OdC35z/xm0BGhTkes=
github.com/tchap/go-patricia/v2 v2.3.1/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k=
github.com/vladimirvivien/gexe v0.2.0 h1:nbdAQ6vbZ+ZNsolCgSVb9Fno60kzSuvtzVh6Ytqi/xY=
Expand Down
15 changes: 8 additions & 7 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/defenseunicorns/lula/src/cmd/tools"
"github.com/defenseunicorns/lula/src/cmd/validate"
)

var rootCmd = &cobra.Command{
Use: "lula",
Short: "lula",
Long: `lula`,
Short: "Risk Management as Code",
Long: `Real Time Risk Transparency through automated validation`,
}

func Execute() {

cobra.CheckErr(rootCmd.Execute())
}

func init() {
commands := []*cobra.Command{
validate.ValidateCommand(),
}

rootCmd.AddCommand(commands...)

if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
tools.Include(rootCmd)
}
16 changes: 16 additions & 0 deletions src/cmd/tools/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tools

import (
"github.com/spf13/cobra"
)

var toolsCmd = &cobra.Command{
Use: "tools",
Aliases: []string{"t"},
Short: "Collection of additional commands to make OSCAL easier",
}

// Include adds the tools command to the root command.
func Include(rootCmd *cobra.Command) {
rootCmd.AddCommand(toolsCmd)
}
39 changes: 39 additions & 0 deletions src/cmd/tools/uuid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tools

import (
"fmt"

"github.com/defenseunicorns/go-oscal/src/pkg/uuid"
"github.com/spf13/cobra"
)

var uuidHelp = `
To create a new random UUID:
lula tools uuidgen

To create a deterministic UUID given some source:
lula tools uuidgen <source>
`

func init() {
// Kubectl stub command.
uuidCmd := &cobra.Command{
Use: "uuidgen",
Short: "Generate a UUID",
Long: "Generate a UUID at random or deterministically with a provided input",
Example: uuidHelp,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
fmt.Println(uuid.NewUUID())
return nil
} else if len(args) == 1 {
fmt.Println(uuid.NewUUIDWithSource(args[0]))
return nil
} else {
return fmt.Errorf("too many arguments")
}
},
}

toolsCmd.AddCommand(uuidCmd)
}
10 changes: 4 additions & 6 deletions src/cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ To validate on a cluster:
lula validate ./oscal-component.yaml
`

var cluster bool

var ValidateCmd = &cobra.Command{
var validateCmd = &cobra.Command{
Use: "validate",
Short: "validate",
Long: "Lula Validation for compliance with established policy",
Short: "validate an OSCAL component definition",
Long: "Lula Validation of an OSCAL component definition",
Example: validateHelp,
RunE: func(cmd *cobra.Command, componentDefinitionPaths []string) error {
// Conduct further error checking here (IE flags/arguments)
Expand Down Expand Up @@ -63,7 +61,7 @@ var ValidateCmd = &cobra.Command{
func ValidateCommand() *cobra.Command {

// insert flag options here
return ValidateCmd
return validateCmd
}

/*
Expand Down
10 changes: 5 additions & 5 deletions src/pkg/common/oscal/assessment-results.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"strconv"
"time"

"github.com/defenseunicorns/go-oscal/src/pkg/uuid"
oscalTypes "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-1"
"github.com/defenseunicorns/lula/src/types"
"github.com/google/uuid"
)

const OSCAL_VERSION = "1.1.1"
Expand All @@ -32,7 +32,7 @@ func GenerateAssessmentResults(report *types.ReportObject) (oscalTypes.OscalMode
relatedObservations := make([]oscalTypes.RelatedObservation, 0)
// For each result - there may be many observations
for _, result := range implementedRequirement.Results {
sharedUuid := uuid.NewString()
sharedUuid := uuid.NewUUID()
observation := oscalTypes.Observation{
Collected: rfc3339Time,
Description: fmt.Sprintf("[TEST] %s - %s\n", implementedRequirement.ControlId, result.UUID),
Expand Down Expand Up @@ -60,7 +60,7 @@ func GenerateAssessmentResults(report *types.ReportObject) (oscalTypes.OscalMode
}
// TODO: Need to add in the control implementation UUID
finding := oscalTypes.Finding{
UUID: uuid.NewString(),
UUID: uuid.NewUUID(),
Title: fmt.Sprintf("Validation Result - Component:%s / Control Implementation: %s / Control: %s", component.UUID, controlImplementation.UUID, implementedRequirement.ControlId),
Description: implementedRequirement.Description,
Target: oscalTypes.FindingTarget{
Expand All @@ -87,7 +87,7 @@ func GenerateAssessmentResults(report *types.ReportObject) (oscalTypes.OscalMode
}

// Always create a new UUID for the assessment results (for now)
assessmentResults.AssessmentResults.UUID = uuid.NewString()
assessmentResults.AssessmentResults.UUID = uuid.NewUUID()

// Create metadata object with requires fields and a few extras
// Where do we establish what `version` should be?
Expand All @@ -103,7 +103,7 @@ func GenerateAssessmentResults(report *types.ReportObject) (oscalTypes.OscalMode
// Create results object
assessmentResults.AssessmentResults.Results = []oscalTypes.Result{
{
UUID: uuid.NewString(),
UUID: uuid.NewUUID(),
Title: "Lula Result Title",
Start: rfc3339Time,
Description: "Lula Result Description",
Expand Down