From bd81e2bbf6c9ccc7dcbcf766b9025647e61d0ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pra=C5=BCak?= Date: Thu, 22 Feb 2018 01:52:28 +0100 Subject: [PATCH] utils/auth: support registry URLs with protocol (#68) - adds the option to pass --reqistry with http:// or https:// and still benefit from .docker/config.json credentials --- utils/utils.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index f3c5c496..b564d683 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -55,6 +55,21 @@ func GetAuthConfig(username, password, registry string) (types.AuthConfig, error if creds, ok := authConfigs[registry]; ok { return creds, nil } + + // remove https:// from user input and try again + if strings.HasPrefix(registry, "https://") { + if creds, ok := authConfigs[strings.TrimPrefix(registry, "https://")]; ok { + return creds, nil + } + } + + // remove http:// from user input and try again + if strings.HasPrefix(registry, "http://") { + if creds, ok := authConfigs[strings.TrimPrefix(registry, "http://")]; ok { + return creds, nil + } + } + // add https:// to user input and try again // see https://github.com/jessfraz/reg/issues/32 if !strings.HasPrefix(registry, "https://") && !strings.HasPrefix(registry, "http://") { @@ -62,6 +77,7 @@ func GetAuthConfig(username, password, registry string) (types.AuthConfig, error return creds, nil } } + fmt.Printf("Using registry '%s' with no authentication\n", registry) // Otherwise just use the registry with no auth. return setDefaultRegistry(types.AuthConfig{ @@ -76,6 +92,7 @@ func GetAuthConfig(username, password, registry string) (types.AuthConfig, error } // Don't use any authentication. + fmt.Println("Not using any authentication") return types.AuthConfig{}, nil }