Skip to content

Commit 9f02d96

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 9f02d96

File tree

5 files changed

+93
-13
lines changed

5 files changed

+93
-13
lines changed

cli/command/image/build.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,17 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
317317
configFile := dockerCli.ConfigFile()
318318
creds, _ := configFile.GetAllCredentials()
319319
authConfigs := make(map[string]registrytypes.AuthConfig, len(creds))
320-
for k, auth := range creds {
321-
authConfigs[k] = registrytypes.AuthConfig(auth)
320+
for k, authConfig := range creds {
321+
authConfigs[k] = registrytypes.AuthConfig{
322+
Username: authConfig.Username,
323+
Password: authConfig.Password,
324+
ServerAddress: authConfig.ServerAddress,
325+
326+
// TODO(thaJeztah): Are these expected to be included?
327+
Auth: authConfig.Auth,
328+
IdentityToken: authConfig.IdentityToken,
329+
RegistryToken: authConfig.RegistryToken,
330+
}
322331
}
323332
buildOpts := imageBuildOptions(dockerCli, options)
324333
buildOpts.Version = buildtypes.BuilderV1

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
}

cli/command/registry/login.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,30 @@ func loginWithDeviceCodeFlow(ctx context.Context, dockerCLI command.Cli) (msg st
238238
return "", err
239239
}
240240

241-
response, err := loginWithRegistry(ctx, dockerCLI.Client(), registrytypes.AuthConfig(*authConfig))
241+
response, err := loginWithRegistry(ctx, dockerCLI.Client(), registrytypes.AuthConfig{
242+
Username: authConfig.Username,
243+
Password: authConfig.Password,
244+
ServerAddress: authConfig.ServerAddress,
245+
246+
// TODO(thaJeztah): Are these expected to be included?
247+
Auth: authConfig.Auth,
248+
IdentityToken: authConfig.IdentityToken,
249+
RegistryToken: authConfig.RegistryToken,
250+
})
242251
if err != nil {
243252
return "", err
244253
}
245254

246-
if err = storeCredentials(dockerCLI.ConfigFile(), registrytypes.AuthConfig(*authConfig)); err != nil {
255+
if err = storeCredentials(dockerCLI.ConfigFile(), registrytypes.AuthConfig{
256+
Username: authConfig.Username,
257+
Password: authConfig.Password,
258+
ServerAddress: authConfig.ServerAddress,
259+
260+
// TODO(thaJeztah): Are these expected to be included?
261+
Auth: authConfig.Auth,
262+
IdentityToken: authConfig.IdentityToken,
263+
RegistryToken: authConfig.RegistryToken,
264+
}); err != nil {
247265
return "", err
248266
}
249267

@@ -252,7 +270,16 @@ func loginWithDeviceCodeFlow(ctx context.Context, dockerCLI command.Cli) (msg st
252270

253271
func storeCredentials(cfg *configfile.ConfigFile, authConfig registrytypes.AuthConfig) error {
254272
creds := cfg.GetCredentialsStore(authConfig.ServerAddress)
255-
if err := creds.Store(configtypes.AuthConfig(authConfig)); err != nil {
273+
if err := creds.Store(configtypes.AuthConfig{
274+
Username: authConfig.Username,
275+
Password: authConfig.Password,
276+
ServerAddress: authConfig.ServerAddress,
277+
278+
// TODO(thaJeztah): Are these expected to be included?
279+
Auth: authConfig.Auth,
280+
IdentityToken: authConfig.IdentityToken,
281+
RegistryToken: authConfig.RegistryToken,
282+
}); err != nil {
256283
return fmt.Errorf("error saving credentials: %v", err)
257284
}
258285

cli/command/registry/search.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,16 @@ func getAuth(dockerCLI command.Cli, reposName string) (encodedAuth string, err e
103103
// "no credentials found"). We'll get an error when search failed,
104104
// so fine to ignore in most situations.
105105
authConfig, _ := dockerCLI.ConfigFile().GetAuthConfig(authCfgKey)
106-
return authconfig.Encode(registrytypes.AuthConfig(authConfig))
106+
return authconfig.Encode(registrytypes.AuthConfig{
107+
Username: authConfig.Username,
108+
Password: authConfig.Password,
109+
ServerAddress: authConfig.ServerAddress,
110+
111+
// TODO(thaJeztah): Are these expected to be included?
112+
Auth: authConfig.Auth,
113+
IdentityToken: authConfig.IdentityToken,
114+
RegistryToken: authConfig.RegistryToken,
115+
})
107116
}
108117

109118
// splitReposSearchTerm breaks a search term into an index name and remote name

cli/command/registry_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,17 @@ func TestGetDefaultAuthConfig(t *testing.T) {
5959
},
6060
}
6161
cfg := configfile.New("filename")
62-
for _, authCfg := range testAuthConfigs {
63-
assert.Check(t, cfg.GetCredentialsStore(authCfg.ServerAddress).Store(configtypes.AuthConfig(authCfg)))
62+
for _, authConfig := range testAuthConfigs {
63+
assert.Check(t, cfg.GetCredentialsStore(authConfig.ServerAddress).Store(configtypes.AuthConfig{
64+
Username: authConfig.Username,
65+
Password: authConfig.Password,
66+
ServerAddress: authConfig.ServerAddress,
67+
68+
// TODO(thaJeztah): Are these expected to be included?
69+
Auth: authConfig.Auth,
70+
IdentityToken: authConfig.IdentityToken,
71+
RegistryToken: authConfig.RegistryToken,
72+
}))
6473
}
6574
for _, tc := range testCases {
6675
serverAddress := tc.inputServerAddress

0 commit comments

Comments
 (0)