Skip to content

Commit

Permalink
feat(checks): Add aliasing support
Browse files Browse the repository at this point in the history
Fixes: aquasecurity/trivy#5691

Signed-off-by: Simar <[email protected]>
  • Loading branch information
simar7 committed Jan 10, 2024
1 parent 72340d1 commit a2051b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/rego/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type StaticMetadata struct {
AVDID string
Title string
ShortCode string
Aliases []string
Description string
Severity string
RecommendedActions string
Expand Down Expand Up @@ -99,6 +100,14 @@ func (sm *StaticMetadata) Update(meta map[string]any) error {
}
}

if raw, ok := meta["aliases"]; ok {
if aliases, ok := raw.([]interface{}); ok {
for _, a := range aliases {
sm.Aliases = append(sm.Aliases, fmt.Sprintf("%s", a))
}
}
}

var err error
if sm.CloudFormation, err = NewEngineMetadata("cloud_formation", meta); err != nil {
return err
Expand Down Expand Up @@ -191,7 +200,7 @@ func (m StaticMetadata) ToRule() scan.Rule {

return scan.Rule{
AVDID: m.AVDID,
Aliases: []string{m.ID},
Aliases: append(m.Aliases, m.ID),
ShortCode: m.ShortCode,
Summary: m.Title,
Explanation: m.Description,
Expand Down
3 changes: 3 additions & 0 deletions pkg/rego/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func Test_UpdateStaticMetadata(t *testing.T) {
AVDID: "a",
Title: "t",
ShortCode: "sc",
Aliases: []string{"a", "b", "c"},
Description: "d",
Severity: "s",
RecommendedActions: "ra",
Expand All @@ -36,6 +37,7 @@ func Test_UpdateStaticMetadata(t *testing.T) {
"avd_id": "a_n",
"title": "t_n",
"short_code": "sc_n",
"aliases": []any{"a_n", "b_n", "c_n"},
"description": "d_n",
"service": "srvc_n",
"provider": "pr_n",
Expand All @@ -54,6 +56,7 @@ func Test_UpdateStaticMetadata(t *testing.T) {
AVDID: "a_n",
Title: "t_n",
ShortCode: "sc_n",
Aliases: []string{"a", "b", "c", "a_n", "b_n", "c_n"},
Description: "d_n",
Severity: "S_N",
RecommendedActions: "ra_n",
Expand Down

0 comments on commit a2051b3

Please sign in to comment.