Skip to content

Commit

Permalink
feat: enhance get docker auth
Browse files Browse the repository at this point in the history
allow registry with suffix /
  • Loading branch information
l-qing committed Aug 26, 2023
1 parent dcd27cb commit 9aaded4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apis/artifacts/v1alpha1/registry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func GetAuthFromDockerConfigJson(registry string, dockerConfigJsonBytes []byte)
candidate = append(candidate, u.Host, "https://"+u.Host, "http://"+u.Host)
}

// generate all possible address
for address, auth := range dockerConfig.Auths {
address = strings.TrimRight(address, "/")
dockerConfig.Auths[address] = auth
}

for _, address := range candidate {
if auth, ok := dockerConfig.Auths[address]; ok {
return auth.Username, auth.Password, nil
Expand Down
7 changes: 7 additions & 0 deletions apis/artifacts/v1alpha1/registry_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ var _ = Describe("Test.GetAuthFromDockerConfigJson", func() {
"https://docker.io/user": {
"username": "u4",
"password": "p4"
},
"https://suffix.docker.io/////": {
"username": "u5",
"password": "p5"
}
}
}
Expand Down Expand Up @@ -82,6 +86,9 @@ var _ = Describe("Test.GetAuthFromDockerConfigJson", func() {
Entry("just matched registry", "https://docker.io/user", mockAuths,
"u4", "p4", nil,
),
Entry("matched registry suffixed with /", "https://suffix.docker.io", mockAuths,
"u5", "p5", nil,
),
Entry("fallback to host", "https://docker.io/not-exist", mockAuths,
"u1", "p1", nil,
),
Expand Down

0 comments on commit 9aaded4

Please sign in to comment.