MCPcopy Index your code
hub / github.com/docker/cli / readCredentials

Function readCredentials

cli/command/container/auth_config_utils.go:25–46  ·  view source on GitHub ↗

readCredentials resolves auth-config from the current environment to be applied to the container if the `--use-api-socket` flag is set. - If a valid "DOCKER_AUTH_CONFIG" env-var is found, and it contains credentials, it's value is used. - If no "DOCKER_AUTH_CONFIG" env-var is found, or it does not

(dockerCLI config.Provider)

Source from the content-addressed store, hash-verified

23//
24// A nil value is returned if neither option contained any credentials.
25func readCredentials(dockerCLI config.Provider) (creds map[string]types.AuthConfig, _ error) {
26 if v, ok := os.LookupEnv("DOCKER_AUTH_CONFIG"); ok && v != "" {
27 // The results are expected to have been unmarshaled the same as
28 // when reading from a config-file, which includes decoding the
29 // base64-encoded "username:password" into the "UserName" and
30 // "Password" fields.
31 ac := &configfile.ConfigFile{}
32 if err := ac.LoadFromReader(strings.NewReader(v)); err != nil {
33 return nil, fmt.Errorf("failed to read credentials from DOCKER_AUTH_CONFIG: %w", err)
34 }
35 if len(ac.AuthConfigs) > 0 {
36 return ac.AuthConfigs, nil
37 }
38 }
39
40 // Resolve this here for later, ensuring we error our before we create the container.
41 creds, err := dockerCLI.ConfigFile().GetAllCredentials()
42 if err != nil {
43 return nil, fmt.Errorf("resolving credentials failed: %w", err)
44 }
45 return creds, nil
46}

Callers 1

createContainerFunction · 0.85

Calls 4

LoadFromReaderMethod · 0.95
LookupEnvMethod · 0.80
GetAllCredentialsMethod · 0.80
ConfigFileMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…