(imageName string)
| 349 | } |
| 350 | |
| 351 | func loadRegistryAuthFromDockerConfig(imageName string) (string, bool) { |
| 352 | registryHost, hasRegistry := extractRegistryHost(imageName) |
| 353 | cfg := config.LoadDefaultConfigFile(io.Discard) |
| 354 | if cfg == nil { |
| 355 | return "", false |
| 356 | } |
| 357 | candidates := make([]string, 0) |
| 358 | if hasRegistry { |
| 359 | candidates = append(candidates, registryHost, "https://"+registryHost, "http://"+registryHost) |
| 360 | } |
| 361 | if !hasRegistry || isDockerHubRegistry(registryHost) { |
| 362 | candidates = append(candidates, |
| 363 | "https://index.docker.io/v1/", |
| 364 | "index.docker.io", |
| 365 | "docker.io", |
| 366 | "registry-1.docker.io", |
| 367 | "https://registry-1.docker.io", |
| 368 | ) |
| 369 | } |
| 370 | seen := make(map[string]struct{}) |
| 371 | for _, key := range candidates { |
| 372 | if key == "" { |
| 373 | continue |
| 374 | } |
| 375 | if _, ok := seen[key]; ok { |
| 376 | continue |
| 377 | } |
| 378 | seen[key] = struct{}{} |
| 379 | auth, err := cfg.GetAuthConfig(key) |
| 380 | if err != nil { |
| 381 | continue |
| 382 | } |
| 383 | if auth.Username == "" && auth.Password == "" && auth.Auth == "" && auth.IdentityToken == "" && auth.RegistryToken == "" { |
| 384 | continue |
| 385 | } |
| 386 | authStr, err := registry.EncodeAuthConfig(registry.AuthConfig{ |
| 387 | Username: auth.Username, |
| 388 | Password: auth.Password, |
| 389 | Auth: auth.Auth, |
| 390 | ServerAddress: auth.ServerAddress, |
| 391 | IdentityToken: auth.IdentityToken, |
| 392 | RegistryToken: auth.RegistryToken, |
| 393 | }) |
| 394 | if err != nil { |
| 395 | return "", false |
| 396 | } |
| 397 | return authStr, true |
| 398 | } |
| 399 | return "", false |
| 400 | } |
| 401 | |
| 402 | func isDockerHubRegistry(host string) bool { |
| 403 | switch normalizeRegistryHost(host) { |
no test coverage detected