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

#278. Upgrade go-oscal package. #283

Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ compliance_report-*
out/
assessment-results-*.yaml
.idea
.vscode/settings.json
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/defenseunicorns/lula
go 1.22.0

require (
github.com/defenseunicorns/go-oscal v0.1.0
github.com/defenseunicorns/go-oscal v0.2.0
github.com/mitchellh/mapstructure v1.5.0
github.com/open-policy-agent/opa v0.61.0
github.com/pterm/pterm v0.12.79
Expand Down Expand Up @@ -95,6 +95,8 @@ require (
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/swaggest/jsonschema-go v0.3.66 // 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
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
github.com/defenseunicorns/go-oscal v0.1.0 h1:X3EOjEyQ5XvdD6xjIyhrtBhhg/bPgYdEXRjXjK6sd4s=
github.com/defenseunicorns/go-oscal v0.1.0/go.mod h1:y1esWKT2qg77jVwGHYjOy0mcjPQinujj3UAVbnq2xxI=
github.com/defenseunicorns/go-oscal v0.2.0 h1:hyRMUoQT2RFk/VIxz19yZKngobjdIuI+si6+k7+OX/M=
github.com/defenseunicorns/go-oscal v0.2.0/go.mod h1:4JXNIFmWK1VBHpmXicW/g65MizUEHKUexy3Lb2lH2/I=
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 @@ -306,6 +308,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.66 h1:4c5d7NRRqPLTswsbaypKqcMe3Z+CYHE3/lGsPIByp8o=
github.com/swaggest/jsonschema-go v0.3.66/go.mod h1:7N43/CwdaWgPUDfYV70K7Qm79tRqe/al7gLSt9YeGIE=
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
8 changes: 4 additions & 4 deletions src/cmd/evaluate/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package evaluate
import (
"fmt"

oscalTypes "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-1"
oscalTypes_1_1_2 "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-2"
"github.com/defenseunicorns/lula/src/pkg/common"
"github.com/defenseunicorns/lula/src/pkg/common/oscal"
"github.com/defenseunicorns/lula/src/pkg/message"
Expand Down Expand Up @@ -49,7 +49,7 @@ func EvaluateCommand() *cobra.Command {

func EvaluateAssessmentResults(files []string) error {
var status bool
var findings map[string][]oscalTypes.Finding
var findings map[string][]oscalTypes_1_1_2.Finding
// Read in files - establish the results to
if len(files) == 0 {
// TODO: Determine if we will handle a default location/name for assessment files
Expand Down Expand Up @@ -120,12 +120,12 @@ func EvaluateAssessmentResults(files []string) error {
}
}

func EvaluateResults(thresholdResult oscalTypes.Result, newResult oscalTypes.Result) (bool, map[string][]oscalTypes.Finding, error) {
func EvaluateResults(thresholdResult oscalTypes_1_1_2.Result, newResult oscalTypes_1_1_2.Result) (bool, map[string][]oscalTypes_1_1_2.Finding, error) {
spinner := message.NewProgressSpinner("Evaluating Assessment Results %s against %s", newResult.UUID, thresholdResult.UUID)
defer spinner.Stop()

// Store unique findings for review here
findings := make(map[string][]oscalTypes.Finding, 0)
findings := make(map[string][]oscalTypes_1_1_2.Finding, 0)
result := true

findingMapThreshold := oscal.GenerateFindingsMap(thresholdResult.Findings)
Expand Down
58 changes: 29 additions & 29 deletions src/cmd/evaluate/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ package evaluate
import (
"testing"

oscalTypes "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-1"
oscalTypes_1_1_2 "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-2"
"github.com/defenseunicorns/lula/src/pkg/message"
)

// Given two results - evaluate for passing
func TestEvaluateResultsPassing(t *testing.T) {
message.NoProgress = true

mockThresholdResult := oscalTypes.Result{
Findings: []oscalTypes.Finding{
mockThresholdResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
{
Target: oscalTypes.FindingTarget{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Status: oscalTypes.Status{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: "satisfied",
},
},
},
},
}

mockEvaluationResult := oscalTypes.Result{
Findings: []oscalTypes.Finding{
mockEvaluationResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
{
Target: oscalTypes.FindingTarget{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Status: oscalTypes.Status{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: "satisfied",
},
},
Expand All @@ -51,25 +51,25 @@ func TestEvaluateResultsPassing(t *testing.T) {

func TestEvaluateResultsFailed(t *testing.T) {
message.NoProgress = true
mockThresholdResult := oscalTypes.Result{
Findings: []oscalTypes.Finding{
mockThresholdResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
{
Target: oscalTypes.FindingTarget{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Status: oscalTypes.Status{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: "satisfied",
},
},
},
},
}

mockEvaluationResult := oscalTypes.Result{
Findings: []oscalTypes.Finding{
mockEvaluationResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
{
Target: oscalTypes.FindingTarget{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Status: oscalTypes.Status{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: "not-satisfied",
},
},
Expand All @@ -95,41 +95,41 @@ func TestEvaluateResultsFailed(t *testing.T) {

func TestEvaluateResultsNewFindings(t *testing.T) {
message.NoProgress = true
mockThresholdResult := oscalTypes.Result{
Findings: []oscalTypes.Finding{
mockThresholdResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
{
Target: oscalTypes.FindingTarget{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Status: oscalTypes.Status{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: "satisfied",
},
},
},
},
}
// Adding two new findings
mockEvaluationResult := oscalTypes.Result{
Findings: []oscalTypes.Finding{
mockEvaluationResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
{
Target: oscalTypes.FindingTarget{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Status: oscalTypes.Status{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: "satisfied",
},
},
},
{
Target: oscalTypes.FindingTarget{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-2",
Status: oscalTypes.Status{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: "satisfied",
},
},
},
{
Target: oscalTypes.FindingTarget{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-3",
Status: oscalTypes.Status{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: "not-satisfied",
},
},
Expand Down
42 changes: 21 additions & 21 deletions src/cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/defenseunicorns/go-oscal/src/pkg/uuid"
"github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-1"
oscalTypes_1_1_2 "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-2"
"github.com/defenseunicorns/lula/src/pkg/common/oscal"
"github.com/defenseunicorns/lula/src/pkg/message"
"github.com/defenseunicorns/lula/src/pkg/providers/opa"
Expand Down Expand Up @@ -97,7 +97,7 @@ func ValidateCommand() *cobra.Command {

// ValidateOnPath takes 1 -> N paths to OSCAL component-definition files
// It will then read those files to perform validation and return an ResultObject
func ValidateOnPath(path string) (findingMap map[string]oscalTypes.Finding, observations []oscalTypes.Observation, err error) {
func ValidateOnPath(path string) (findingMap map[string]oscalTypes_1_1_2.Finding, observations []oscalTypes_1_1_2.Observation, err error) {

_, err = os.Stat(path)
if os.IsNotExist(err) {
Expand All @@ -124,7 +124,7 @@ func ValidateOnPath(path string) (findingMap map[string]oscalTypes.Finding, obse

// ValidateOnCompDef takes a single ComponentDefinition object
// It will perform a validation and add data to a referenced report object
func ValidateOnCompDef(compDef oscalTypes.ComponentDefinition) (map[string]oscalTypes.Finding, []oscalTypes.Observation, error) {
func ValidateOnCompDef(compDef oscalTypes_1_1_2.ComponentDefinition) (map[string]oscalTypes_1_1_2.Finding, []oscalTypes_1_1_2.Observation, error) {

// Populate a map[uuid]Validation into the validations
validations := oscal.BackMatterToMap(compDef.BackMatter)
Expand All @@ -133,25 +133,25 @@ func ValidateOnCompDef(compDef oscalTypes.ComponentDefinition) (map[string]oscal
ctx := context.Background()
// Loops all the way down

findings := make(map[string]oscalTypes.Finding)
observations := make([]oscalTypes.Observation, 0)
findings := make(map[string]oscalTypes_1_1_2.Finding)
observations := make([]oscalTypes_1_1_2.Observation, 0)

for _, component := range compDef.Components {
for _, controlImplementation := range component.ControlImplementations {
rfc3339Time := time.Now().Format(time.RFC3339)
rfc3339Time := time.Now()
for _, implementedRequirement := range controlImplementation.ImplementedRequirements {
spinner := message.NewProgressSpinner("Validating Implemented Requirement - %s", implementedRequirement.UUID)
defer spinner.Stop()

// This should produce a finding - check if an existing finding for the control-id has been processed
var finding oscalTypes.Finding
tempObservations := make([]oscalTypes.Observation, 0)
relatedObservations := make([]oscalTypes.RelatedObservation, 0)
var finding oscalTypes_1_1_2.Finding
tempObservations := make([]oscalTypes_1_1_2.Observation, 0)
relatedObservations := make([]oscalTypes_1_1_2.RelatedObservation, 0)

if _, ok := findings[implementedRequirement.ControlId]; ok {
finding = findings[implementedRequirement.ControlId]
} else {
finding = oscalTypes.Finding{
finding = oscalTypes_1_1_2.Finding{
UUID: uuid.NewUUID(),
Title: fmt.Sprintf("Validation Result - Component:%s / Control Implementation: %s / Control: %s", component.UUID, controlImplementation.UUID, implementedRequirement.ControlId),
Description: implementedRequirement.Description,
Expand All @@ -167,7 +167,7 @@ func ValidateOnCompDef(compDef oscalTypes.ComponentDefinition) (map[string]oscal
// Current identifier is the link text
if link.Text == "Lula Validation" {
sharedUuid := uuid.NewUUID()
observation := oscalTypes.Observation{
observation := oscalTypes_1_1_2.Observation{
Collected: rfc3339Time,
Methods: []string{"TEST"},
UUID: sharedUuid,
Expand All @@ -183,15 +183,15 @@ func ValidateOnCompDef(compDef oscalTypes.ComponentDefinition) (map[string]oscal
} else {
result, err = ValidateOnTarget(ctx, id, val.Description)
if err != nil {
return map[string]oscalTypes.Finding{}, []oscalTypes.Observation{}, err
return map[string]oscalTypes_1_1_2.Finding{}, []oscalTypes_1_1_2.Observation{}, err
}
// Store the result in the validation object
val.Result = result
val.Evaluated = true
validations[id] = val
}
} else {
return map[string]oscalTypes.Finding{}, []oscalTypes.Observation{}, fmt.Errorf("Back matter Validation %v not found", id)
return map[string]oscalTypes_1_1_2.Finding{}, []oscalTypes_1_1_2.Observation{}, fmt.Errorf("Back matter Validation %v not found", id)
}

// Individual result state
Expand All @@ -201,13 +201,13 @@ func ValidateOnCompDef(compDef oscalTypes.ComponentDefinition) (map[string]oscal
result.State = "not-satisfied"
}

observation.RelevantEvidence = []oscalTypes.RelevantEvidence{
observation.RelevantEvidence = []oscalTypes_1_1_2.RelevantEvidence{
{
Description: fmt.Sprintf("Result: %s - Passing Resources: %s - Failing Resources %s\n", result.State, strconv.Itoa(result.Passing), strconv.Itoa(result.Failing)),
},
}

relatedObservation := oscalTypes.RelatedObservation{
relatedObservation := oscalTypes_1_1_2.RelatedObservation{
ObservationUuid: sharedUuid,
}

Expand All @@ -234,8 +234,8 @@ func ValidateOnCompDef(compDef oscalTypes.ComponentDefinition) (map[string]oscal
message.Infof("UUID: %v", finding.UUID)
message.Infof(" Status: %v", state)

finding.Target = oscalTypes.FindingTarget{
Status: oscalTypes.Status{
finding.Target = oscalTypes_1_1_2.FindingTarget{
Status: oscalTypes_1_1_2.ObjectiveStatus{
State: state,
},
TargetId: implementedRequirement.ControlId,
Expand Down Expand Up @@ -274,10 +274,10 @@ func ValidateOnTarget(ctx context.Context, id string, target map[string]interfac
// This is the OSCAL document generation for final output.
// This should include some ability to consolidate controls met in multiple input documents under single control entries
// This should include fields that reference the source of the control to the original document ingested
func WriteReport(report oscalTypes.AssessmentResults, assessmentFilePath string) error {
func WriteReport(report oscalTypes_1_1_2.AssessmentResults, assessmentFilePath string) error {

var fileName string
var tempAssessment oscalTypes.AssessmentResults
var tempAssessment oscalTypes_1_1_2.AssessmentResults

if assessmentFilePath != "" {

Expand All @@ -294,7 +294,7 @@ func WriteReport(report oscalTypes.AssessmentResults, assessmentFilePath string)
return err
}

results := make([]oscalTypes.Result, 0)
results := make([]oscalTypes_1_1_2.Result, 0)
// append new results first - unfurl so as to allow multiple results in the future
results = append(results, report.Results...)
results = append(results, tempAssessment.Results...)
Expand All @@ -318,7 +318,7 @@ func WriteReport(report oscalTypes.AssessmentResults, assessmentFilePath string)

var b bytes.Buffer

var sar = oscalTypes.OscalModels{
var sar = oscalTypes_1_1_2.OscalModels{
AssessmentResults: tempAssessment,
}

Expand Down
Loading