Merge pull request #30963 from TerryHowe/oras-v2-login

Fix Oras v2 login
This commit is contained in:
Robert Sirchia 2025-06-13 10:57:59 -04:00 committed by GitHub
commit d823a497a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -289,16 +289,16 @@ func (c *Client) Login(host string, options ...LoginOption) error {
return err
}
reg.PlainHTTP = c.plainHTTP
cred := auth.Credential{Username: c.username, Password: c.password}
c.authorizer.ForceAttemptOAuth2 = true
reg.Client = c.authorizer
ctx := context.Background()
cred, err := c.authorizer.Credential(ctx, host)
if err != nil {
return fmt.Errorf("fetching credentials for %q: %w", host, err)
}
if err := reg.Ping(ctx); err != nil {
return fmt.Errorf("authenticating to %q: %w", host, err)
c.authorizer.ForceAttemptOAuth2 = false
if err := reg.Ping(ctx); err != nil {
return fmt.Errorf("authenticating to %q: %w", host, err)
}
}
// The credentialsStore loader does not handle empty files. So, there is a workaround.