Skip to content

Commit

Permalink
refactor!(assessment-results): #388 NewAssessmentResults now returns …
Browse files Browse the repository at this point in the history
…a pointer
  • Loading branch information
mike-winberry committed May 10, 2024
1 parent b94f17c commit 389d46d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func ValidateOnCompDef(compDef *oscalTypes_1_1_2.ComponentDefinition) (map[strin
func WriteReport(report oscalTypes_1_1_2.AssessmentResults, assessmentFilePath string) error {

var fileName string
var tempAssessment oscalTypes_1_1_2.AssessmentResults
var tempAssessment *oscalTypes_1_1_2.AssessmentResults

if assessmentFilePath != "" {

Expand All @@ -308,23 +308,23 @@ func WriteReport(report oscalTypes_1_1_2.AssessmentResults, assessmentFilePath s

} else if os.IsNotExist(err) {
// File does not exist
tempAssessment = report
tempAssessment = &report
fileName = assessmentFilePath
} else {
// Some other error occurred (permission issues, etc.)
return err
}

} else {
tempAssessment = report
tempAssessment = &report
currentTime := time.Now()
fileName = "assessment-results-" + currentTime.Format("01-02-2006-15:04:05") + ".yaml"
fileName = "assessment-results-" + currentTime.Format("01-02-206-15:04:05") + ".yaml"
}

var b bytes.Buffer

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

yamlEncoder := yaml.NewEncoder(&b)
Expand Down
7 changes: 4 additions & 3 deletions src/pkg/common/oscal/assessment-results.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (

const OSCAL_VERSION = "1.1.2"

func NewAssessmentResults(data []byte) (oscalTypes_1_1_2.AssessmentResults, error) {
// NewAssessmentResults creates a new assessment results object from the given data.
func NewAssessmentResults(data []byte) (*oscalTypes_1_1_2.AssessmentResults, error) {
var oscalModels oscalTypes_1_1_2.OscalModels

err := yaml.Unmarshal(data, &oscalModels)
if err != nil {
fmt.Printf("Error marshalling yaml: %s\n", err.Error())
return oscalTypes_1_1_2.AssessmentResults{}, err
return nil, 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

0 comments on commit 389d46d

Please sign in to comment.