Skip to content

Commit

Permalink
fix(registry/index): do not add artifact name to keywords if already…
Browse files Browse the repository at this point in the history
… present

The artifact name is added to the list of keywords when generating the index.yaml
file. It could happen that the list of keywords in registry.yaml already contains
the artifact name. This fix checks if the artifact name is contained in the keywords,
if not adds it

Signed-off-by: Aldo Lacuku <[email protected]>
  • Loading branch information
alacuku authored and poiana committed May 23, 2023
1 parent 6da15ae commit b2290ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion build/registry/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func pluginRulesToIndexEntry(rf Rulesfile, registry, repo string) *index.Entry {
Repository: repo,
Description: rf.Description,
Home: rf.URL,
Keywords: append(rf.Keywords, rf.Name),
Keywords: appendIfNotPresent(rf.Keywords, rf.Name),
License: rf.License,
Maintainers: rf.Maintainers,
Sources: []string{rf.URL},
Expand Down Expand Up @@ -69,3 +69,16 @@ func upsertIndexFile(r *Registry, ociArtifacts map[string]string, indexPath stri

return i.Write(indexPath)
}

// Add new item to a slice if not present.
func appendIfNotPresent(keywords []string, kw string) []string {
// If the keyword already exist do nothing.
for i := range keywords {
if keywords[i] == kw {
return keywords
}
}

// Add the keyword
return append(keywords, kw)
}
2 changes: 2 additions & 0 deletions build/registry/testdata/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ rulesfiles:
email: [email protected]
path: rules/falco_rules.yaml
license: apache-2.0
keywords:
- falco
url: https://github.com/falcosecurity/rules/blob/main/rules/falco_rules.yaml
- name: applications
description: Application rules
Expand Down

0 comments on commit b2290ad

Please sign in to comment.