Skip to content

Commit

Permalink
fix(profile): support for profile instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtkeller committed Oct 8, 2024
1 parent 841e8c3 commit d301564
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/pkg/common/oscal/complete-schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
type OSCALModel interface {
GetType() string
GetCompleteModel() *oscalTypes.OscalModels
MakeDeterministic()
MakeDeterministic() error
HandleExisting(string) error
New([]byte) error
NewModel([]byte) error
}

func NewOscalModel(data []byte) (*oscalTypes.OscalModels, error) {
Expand Down
18 changes: 12 additions & 6 deletions src/pkg/common/oscal/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ type Profile struct {
Model *oscalTypes.Profile
}

func NewProfile() *Profile {
var profile Profile
profile.Model = nil
return &profile
}

func (p *Profile) GetType() string {
return "profile"
}
Expand All @@ -25,10 +31,10 @@ func (p *Profile) GetCompleteModel() *oscalTypes.OscalModels {
}
}

func (p *Profile) MakeDeterministic() {

// Default behavior of a nil model - do nothing
if p.Model != nil {
func (p *Profile) MakeDeterministic() error {
if p.Model == nil {
return fmt.Errorf("cannot make nil model deterministic")
} else {
// sort the import items by source string
importItems := p.Model.Imports

Expand Down Expand Up @@ -65,7 +71,7 @@ func (p *Profile) MakeDeterministic() {
}
}

return
return nil
}

func (p *Profile) HandleExisting(filepath string) error {
Expand All @@ -81,7 +87,7 @@ func (p *Profile) HandleExisting(filepath string) error {
}

// Create a new profile model
func (p *Profile) New(data []byte) error {
func (p *Profile) NewModel(data []byte) error {

var oscalModels oscalTypes.OscalModels

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/common/oscal/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestMakeDeterministic(t *testing.T) {
})

t.Run("Profile with empty model", func(t *testing.T) {
var profile *oscal.Profile
profile := oscal.NewProfile()

test(t, profile, []string{}, []string{}, true)
})
Expand Down
4 changes: 2 additions & 2 deletions src/test/e2e/cmd/generate_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func TestGenerateProfileCommand(t *testing.T) {
t.Errorf("error reading generated profile: %v\n", err)
}

var profile oscal.Profile
profile := oscal.NewProfile()

// Create the new profile object
err = profile.New(compiledBytes)
err = profile.NewModel(compiledBytes)
if err != nil {
t.Errorf("error creating oscal model from profile artifact: %v\n", err)
}
Expand Down

0 comments on commit d301564

Please sign in to comment.