summaryrefslogtreecommitdiff
path: root/registry-scanner/pkg/image/kustomize.go
diff options
context:
space:
mode:
authorIshita Sequeira <46771830+ishitasequeira@users.noreply.github.com>2024-12-04 21:34:58 +0530
committerGitHub <noreply@github.com>2024-12-04 11:04:58 -0500
commit8076d2005ea625c73604073fca43df38eb675751 (patch)
tree1570ba5969882a26e021875da86bee6850a9cfc6 /registry-scanner/pkg/image/kustomize.go
parentc3f0eff54daf871fa1c274462b17f5149c11d368 (diff)
Add image folder to registry scanner (#952)
Signed-off-by: Ishita Sequeira <ishiseq29@gmail.com>
Diffstat (limited to 'registry-scanner/pkg/image/kustomize.go')
-rw-r--r--registry-scanner/pkg/image/kustomize.go39
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
+}