diff options
Diffstat (limited to 'registry-scanner/pkg/image/kustomize.go')
| -rw-r--r-- | registry-scanner/pkg/image/kustomize.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/registry-scanner/pkg/image/kustomize.go b/registry-scanner/pkg/image/kustomize.go new file mode 100644 index 0000000..ef7c88b --- /dev/null +++ b/registry-scanner/pkg/image/kustomize.go @@ -0,0 +1,39 @@ +package image + +import ( + "strings" +) + +// Shamelessly ripped from ArgoCD CLI code + +type KustomizeImage string + +func (i KustomizeImage) delim() string { + for _, d := range []string{"=", ":", "@"} { + if strings.Contains(string(i), d) { + return d + } + } + return ":" +} + +// if the image name matches (i.e. up to the first delimiter) +func (i KustomizeImage) Match(j KustomizeImage) bool { + delim := j.delim() + if !strings.Contains(string(j), delim) { + return false + } + return strings.HasPrefix(string(i), strings.Split(string(j), delim)[0]) +} + +type KustomizeImages []KustomizeImage + +// find the image or -1 +func (images KustomizeImages) Find(image KustomizeImage) int { + for i, a := range images { + if a.Match(image) { + return i + } + } + return -1 +} |
