diff --git a/pkg/rego/metadata.go b/pkg/rego/metadata.go index ee6b5d1d2..6873dee02 100644 --- a/pkg/rego/metadata.go +++ b/pkg/rego/metadata.go @@ -20,6 +20,7 @@ type StaticMetadata struct { AVDID string Title string ShortCode string + Aliases []string Description string Severity string RecommendedActions string @@ -99,6 +100,8 @@ func (sm *StaticMetadata) Update(meta map[string]any) error { } } + sm.updateAliases(meta) + var err error if sm.CloudFormation, err = NewEngineMetadata("cloud_formation", meta); err != nil { return err @@ -111,6 +114,16 @@ func (sm *StaticMetadata) Update(meta map[string]any) error { return nil } +func (sm *StaticMetadata) updateAliases(meta map[string]any) { + 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)) + } + } + } +} + func (sm *StaticMetadata) FromAnnotations(annotations *ast.Annotations) error { sm.Title = annotations.Title sm.Description = annotations.Description @@ -191,7 +204,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, diff --git a/pkg/rego/metadata_test.go b/pkg/rego/metadata_test.go index 935c027d0..35c13ae2c 100644 --- a/pkg/rego/metadata_test.go +++ b/pkg/rego/metadata_test.go @@ -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", @@ -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", @@ -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",