mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-28 11:46:20 -04:00
Use credential store auth if it exists (#23)
This commit is contained in:
parent
3475db4ba4
commit
9f7b235849
1 changed files with 8 additions and 3 deletions
|
@ -44,16 +44,21 @@ func GetAuthConfig(username, password, registry string) (types.AuthConfig, error
|
||||||
return types.AuthConfig{}, nil
|
return types.AuthConfig{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authConfigs, err := dcfg.GetAllCredentials()
|
||||||
|
if err != nil {
|
||||||
|
return types.AuthConfig{}, fmt.Errorf("Getting credentials failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// if they passed a specific registry, return those creds _if_ they exist
|
// if they passed a specific registry, return those creds _if_ they exist
|
||||||
if registry != "" {
|
if registry != "" {
|
||||||
// try with the user input
|
// try with the user input
|
||||||
if creds, ok := dcfg.AuthConfigs[registry]; ok {
|
if creds, ok := authConfigs[registry]; ok {
|
||||||
return creds, nil
|
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://") {
|
||||||
if creds, ok := dcfg.AuthConfigs["https://"+registry]; ok {
|
if creds, ok := authConfigs["https://"+registry]; ok {
|
||||||
return creds, nil
|
return creds, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +71,7 @@ func GetAuthConfig(username, password, registry string) (types.AuthConfig, error
|
||||||
|
|
||||||
// Just set the auth config as the first registryURL, username and password
|
// Just set the auth config as the first registryURL, username and password
|
||||||
// found in the auth config.
|
// found in the auth config.
|
||||||
for _, creds := range dcfg.AuthConfigs {
|
for _, creds := range authConfigs {
|
||||||
return creds, nil
|
return creds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue