MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / loadRegistryAuthFromDockerConfig

Function loadRegistryAuthFromDockerConfig

agent/utils/docker/docker.go:351–400  ·  view source on GitHub ↗
(imageName string)

Source from the content-addressed store, hash-verified

349}
350
351func 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
402func isDockerHubRegistry(host string) bool {
403 switch normalizeRegistryHost(host) {

Callers 2

PullImageWithProcessMethod · 0.85
PullImageFunction · 0.85

Calls 3

extractRegistryHostFunction · 0.85
isDockerHubRegistryFunction · 0.85
GetAuthConfigMethod · 0.80

Tested by

no test coverage detected