Skip to content

Commit

Permalink
clean up scope builder and remove fmt print
Browse files Browse the repository at this point in the history
  • Loading branch information
simskij committed Dec 21, 2020
1 parent cf6a71d commit 8911951
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions pkg/registry/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,25 @@ func GetAuthURL(challenge string, img string) (*url.URL, error) {
// GetScopeFromImageName normalizes an image name for use as scope during auth and head requests
func GetScopeFromImageName(img, svc string) string {
parts := strings.Split(img, "/")
scopeImage := ""

if len(parts) > 2 {
if strings.Contains(svc, "docker.io") {
fmt.Printf("Identified dockerhub image")
scopeImage = fmt.Sprintf("%s/%s", parts[1], strings.Join(parts[2:], "/"))
} else {
scopeImage = strings.Join(parts, "/")
return fmt.Sprintf("%s/%s", parts[1], strings.Join(parts[2:], "/"))
}
} else if len(parts) == 2 {
return strings.Join(parts, "/")
}

if len(parts) == 2 {
if strings.Contains(parts[0], "docker.io") {
scopeImage = fmt.Sprintf("library/%s", parts[1])
} else {
scopeImage = strings.Replace(img, svc+"/", "", 1)
return fmt.Sprintf("library/%s", parts[1])
}
} else if strings.Contains(svc, "docker.io") {
scopeImage = fmt.Sprintf("library/%s", parts[0])
} else {
scopeImage = img
return strings.Replace(img, svc+"/", "", 1)
}

if strings.Contains(svc, "docker.io") {
return fmt.Sprintf("library/%s", parts[0])
}
return scopeImage
return img
}

// GetChallengeURL creates a URL object based on the image info
Expand Down

0 comments on commit 8911951

Please sign in to comment.