Skip to content

Commit

Permalink
Make risk magnitude a struct (#1352)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaym authored Jul 12, 2024
1 parent 884152d commit 4ca0be1
Show file tree
Hide file tree
Showing 9 changed files with 1,906 additions and 1,688 deletions.
46 changes: 31 additions & 15 deletions internal/bundle/bundle.yac.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions internal/bundle/bundle_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,19 @@ func (x *Remediation) MarshalYAML() (interface{}, error) {

return x.Items, nil
}

func (x *RiskMagnitude) UnmarshalYAML(node *yaml.Node) error {
x.addFileContext(node)

var res float32
if err := node.Decode(&res); err == nil {
x.Value = res
return nil
}

type tmp RiskMagnitude
if err := node.Decode((*tmp)(x)); err != nil {
return errors.Wrap(err, "can't unmarshal risk magnitude")
}
return nil
}
2 changes: 1 addition & 1 deletion internal/bundle/yacit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func main() {
res := yacit.New(yacit.YacItConfig{
SkipUnmarshal: []string{
"Impact", "ImpactValue", "Filters", "Remediation",
"Impact", "ImpactValue", "Filters", "Remediation", "RiskMagnitude",
},
Package: "bundle",
// field names with sort weight
Expand Down
4 changes: 2 additions & 2 deletions internal/datalakes/inmemory/policyresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ func (db *Db) GetScoredRisks(ctx context.Context, assetMrn string) (*policy.Scor
return nil, errors.New("cannot find risk metadata for " + risk.Mrn)
}
riskInfo := raw.(*policy.RiskFactor)
srisk.IsAbsolute = riskInfo.IsAbsolute
srisk.Risk = riskInfo.Magnitude
srisk.IsToxic = riskInfo.GetMagnitude().GetIsToxic()
srisk.Risk = riskInfo.GetMagnitude().GetValue()
if !risk.IsDetected {
srisk.Risk *= -1
}
Expand Down
Loading

0 comments on commit 4ca0be1

Please sign in to comment.