Skip to content

Commit 5337c9c

Browse files
committed
Refactor Docker image parsing and remove redundant checkDockerSupport
1 parent 06c852a commit 5337c9c

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

commands/curation/curationaudit.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var supportedTech = map[techutils.Technology]func(ca *CurationAuditCommand) (boo
104104
return ca.checkSupportByVersionOrEnv(techutils.Gem, MinArtiGradleGemSupport)
105105
},
106106
techutils.Docker: func(ca *CurationAuditCommand) (bool, error) {
107-
return ca.DockerImageName() != "", nil
107+
return ca.DockerImageName() != "", nil
108108
},
109109
}
110110

@@ -132,10 +132,6 @@ func (ca *CurationAuditCommand) checkSupportByVersionOrEnv(tech techutils.Techno
132132
return true, nil
133133
}
134134

135-
func (ca *CurationAuditCommand) checkDockerSupport() (bool, error) {
136-
return ca.DockerImageName() != "", nil
137-
}
138-
139135
func (ca *CurationAuditCommand) getRtVersion(tech techutils.Technology) (string, error) {
140136
rtManager, _, err := ca.getRtManagerAndAuth(tech)
141137
if err != nil {

sca/bom/buildinfo/technologies/docker/docker.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ func ParseDockerImage(imageName string) (*DockerImageInfo, error) {
3939
}
4040
}
4141

42-
parts := strings.Split(imageName, "/")
42+
parts := strings.SplitN(imageName, "/", 2)
4343
if len(parts) < 2 {
4444
return nil, fmt.Errorf("invalid docker image format: '%s'", imageName)
4545
}
4646

4747
info.Registry = parts[0]
48-
repo, image := parseRegistryAndExtract(info.Registry, parts[1:])
48+
repo, image := parseRegistryAndExtract(info.Registry, parts[1])
4949
info.Repo = repo
5050
info.Image = image
5151

@@ -55,8 +55,8 @@ func ParseDockerImage(imageName string) (*DockerImageInfo, error) {
5555
return info, nil
5656
}
5757

58-
func parseRegistryAndExtract(registry string, remainingParts []string) (repo, image string) {
59-
image = strings.Join(remainingParts, "/")
58+
func parseRegistryAndExtract(registry string, remaining string) (repo, image string) {
59+
image = remaining
6060

6161
// SaaS subdomain: <INSTANCE>-<REPO>.jfrog.io/image:tag (repo in subdomain, check first)
6262
if matches := jfrogSubdomainPattern.FindStringSubmatch(registry); len(matches) > 2 {
@@ -71,10 +71,9 @@ func parseRegistryAndExtract(registry string, remainingParts []string) (repo, im
7171
return
7272
}
7373

74-
// Repository path: <REGISTRY>/<REPO>/image:tag (2+ parts means repo in path)
75-
if len(remainingParts) >= 2 {
76-
repo = remainingParts[0]
77-
image = strings.Join(remainingParts[1:], "/")
74+
// Repository path: <REGISTRY>/<REPO>/image:tag (repo in path if contains /)
75+
if strings.Contains(remaining, "/") {
76+
repo, image, _ = strings.Cut(remaining, "/")
7877
return
7978
}
8079

sca/bom/buildinfo/technologies/docker/docker_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ func TestParseDockerImage(t *testing.T) {
109109
expectedImg: "nginx",
110110
expectedTag: "latest",
111111
},
112+
{
113+
name: "Tag with multiple dots",
114+
imageName: "acme.jfrog.io/docker-local/myapp:1.0.0",
115+
expectedRepo: "docker-local",
116+
expectedImg: "myapp",
117+
expectedTag: "1.0.0",
118+
},
112119
}
113120

114121
for _, tt := range tests {

0 commit comments

Comments
 (0)