Skip to content

Commit

Permalink
Fix username/password auth
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao committed Apr 30, 2024
1 parent 98111c4 commit b8815f4
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions image/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ func tryRemote(ctx context.Context, imageName string, ref name.Reference, option
}

// Username/Password based auth.
for _, cred := range option.RegistryOptions.Credentials {
remoteOpts = append(remoteOpts, remote.WithAuth(&authn.Basic{
Username: cred.Username,
Password: cred.Password,
}))
}

domain := ref.Context().RegistryStr()
auth := registry.GetToken(ctx, domain, option.RegistryOptions)
if auth.Username != "" && auth.Password != "" {
remoteOpts = append(remoteOpts, remote.WithAuth(&auth))
} else if option.RegistryOptions.RegistryToken != "" {
bearer := authn.Bearer{Token: option.RegistryOptions.RegistryToken}
remoteOpts = append(remoteOpts, remote.WithAuth(&bearer))
if len(option.RegistryOptions.Credentials) > 0 {
for _, cred := range option.RegistryOptions.Credentials {
remoteOpts = append(remoteOpts, remote.WithAuth(&authn.Basic{
Username: cred.Username,
Password: cred.Password,
}))
}
} else {
remoteOpts = append(remoteOpts, remote.WithAuthFromKeychain(authn.DefaultKeychain))
domain := ref.Context().RegistryStr()
auth := registry.GetToken(ctx, domain, option.RegistryOptions)
if auth.Username != "" && auth.Password != "" {
remoteOpts = append(remoteOpts, remote.WithAuth(&auth))
} else if option.RegistryOptions.RegistryToken != "" {
bearer := authn.Bearer{Token: option.RegistryOptions.RegistryToken}
remoteOpts = append(remoteOpts, remote.WithAuth(&bearer))
}
}

if platform := option.RegistryOptions.Platform.Platform; platform != nil {
Expand Down

0 comments on commit b8815f4

Please sign in to comment.