Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance get docker auth #479

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
l-qing marked this conversation as resolved.
Show resolved Hide resolved
}

for _, address := range candidate {
if auth, ok := dockerConfig.Auths[address]; ok {
return auth.Username, auth.Password, nil
Expand Down
10 changes: 10 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,12 @@ 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,
nanjingfm marked this conversation as resolved.
Show resolved Hide resolved
"u5", "p5", 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