Skip to content

Commit

Permalink
fix: merge oopsie
Browse files Browse the repository at this point in the history
  • Loading branch information
meganwolf0 committed Oct 9, 2024
1 parent 0977e78 commit 5f94d8d
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"fmt"
"path/filepath"

"github.com/defenseunicorns/go-oscal/src/pkg/files"
oscalTypes_1_1_2 "github.com/defenseunicorns/go-oscal/src/types/oscal-1-1-2"
"github.com/defenseunicorns/lula/src/cmd/common"
"github.com/defenseunicorns/lula/src/pkg/common/composition"
"github.com/defenseunicorns/lula/src/pkg/common/oscal"
"github.com/defenseunicorns/lula/src/pkg/message"
"github.com/defenseunicorns/lula/src/pkg/common/validation"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -62,20 +62,36 @@ func ValidateCommand() *cobra.Command {
// Check if output file contains a valid OSCAL model
_, err := oscal.ValidOSCALModelAtPath(outputFile)
if err != nil {
message.Fatalf(err, "Output file %s is not a valid OSCAL model: %v", outputFile, err)
return fmt.Errorf("invalid OSCAL model at output: %v", err)
}

if SaveResources {
ResourcesDir = filepath.Join(filepath.Dir(outputFile))
// Set up the composition context
compositionCtx, err := composition.New(
composition.WithModelFromLocalPath(inputFile),
composition.WithRenderSettings("all", true),
composition.WithTemplateRenderer("all", common.TemplateConstants, common.TemplateVariables, setOpts),
)
if err != nil {
return fmt.Errorf("error creating composition context: %v", err)
}

if err := files.IsJsonOrYaml(opts.InputFile); err != nil {
message.Fatalf(err, "Invalid file extension: %s, requires .json or .yaml", opts.InputFile)
// Set up the validation context
validationCtx, err := validation.New(
validation.WithCompositionContext(compositionCtx, inputFile),
validation.WithResourcesDir(saveResources, filepath.Dir(outputFile)),
validation.WithAllowExecution(confirmExecution, runNonInteractively),
)
if err != nil {
return fmt.Errorf("error creating validation context: %v", err)
}

assessment, err := ValidateOnPath(opts.InputFile, opts.Target)
assessmentResults, err := validationCtx.ValidateOnPath(cmd.Context(), inputFile, target)
if err != nil {
message.Fatalf(err, "Validation error: %s", err)
return fmt.Errorf("error validating on path: %v", err)
}

if assessmentResults == nil {
return fmt.Errorf("assessment results are nil")
}

var model = oscalTypes_1_1_2.OscalModels{
Expand Down

0 comments on commit 5f94d8d

Please sign in to comment.