Skip to content

Commit 514ca9a

Browse files
committed
cli/command: explicitly map AuthConfig fields instead of a direct cast
Commit [cli@27b2797] forked the AuthConfig type from the API, and changed existing code to do a direct cast / convert of the forked type to the API type. This can cause issues if the API types diverges, such as the removal of the Email field. This patch explicitly maps each field to the corresponding API type, but adds some TODOs, because various code-paths only included a subset of the fields, which may be intentional for fields that were meant to be handled on the daemon / registry-client only. We should evaluate these conversions to make sure these fields should be sent from the client or not (and possibly even removed from the API type). [cli@27b2797]: 27b2797 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 75f3c08 commit 514ca9a

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

cli/command/registry.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registrytypes.IndexInf
5050
}
5151

5252
a, _ := cfg.GetAuthConfig(configKey)
53-
return registrytypes.AuthConfig(a)
53+
return registrytypes.AuthConfig{
54+
Username: a.Username,
55+
Password: a.Password,
56+
ServerAddress: a.ServerAddress,
57+
58+
// TODO(thaJeztah): Are these expected to be included?
59+
Auth: a.Auth,
60+
IdentityToken: a.IdentityToken,
61+
RegistryToken: a.RegistryToken,
62+
}
5463
}
5564

5665
// GetDefaultAuthConfig gets the default auth config given a serverAddress
@@ -69,9 +78,17 @@ func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serve
6978
}, err
7079
}
7180
}
72-
authCfg.ServerAddress = serverAddress
73-
authCfg.IdentityToken = ""
74-
return registrytypes.AuthConfig(authCfg), nil
81+
82+
return registrytypes.AuthConfig{
83+
Username: authCfg.Username,
84+
Password: authCfg.Password,
85+
ServerAddress: serverAddress,
86+
87+
// TODO(thaJeztah): Are these expected to be included?
88+
Auth: authCfg.Auth,
89+
IdentityToken: "",
90+
RegistryToken: authCfg.RegistryToken,
91+
}, nil
7592
}
7693

7794
// PromptUserForCredentials handles the CLI prompt for the user to input
@@ -186,7 +203,16 @@ func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (strin
186203
return "", err
187204
}
188205

189-
encodedAuth, err := authconfig.Encode(registrytypes.AuthConfig(authConfig))
206+
encodedAuth, err := authconfig.Encode(registrytypes.AuthConfig{
207+
Username: authConfig.Username,
208+
Password: authConfig.Password,
209+
ServerAddress: authConfig.ServerAddress,
210+
211+
// TODO(thaJeztah): Are these expected to be included?
212+
Auth: authConfig.Auth,
213+
IdentityToken: authConfig.IdentityToken,
214+
RegistryToken: authConfig.RegistryToken,
215+
})
190216
if err != nil {
191217
return "", err
192218
}

0 commit comments

Comments
 (0)