GetCredentialsStore returns a new credentials store from the settings in the configuration file
(registryHostname string)
| 319 | // GetCredentialsStore returns a new credentials store from the settings in the |
| 320 | // configuration file |
| 321 | func (c *ConfigFile) GetCredentialsStore(registryHostname string) credentials.Store { |
| 322 | store := credentials.NewFileStore(c) |
| 323 | |
| 324 | if helper := getConfiguredCredentialStore(c, getAuthConfigKey(registryHostname)); helper != "" { |
| 325 | store = newNativeStore(c, helper) |
| 326 | } |
| 327 | |
| 328 | envConfig := os.Getenv(DockerEnvConfigKey) |
| 329 | if envConfig == "" { |
| 330 | return store |
| 331 | } |
| 332 | |
| 333 | authConfig, err := parseEnvConfig(envConfig) |
| 334 | if err != nil { |
| 335 | _, _ = fmt.Fprintln(os.Stderr, "Failed to create credential store from DOCKER_AUTH_CONFIG: ", err) |
| 336 | return store |
| 337 | } |
| 338 | |
| 339 | // use DOCKER_AUTH_CONFIG if set |
| 340 | // it uses the native or file store as a fallback to fetch and store credentials |
| 341 | envStore, err := memorystore.New( |
| 342 | memorystore.WithAuthConfig(authConfig), |
| 343 | memorystore.WithFallbackStore(store), |
| 344 | ) |
| 345 | if err != nil { |
| 346 | _, _ = fmt.Fprintln(os.Stderr, "Failed to create credential store from DOCKER_AUTH_CONFIG: ", err) |
| 347 | return store |
| 348 | } |
| 349 | |
| 350 | return envStore |
| 351 | } |
| 352 | |
| 353 | func parseEnvConfig(v string) (map[string]types.AuthConfig, error) { |
| 354 | envConfig := &configEnv{} |