-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ internal: add blast radius computation (#1191)
Signed-off-by: Dominik Richter <[email protected]>
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package policy | ||
|
||
type BlastRadiusIndicator string | ||
|
||
const ( | ||
BlastRadius_Small BlastRadiusIndicator = "s" | ||
BlastRadius_Medium BlastRadiusIndicator = "m" | ||
BlastRadius_Large BlastRadiusIndicator = "l" | ||
) | ||
|
||
// BlastRadiusConfig for custom blast radius indicators | ||
type BlastRadiusConfig struct { | ||
SmallPct float32 | ||
MediumPct float32 | ||
CategoryThreshold float32 | ||
} | ||
|
||
// DefaultBlastRadiusConfig | ||
var DefaultBlastRadiusConfig = BlastRadiusConfig{ | ||
SmallPct: 0.05, | ||
MediumPct: 0.20, | ||
CategoryThreshold: 20, | ||
} | ||
|
||
// BlastRadius retrieves the blast radius indicator and assets in this category. | ||
// It requires a weight as input | ||
func (b *BlastRadiusConfig) Indicator(totalWeight float32, weight float32) BlastRadiusIndicator { | ||
rel := weight / totalWeight | ||
if rel < b.SmallPct { | ||
return BlastRadius_Small | ||
} | ||
if rel < b.MediumPct { | ||
return BlastRadius_Medium | ||
} | ||
return BlastRadius_Large | ||
} |