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

Make risk magnitude a struct #1352

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious: does having the field here means that it will be unmarshalled using our own UnmarshalJSON func?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means don't generate the unmarshal function because we will write it manually

},
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
Loading