From 1072bca4fbcbb34650684962dc18f8a6faab9777 Mon Sep 17 00:00:00 2001 From: Simar Date: Mon, 11 Dec 2023 21:55:03 -0700 Subject: [PATCH] feat(rego): Add aliases for checks Addresses: https://github.com/aquasecurity/trivy/issues/5691 --- pkg/rego/metadata.go | 11 +++++++++++ pkg/rego/metadata_test.go | 3 +++ 2 files changed, 14 insertions(+) diff --git a/pkg/rego/metadata.go b/pkg/rego/metadata.go index ee6b5d1d..1e0b2693 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 @@ -55,10 +56,20 @@ func (sm *StaticMetadata) Update(meta map[string]any) error { } } + updSlice := func(field *[]string, key string) { + if raw, ok := meta[key]; ok { + if _, ok := raw.([]string); ok { + *field = make([]string, 0) + *field = append(*field, raw.([]string)...) + } + } + } + upd(&sm.ID, "id") upd(&sm.AVDID, "avd_id") upd(&sm.Title, "title") upd(&sm.ShortCode, "short_code") + updSlice(&sm.Aliases, "aliases") upd(&sm.Description, "description") upd(&sm.Service, "service") upd(&sm.Provider, "provider") diff --git a/pkg/rego/metadata_test.go b/pkg/rego/metadata_test.go index 935c027d..cd1ef728 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": []string{"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_n", "b_n", "c_n"}, Description: "d_n", Severity: "S_N", RecommendedActions: "ra_n",