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

types: Add SystemContext.GetAuth #588

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 18 additions & 0 deletions credentials/single/single.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Package single implements a basic credentials helper with a single username and secret.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It’s not at all obvious to me that this warrants a top-level namespace here, but that depends on much else.)

package single

import (
"github.com/docker/docker-credential-helpers/credentials"
)

// AuthStore is a basic credentials store that holds a single entry.
type AuthStore credentials.Credentials

// Get retrieves credentials from the store.
func (s *AuthStore) Get(serverURL string) (string, string, error) {
if s == nil || serverURL != s.ServerURL {
return "", "", credentials.NewErrCredentialsNotFound()
}

return s.Username, s.Secret, nil
}
12 changes: 9 additions & 3 deletions docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,17 @@ func dockerCertDir(sys *types.SystemContext, hostPort string) (string, error) {
// “write” specifies whether the client will be used for "write" access (in particular passed to lookaside.go:toplevelFromSection)
func newDockerClientFromRef(sys *types.SystemContext, ref dockerReference, write bool, actions string) (*dockerClient, error) {
registry := reference.Domain(ref.ref)
username, password, err := config.GetAuthentication(sys, reference.Domain(ref.ref))
getAuth := sys.GetAuth
if getAuth == nil {
getAuth = func(serverURL string) (string, string, error) {
return config.GetAuthentication(sys, serverURL)
}
}
username, password, err := getAuth(registry)
if err != nil {
return nil, errors.Wrapf(err, "error getting username and password")
}

sigBase, err := configuredSignatureStorageBase(sys, ref, write)
if err != nil {
return nil, err
Expand Down Expand Up @@ -327,8 +334,7 @@ func SearchRegistry(ctx context.Context, sys *types.SystemContext, registry, ima
v2Res := &V2Results{}
v1Res := &V1Results{}

// Get credentials from authfile for the underlying hostname
username, password, err := config.GetAuthentication(sys, registry)
username, password, err := sys.GetAuth(registry)
if err != nil {
return nil, errors.Wrapf(err, "error getting username and password")
}
Expand Down
Loading