Fix host auth key format
This commit is contained in:
@@ -81,6 +81,9 @@ func wrap(host *host, registries ...Registry) (*cli, error) {
|
|||||||
|
|
||||||
auths := map[string]cfgtypes.AuthConfig{}
|
auths := map[string]cfgtypes.AuthConfig{}
|
||||||
for k, v := range host.auths {
|
for k, v := range host.auths {
|
||||||
|
if k != config.DockerRegistryAuth {
|
||||||
|
k = credentials.ConvertToHostname(k)
|
||||||
|
}
|
||||||
auths[k] = cfgtypes.AuthConfig{
|
auths[k] = cfgtypes.AuthConfig{
|
||||||
ServerAddress: v.ServerAddress,
|
ServerAddress: v.ServerAddress,
|
||||||
Username: v.Username,
|
Username: v.Username,
|
||||||
@@ -95,10 +98,6 @@ func wrap(host *host, registries ...Registry) (*cli, error) {
|
|||||||
if key == "" {
|
if key == "" {
|
||||||
key = h.Hostname
|
key = h.Hostname
|
||||||
}
|
}
|
||||||
// Add a scheme if it's missing.
|
|
||||||
if !strings.Contains(key, "://") {
|
|
||||||
key = "https://" + key
|
|
||||||
}
|
|
||||||
|
|
||||||
auths[key] = cfgtypes.AuthConfig{
|
auths[key] = cfgtypes.AuthConfig{
|
||||||
ServerAddress: h.Hostname,
|
ServerAddress: h.Hostname,
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ func TestWrappedAuth(t *testing.T) {
|
|||||||
config.DockerRegistryAuth: {
|
config.DockerRegistryAuth: {
|
||||||
Username: "resource-dockerhub-user",
|
Username: "resource-dockerhub-user",
|
||||||
Password: "resource-dockerhub-password",
|
Password: "resource-dockerhub-password",
|
||||||
ServerAddress: config.DockerRegistryAuth,
|
ServerAddress: config.DockerRegistryDNS,
|
||||||
},
|
},
|
||||||
"misc": {
|
"misc": {
|
||||||
Username: "host-misc-user",
|
Username: "host-misc-user",
|
||||||
@@ -99,9 +99,9 @@ func TestWrappedAuth(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, cli.auths)
|
assert.Equal(t, expected, cli.auths)
|
||||||
assert.Len(t, h.auths, 2) // Host auth is unchanged.
|
assert.Len(t, h.auths, 2) // In-memory host auth is unchanged.
|
||||||
|
|
||||||
// Assert that our host's auth is untouched.
|
// Assert that our on-disk host's auth is untouched.
|
||||||
realhostRefreshed, err := newHost(nil)
|
realhostRefreshed, err := newHost(nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, realhost.auths, realhostRefreshed.auths)
|
assert.Equal(t, realhost.auths, realhostRefreshed.auths)
|
||||||
|
|||||||
Reference in New Issue
Block a user