Skip to content

Commit

Permalink
more better godocs
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh committed Mar 16, 2023
1 parent 47f67fc commit 878df4d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/authn/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,20 @@ type defaultKeychain struct {
}

var (
// DefaultKeychain implements Keychain by interpreting the docker config file.
// DefaultKeychain implements Keychain by interpreting the Docker config file.
// This matches the behavior of tools like `docker` and `podman`.
//
// This keychain looks for credentials configured in a few places, in order:
//
// 1. $HOME/.docker/config.json
// 2. $DOCKER_CONFIG/config.json
// 3. $XDG_RUNTIME_DIR/containers/auth.json (for compatibility with Podman)
//
// If a config file is found and can be parsed, Resolve will return credentials
// configured by the file for the given registry.
//
// If no config file is found, Resolve returns Anonymous.
// If a config file is found but can't be parsed, Resolve returns an error.
DefaultKeychain Keychain = &defaultKeychain{}
)

Expand All @@ -63,6 +76,11 @@ const (
DefaultAuthKey = "https://" + name.DefaultRegistry + "/v1/"
)

// NewConfigKeychain implements Keychain by interpreting the Docker config file
// at the specified file path.
//
// It acts like DefaultKeychain except that the exact path of the file can be specified,
// instead of being dependent on environment variables and conventional file names.
func NewConfigKeychain(filename string) Keychain {
return &defaultKeychain{configFilePath: filename}
}
Expand Down Expand Up @@ -111,7 +129,6 @@ func getDefaultConfigFile() (*configfile.ConfigFile, error) {
return cf, nil
}

// Resolve implements Keychain.
func (dk *defaultKeychain) Resolve(target Resource) (Authenticator, error) {
dk.mu.Lock()
defer dk.mu.Unlock()
Expand Down

0 comments on commit 878df4d

Please sign in to comment.