Use library GH keychain instead of our own (#2624)

Signed-off-by: Matej Vašek <mvasek@redhat.com>
This commit is contained in:
Matej Vašek 2024-12-18 19:13:10 +01:00 committed by GitHub
parent 770949b7d2
commit 77489858d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 13 deletions

View File

@ -31,6 +31,7 @@ import (
docker "github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/google/go-containerregistry/pkg/authn"
ghAuth "github.com/google/go-containerregistry/pkg/authn/github"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/mutate"
@ -737,19 +738,7 @@ func newGHClient(ctx context.Context) *github.Client {
})))
}
var DefaultKeychain = authn.NewMultiKeychain(ghKeychain{}, authn.DefaultKeychain)
type ghKeychain struct{}
func (g ghKeychain) Resolve(resource authn.Resource) (authn.Authenticator, error) {
if resource.RegistryStr() != "ghcr.io" {
return authn.Anonymous, nil
}
return &authn.Basic{
Username: "gh-action",
Password: os.Getenv("GITHUB_TOKEN"),
}, nil
}
var DefaultKeychain = authn.NewMultiKeychain(ghAuth.Keychain, authn.DefaultKeychain)
func dockerDaemonAuthStr(img string) (string, error) {
ref, err := name.ParseReference(img)