mirror of
https://github.com/genuinetools/reg.git
synced 2024-06-28 10:24:17 -04:00
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
This commit is contained in:
parent
9f7b235849
commit
bd81e2bbf6
|
@ -55,6 +55,21 @@ func GetAuthConfig(username, password, registry string) (types.AuthConfig, error
|
||||||
if creds, ok := authConfigs[registry]; ok {
|
if creds, ok := authConfigs[registry]; ok {
|
||||||
return creds, nil
|
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
|
// add https:// to user input and try again
|
||||||
// see https://github.com/jessfraz/reg/issues/32
|
// see https://github.com/jessfraz/reg/issues/32
|
||||||
if !strings.HasPrefix(registry, "https://") && !strings.HasPrefix(registry, "http://") {
|
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
|
return creds, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Using registry '%s' with no authentication\n", registry)
|
||||||
|
|
||||||
// Otherwise just use the registry with no auth.
|
// Otherwise just use the registry with no auth.
|
||||||
return setDefaultRegistry(types.AuthConfig{
|
return setDefaultRegistry(types.AuthConfig{
|
||||||
|
@ -76,6 +92,7 @@ func GetAuthConfig(username, password, registry string) (types.AuthConfig, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't use any authentication.
|
// Don't use any authentication.
|
||||||
|
fmt.Println("Not using any authentication")
|
||||||
return types.AuthConfig{}, nil
|
return types.AuthConfig{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue