Skip to content

Commit ec8eac6

Browse files
committed
cli/config/types: make AuthConfig an alias for registry.AuthConfig
The AuthConfig type was forked from the docker/docker API types in commit 27b2797 to reduce the dependency on the docker API types in BuildKit and Buildx (see [buildkit#800]). Now that the API is a separate module with minimal dependencies, this should no longer be a big concern, so this patch un-forks the type. [buildkit#800]: moby/buildkit#800 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 65cf876 commit ec8eac6

File tree

19 files changed

+214
-229
lines changed

19 files changed

+214
-229
lines changed

cli/command/container/auth_config_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/docker/cli/cli/config"
99
"github.com/docker/cli/cli/config/configfile"
10-
"github.com/docker/cli/cli/config/types"
10+
"github.com/moby/moby/api/types/registry"
1111
)
1212

1313
// readCredentials resolves auth-config from the current environment to be
@@ -22,7 +22,7 @@ import (
2222
// formatted, or when failing to read from the credentials store.
2323
//
2424
// A nil value is returned if neither option contained any credentials.
25-
func readCredentials(dockerCLI config.Provider) (creds map[string]types.AuthConfig, _ error) {
25+
func readCredentials(dockerCLI config.Provider) (creds map[string]registry.AuthConfig, _ error) {
2626
if v, ok := os.LookupEnv("DOCKER_AUTH_CONFIG"); ok && v != "" {
2727
// The results are expected to have been unmarshaled the same as
2828
// when reading from a config-file, which includes decoding the

cli/command/container/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
"github.com/docker/cli/cli/command"
1919
"github.com/docker/cli/cli/command/completion"
2020
"github.com/docker/cli/cli/config/configfile"
21-
"github.com/docker/cli/cli/config/types"
2221
"github.com/docker/cli/cli/streams"
2322
"github.com/docker/cli/internal/jsonstream"
2423
"github.com/docker/cli/opts"
2524
"github.com/moby/moby/api/types/mount"
25+
"github.com/moby/moby/api/types/registry"
2626
"github.com/moby/moby/client"
2727
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2828
"github.com/spf13/cobra"
@@ -239,7 +239,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
239239
}
240240

241241
const dockerConfigPathInContainer = "/run/secrets/docker/config.json"
242-
var apiSocketCreds map[string]types.AuthConfig
242+
var apiSocketCreds map[string]registry.AuthConfig
243243

244244
if options.useAPISocket {
245245
// We'll create two new mounts to handle this flag:

cli/command/registry.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ import (
1111
"github.com/distribution/reference"
1212
"github.com/docker/cli/cli/config/configfile"
1313
"github.com/docker/cli/cli/config/credentials"
14-
configtypes "github.com/docker/cli/cli/config/types"
1514
"github.com/docker/cli/cli/hints"
1615
"github.com/docker/cli/cli/streams"
1716
"github.com/docker/cli/internal/prompt"
1817
"github.com/docker/cli/internal/tui"
1918
"github.com/moby/moby/api/pkg/authconfig"
20-
registrytypes "github.com/moby/moby/api/types/registry"
19+
"github.com/moby/moby/api/types/registry"
2120
"github.com/morikuni/aec"
2221
)
2322

@@ -40,14 +39,14 @@ const authConfigKey = "https://index.docker.io/v1/"
4039
// found.
4140
//
4241
// Deprecated: this function is no longer used, and will be removed in the next release.
43-
func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
42+
func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registry.IndexInfo) registry.AuthConfig {
4443
configKey := index.Name
4544
if index.Official {
4645
configKey = authConfigKey
4746
}
4847

4948
a, _ := cfg.GetAuthConfig(configKey)
50-
return registrytypes.AuthConfig{
49+
return registry.AuthConfig{
5150
Username: a.Username,
5251
Password: a.Password,
5352
ServerAddress: a.ServerAddress,
@@ -61,22 +60,22 @@ func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registrytypes.IndexInf
6160

6261
// GetDefaultAuthConfig gets the default auth config given a serverAddress
6362
// If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it
64-
func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registrytypes.AuthConfig, error) {
63+
func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registry.AuthConfig, error) {
6564
if !isDefaultRegistry {
6665
serverAddress = credentials.ConvertToHostname(serverAddress)
6766
}
68-
authCfg := configtypes.AuthConfig{}
67+
authCfg := registry.AuthConfig{}
6968
var err error
7069
if checkCredStore {
7170
authCfg, err = cfg.GetAuthConfig(serverAddress)
7271
if err != nil {
73-
return registrytypes.AuthConfig{
72+
return registry.AuthConfig{
7473
ServerAddress: serverAddress,
7574
}, err
7675
}
7776
}
7877

79-
return registrytypes.AuthConfig{
78+
return registry.AuthConfig{
8079
Username: authCfg.Username,
8180
Password: authCfg.Password,
8281
ServerAddress: serverAddress,
@@ -97,7 +96,7 @@ func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serve
9796
// If defaultUsername is not empty, the username prompt includes that username
9897
// and the user can hit enter without inputting a username to use that default
9998
// username.
100-
func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword, defaultUsername, serverAddress string) (registrytypes.AuthConfig, error) {
99+
func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword, defaultUsername, serverAddress string) (registry.AuthConfig, error) {
101100
// On Windows, force the use of the regular OS stdin stream.
102101
//
103102
// See:
@@ -134,21 +133,21 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword
134133
var err error
135134
argUser, err = prompt.ReadInput(ctx, cli.In(), cli.Out(), msg)
136135
if err != nil {
137-
return registrytypes.AuthConfig{}, err
136+
return registry.AuthConfig{}, err
138137
}
139138
if argUser == "" {
140139
argUser = defaultUsername
141140
}
142141
if argUser == "" {
143-
return registrytypes.AuthConfig{}, errors.New("error: username is required")
142+
return registry.AuthConfig{}, errors.New("error: username is required")
144143
}
145144
}
146145

147146
argPassword = strings.TrimSpace(argPassword)
148147
if argPassword == "" {
149148
restoreInput, err := prompt.DisableInputEcho(cli.In())
150149
if err != nil {
151-
return registrytypes.AuthConfig{}, err
150+
return registry.AuthConfig{}, err
152151
}
153152
defer func() {
154153
if err := restoreInput(); err != nil {
@@ -168,15 +167,15 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword
168167

169168
argPassword, err = prompt.ReadInput(ctx, cli.In(), cli.Out(), "Password: ")
170169
if err != nil {
171-
return registrytypes.AuthConfig{}, err
170+
return registry.AuthConfig{}, err
172171
}
173172
_, _ = fmt.Fprintln(cli.Out())
174173
if argPassword == "" {
175-
return registrytypes.AuthConfig{}, errors.New("error: password is required")
174+
return registry.AuthConfig{}, errors.New("error: password is required")
176175
}
177176
}
178177

179-
return registrytypes.AuthConfig{
178+
return registry.AuthConfig{
180179
Username: argUser,
181180
Password: argPassword,
182181
ServerAddress: serverAddress,
@@ -200,7 +199,7 @@ func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (strin
200199
return "", err
201200
}
202201

203-
encodedAuth, err := authconfig.Encode(registrytypes.AuthConfig{
202+
encodedAuth, err := authconfig.Encode(registry.AuthConfig{
204203
Username: authConfig.Username,
205204
Password: authConfig.Password,
206205
ServerAddress: authConfig.ServerAddress,

cli/command/registry/login.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/docker/cli/cli"
1212
"github.com/docker/cli/cli/command"
1313
"github.com/docker/cli/cli/config/configfile"
14-
configtypes "github.com/docker/cli/cli/config/types"
1514
"github.com/docker/cli/internal/commands"
1615
"github.com/docker/cli/internal/oauth/manager"
1716
"github.com/docker/cli/internal/registry"
@@ -283,7 +282,7 @@ func loginWithDeviceCodeFlow(ctx context.Context, dockerCLI command.Cli) (msg st
283282

284283
func storeCredentials(cfg *configfile.ConfigFile, authConfig registrytypes.AuthConfig) error {
285284
creds := cfg.GetCredentialsStore(authConfig.ServerAddress)
286-
if err := creds.Store(configtypes.AuthConfig{
285+
if err := creds.Store(registrytypes.AuthConfig{
287286
Username: authConfig.Username,
288287
Password: authConfig.Password,
289288
ServerAddress: authConfig.ServerAddress,

cli/command/registry/login_test.go

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/creack/pty"
13-
configtypes "github.com/docker/cli/cli/config/types"
1413
"github.com/docker/cli/cli/streams"
1514
"github.com/docker/cli/internal/prompt"
1615
"github.com/docker/cli/internal/registry"
@@ -90,14 +89,14 @@ func TestLoginWithCredStoreCreds(t *testing.T) {
9089
func TestRunLogin(t *testing.T) {
9190
testCases := []struct {
9291
doc string
93-
priorCredentials map[string]configtypes.AuthConfig
92+
priorCredentials map[string]registrytypes.AuthConfig
9493
input loginOptions
95-
expectedCredentials map[string]configtypes.AuthConfig
94+
expectedCredentials map[string]registrytypes.AuthConfig
9695
expectedErr string
9796
}{
9897
{
9998
doc: "valid auth from store",
100-
priorCredentials: map[string]configtypes.AuthConfig{
99+
priorCredentials: map[string]registrytypes.AuthConfig{
101100
"reg1": {
102101
Username: "my-username",
103102
Password: "a-password",
@@ -107,7 +106,7 @@ func TestRunLogin(t *testing.T) {
107106
input: loginOptions{
108107
serverAddress: "reg1",
109108
},
110-
expectedCredentials: map[string]configtypes.AuthConfig{
109+
expectedCredentials: map[string]registrytypes.AuthConfig{
111110
"reg1": {
112111
Username: "my-username",
113112
Password: "a-password",
@@ -117,7 +116,7 @@ func TestRunLogin(t *testing.T) {
117116
},
118117
{
119118
doc: "expired auth from store",
120-
priorCredentials: map[string]configtypes.AuthConfig{
119+
priorCredentials: map[string]registrytypes.AuthConfig{
121120
"reg1": {
122121
Username: "my-username",
123122
Password: expiredPassword,
@@ -131,13 +130,13 @@ func TestRunLogin(t *testing.T) {
131130
},
132131
{
133132
doc: "store valid username and password",
134-
priorCredentials: map[string]configtypes.AuthConfig{},
133+
priorCredentials: map[string]registrytypes.AuthConfig{},
135134
input: loginOptions{
136135
serverAddress: "reg1",
137136
user: "my-username",
138137
password: "p2",
139138
},
140-
expectedCredentials: map[string]configtypes.AuthConfig{
139+
expectedCredentials: map[string]registrytypes.AuthConfig{
141140
"reg1": {
142141
Username: "my-username",
143142
Password: "p2",
@@ -147,7 +146,7 @@ func TestRunLogin(t *testing.T) {
147146
},
148147
{
149148
doc: "unknown user w/ prior credentials",
150-
priorCredentials: map[string]configtypes.AuthConfig{
149+
priorCredentials: map[string]registrytypes.AuthConfig{
151150
"reg1": {
152151
Username: "my-username",
153152
Password: "a-password",
@@ -160,7 +159,7 @@ func TestRunLogin(t *testing.T) {
160159
password: "a-password",
161160
},
162161
expectedErr: errUnknownUser,
163-
expectedCredentials: map[string]configtypes.AuthConfig{
162+
expectedCredentials: map[string]registrytypes.AuthConfig{
164163
"reg1": {
165164
Username: "a-password",
166165
Password: "a-password",
@@ -170,24 +169,24 @@ func TestRunLogin(t *testing.T) {
170169
},
171170
{
172171
doc: "unknown user w/o prior credentials",
173-
priorCredentials: map[string]configtypes.AuthConfig{},
172+
priorCredentials: map[string]registrytypes.AuthConfig{},
174173
input: loginOptions{
175174
serverAddress: "reg1",
176175
user: unknownUser,
177176
password: "a-password",
178177
},
179178
expectedErr: errUnknownUser,
180-
expectedCredentials: map[string]configtypes.AuthConfig{},
179+
expectedCredentials: map[string]registrytypes.AuthConfig{},
181180
},
182181
{
183182
doc: "store valid token",
184-
priorCredentials: map[string]configtypes.AuthConfig{},
183+
priorCredentials: map[string]registrytypes.AuthConfig{},
185184
input: loginOptions{
186185
serverAddress: "reg1",
187186
user: "my-username",
188187
password: useToken,
189188
},
190-
expectedCredentials: map[string]configtypes.AuthConfig{
189+
expectedCredentials: map[string]registrytypes.AuthConfig{
191190
"reg1": {
192191
Username: "my-username",
193192
IdentityToken: useToken,
@@ -197,7 +196,7 @@ func TestRunLogin(t *testing.T) {
197196
},
198197
{
199198
doc: "valid token from store",
200-
priorCredentials: map[string]configtypes.AuthConfig{
199+
priorCredentials: map[string]registrytypes.AuthConfig{
201200
"reg1": {
202201
Username: "my-username",
203202
Password: useToken,
@@ -207,7 +206,7 @@ func TestRunLogin(t *testing.T) {
207206
input: loginOptions{
208207
serverAddress: "reg1",
209208
},
210-
expectedCredentials: map[string]configtypes.AuthConfig{
209+
expectedCredentials: map[string]registrytypes.AuthConfig{
211210
"reg1": {
212211
Username: "my-username",
213212
IdentityToken: useToken,
@@ -217,12 +216,12 @@ func TestRunLogin(t *testing.T) {
217216
},
218217
{
219218
doc: "no registry specified defaults to index server",
220-
priorCredentials: map[string]configtypes.AuthConfig{},
219+
priorCredentials: map[string]registrytypes.AuthConfig{},
221220
input: loginOptions{
222221
user: "my-username",
223222
password: "my-password",
224223
},
225-
expectedCredentials: map[string]configtypes.AuthConfig{
224+
expectedCredentials: map[string]registrytypes.AuthConfig{
226225
registry.IndexServer: {
227226
Username: "my-username",
228227
Password: "my-password",
@@ -232,13 +231,13 @@ func TestRunLogin(t *testing.T) {
232231
},
233232
{
234233
doc: "registry-1.docker.io",
235-
priorCredentials: map[string]configtypes.AuthConfig{},
234+
priorCredentials: map[string]registrytypes.AuthConfig{},
236235
input: loginOptions{
237236
serverAddress: "registry-1.docker.io",
238237
user: "my-username",
239238
password: "my-password",
240239
},
241-
expectedCredentials: map[string]configtypes.AuthConfig{
240+
expectedCredentials: map[string]registrytypes.AuthConfig{
242241
"registry-1.docker.io": {
243242
Username: "my-username",
244243
Password: "my-password",
@@ -249,13 +248,13 @@ func TestRunLogin(t *testing.T) {
249248
// Regression test for https://github.com/docker/cli/issues/5382
250249
{
251250
doc: "sanitizes server address to remove repo",
252-
priorCredentials: map[string]configtypes.AuthConfig{},
251+
priorCredentials: map[string]registrytypes.AuthConfig{},
253252
input: loginOptions{
254253
serverAddress: "registry-1.docker.io/bork/test",
255254
user: "my-username",
256255
password: "a-password",
257256
},
258-
expectedCredentials: map[string]configtypes.AuthConfig{
257+
expectedCredentials: map[string]registrytypes.AuthConfig{
259258
"registry-1.docker.io": {
260259
Username: "my-username",
261260
Password: "a-password",
@@ -266,7 +265,7 @@ func TestRunLogin(t *testing.T) {
266265
// Regression test for https://github.com/docker/cli/issues/5382
267266
{
268267
doc: "updates credential if server address includes repo",
269-
priorCredentials: map[string]configtypes.AuthConfig{
268+
priorCredentials: map[string]registrytypes.AuthConfig{
270269
"registry-1.docker.io": {
271270
Username: "my-username",
272271
Password: "a-password",
@@ -278,7 +277,7 @@ func TestRunLogin(t *testing.T) {
278277
user: "my-username",
279278
password: "new-password",
280279
},
281-
expectedCredentials: map[string]configtypes.AuthConfig{
280+
expectedCredentials: map[string]registrytypes.AuthConfig{
282281
"registry-1.docker.io": {
283282
Username: "my-username",
284283
Password: "new-password",
@@ -428,7 +427,7 @@ func TestLoginNonInteractive(t *testing.T) {
428427
if serverAddress == "" {
429428
serverAddress = "https://index.docker.io/v1/"
430429
}
431-
assert.NilError(t, cfg.GetCredentialsStore(serverAddress).Store(configtypes.AuthConfig{
430+
assert.NilError(t, cfg.GetCredentialsStore(serverAddress).Store(registrytypes.AuthConfig{
432431
Username: "my-username",
433432
Password: "my-password",
434433
ServerAddress: serverAddress,

cli/command/registry_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/docker/cli/cli/command"
99
"github.com/docker/cli/cli/config/configfile"
10-
configtypes "github.com/docker/cli/cli/config/types"
1110
"github.com/moby/moby/api/pkg/authconfig"
1211
"github.com/moby/moby/api/types/registry"
1312
"gotest.tools/v3/assert"
@@ -60,7 +59,7 @@ func TestGetDefaultAuthConfig(t *testing.T) {
6059
}
6160
cfg := configfile.New("filename")
6261
for _, authConfig := range testAuthConfigs {
63-
assert.Check(t, cfg.GetCredentialsStore(authConfig.ServerAddress).Store(configtypes.AuthConfig{
62+
assert.Check(t, cfg.GetCredentialsStore(authConfig.ServerAddress).Store(registry.AuthConfig{
6463
Username: authConfig.Username,
6564
Password: authConfig.Password,
6665
ServerAddress: authConfig.ServerAddress,

0 commit comments

Comments
 (0)