Skip to content

Commit

Permalink
feat(rego): Add aliases for checks
Browse files Browse the repository at this point in the history
  • Loading branch information
simar7 committed Jan 4, 2024
1 parent f3eacbb commit 1072bca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 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 @@ -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")
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": []string{"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_n", "b_n", "c_n"},
Description: "d_n",
Severity: "S_N",
RecommendedActions: "ra_n",
Expand Down

0 comments on commit 1072bca

Please sign in to comment.