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

deps(go-oscal): upgrade to v0.3.0 #317

Merged
merged 12 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 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.1

require (
github.com/defenseunicorns/go-oscal v0.2.5
github.com/defenseunicorns/go-oscal v0.3.0
github.com/hashicorp/go-version v1.6.0
github.com/open-policy-agent/opa v0.62.1
github.com/pterm/pterm v0.12.79
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE=
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
github.com/defenseunicorns/go-oscal v0.2.5 h1:r8A2sXz/VTjVIf4Er/WyDSTyqUteek5AHeKEAT2XzTU=
github.com/defenseunicorns/go-oscal v0.2.5/go.mod h1:4JXNIFmWK1VBHpmXicW/g65MizUEHKUexy3Lb2lH2/I=
github.com/defenseunicorns/go-oscal v0.3.0 h1:DxkbVSqetXFZku+bi53pHQaE1+iLgHw0R3PMeIwb4Mw=
github.com/defenseunicorns/go-oscal v0.3.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
4 changes: 2 additions & 2 deletions src/cmd/evaluate/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func EvaluateResults(thresholdResult oscalTypes_1_1_2.Result, newResult oscalTyp
findings := make(map[string][]oscalTypes_1_1_2.Finding, 0)
result := true

findingMapThreshold := oscal.GenerateFindingsMap(thresholdResult.Findings)
findingMapNew := oscal.GenerateFindingsMap(newResult.Findings)
findingMapThreshold := oscal.GenerateFindingsMap(*thresholdResult.Findings)
findingMapNew := oscal.GenerateFindingsMap(*newResult.Findings)

// For a given oldResult - we need to prove that the newResult implements all of the oldResult findings/controls
// We are explicitly iterating through the findings in order to collect a delta to display
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/evaluate/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestEvaluateResultsPassing(t *testing.T) {
message.NoProgress = true

mockThresholdResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
Findings: &[]oscalTypes_1_1_2.Finding{
{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Expand All @@ -25,7 +25,7 @@ func TestEvaluateResultsPassing(t *testing.T) {
}

mockEvaluationResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
Findings: &[]oscalTypes_1_1_2.Finding{
{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Expand All @@ -52,7 +52,7 @@ func TestEvaluateResultsPassing(t *testing.T) {
func TestEvaluateResultsFailed(t *testing.T) {
message.NoProgress = true
mockThresholdResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
Findings: &[]oscalTypes_1_1_2.Finding{
{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Expand All @@ -65,7 +65,7 @@ func TestEvaluateResultsFailed(t *testing.T) {
}

mockEvaluationResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
Findings: &[]oscalTypes_1_1_2.Finding{
{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestEvaluateResultsFailed(t *testing.T) {
func TestEvaluateResultsNewFindings(t *testing.T) {
message.NoProgress = true
mockThresholdResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
Findings: &[]oscalTypes_1_1_2.Finding{
{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Expand All @@ -109,7 +109,7 @@ func TestEvaluateResultsNewFindings(t *testing.T) {
}
// Adding two new findings
mockEvaluationResult := oscalTypes_1_1_2.Result{
Findings: []oscalTypes_1_1_2.Finding{
Findings: &[]oscalTypes_1_1_2.Finding{
{
Target: oscalTypes_1_1_2.FindingTarget{
TargetId: "ID-1",
Expand Down
14 changes: 7 additions & 7 deletions src/cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func ValidateOnPath(path string) (findingMap map[string]oscalTypes_1_1_2.Finding
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)
validations := oscal.BackMatterToMap(*compDef.BackMatter)

// TODO: Is there a better location for context?
ctx := context.Background()
Expand All @@ -135,8 +135,8 @@ func ValidateOnCompDef(compDef oscalTypes_1_1_2.ComponentDefinition) (map[string
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 {
for _, component := range *compDef.Components {
mike-winberry marked this conversation as resolved.
Show resolved Hide resolved
for _, controlImplementation := range *component.ControlImplementations {
mike-winberry marked this conversation as resolved.
Show resolved Hide resolved
rfc3339Time := time.Now()
for _, implementedRequirement := range controlImplementation.ImplementedRequirements {
spinner := message.NewProgressSpinner("Validating Implemented Requirement - %s", implementedRequirement.UUID)
Expand All @@ -160,7 +160,7 @@ func ValidateOnCompDef(compDef oscalTypes_1_1_2.ComponentDefinition) (map[string
var pass, fail int
// IF the implemented requirement contains a link - check for Lula Validation

for _, link := range implementedRequirement.Links {
for _, link := range *implementedRequirement.Links {
var result types.Result
var err error
// Current identifier is the link text
Expand Down Expand Up @@ -208,7 +208,7 @@ func ValidateOnCompDef(compDef oscalTypes_1_1_2.ComponentDefinition) (map[string
}
}

observation.RelevantEvidence = []oscalTypes_1_1_2.RelevantEvidence{
observation.RelevantEvidence = &[]oscalTypes_1_1_2.RelevantEvidence{
{
Description: fmt.Sprintf("Result: %s\n", result.State),
Remarks: remarks,
Expand Down Expand Up @@ -250,7 +250,7 @@ func ValidateOnCompDef(compDef oscalTypes_1_1_2.ComponentDefinition) (map[string
Type: "objective-id",
}

finding.RelatedObservations = relatedObservations
finding.RelatedObservations = &relatedObservations

findings[implementedRequirement.ControlId] = finding
observations = append(observations, tempObservations...)
Expand Down Expand Up @@ -327,7 +327,7 @@ func WriteReport(report oscalTypes_1_1_2.AssessmentResults, assessmentFilePath s
var b bytes.Buffer

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

yamlEncoder := yaml.NewEncoder(&b)
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 @@ -21,7 +21,7 @@ func NewAssessmentResults(data []byte) (oscalTypes_1_1_2.AssessmentResults, erro
return oscalTypes_1_1_2.AssessmentResults{}, err
}

return oscalModels.AssessmentResults, nil
return *oscalModels.AssessmentResults, nil
}

func GenerateAssessmentResults(findingMap map[string]oscalTypes_1_1_2.Finding, observations []oscalTypes_1_1_2.Observation) (oscalTypes_1_1_2.AssessmentResults, error) {
Expand Down Expand Up @@ -51,7 +51,7 @@ func GenerateAssessmentResults(findingMap map[string]oscalTypes_1_1_2.Finding, o
Version: "0.0.1",
OscalVersion: OSCAL_VERSION,
Remarks: "Assessment Results generated from Lula",
Published: rfc3339Time,
Published: &rfc3339Time,
LastModified: rfc3339Time,
}

Expand All @@ -68,12 +68,12 @@ func GenerateAssessmentResults(findingMap map[string]oscalTypes_1_1_2.Finding, o
ControlSelections: []oscalTypes_1_1_2.AssessedControls{
{
Description: "Controls Assessed by Lula",
IncludeControls: controlList,
IncludeControls: &controlList,
},
},
},
Findings: findings,
Observations: observations,
Findings: &findings,
Observations: &observations,
},
}

Expand Down
6 changes: 3 additions & 3 deletions src/pkg/common/oscal/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ func NewOscalComponentDefinition(data []byte) (oscalTypes_1_1_2.ComponentDefinit
err := yaml.Unmarshal(data, &oscalModels)
if err != nil {
fmt.Printf("Error marshalling yaml: %s\n", err.Error())
return oscalModels.ComponentDefinition, err
return *oscalModels.ComponentDefinition, err
}

return oscalModels.ComponentDefinition, nil
return *oscalModels.ComponentDefinition, nil
}

// Map an array of resources to a map of UUID to validation object
func BackMatterToMap(backMatter oscalTypes_1_1_2.BackMatter) map[string]types.Validation {
resourceMap := make(map[string]types.Validation)

for _, resource := range backMatter.Resources {
for _, resource := range *backMatter.Resources {
if resource.Title == "Lula Validation" {
var validation types.Validation

Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/outputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func TestOutputs(t *testing.T) {
for _, o := range observations {
if strings.Contains(o.Description, "ID-1") {
// Check remarks have printed the correct observation value
if o.RelevantEvidence[0].Remarks != "validate.test: hello world\n" {
if (*o.RelevantEvidence)[0].Remarks != "validate.test: hello world\n" {
t.Fatal("Failed to validate payload.output observations for ID-1")
}
}
if strings.Contains(o.Description, "ID-2") {
// Check remarks are empty due to incorrect observation formats
if o.RelevantEvidence[0].Remarks != "" {
if (*o.RelevantEvidence)[0].Remarks != "" {
t.Fatal("Failed to validate payload.output observations for ID-2")
}
}
Expand Down