Skip to content

Commit ab80541

Browse files
committed
cli/config/types: update deprecation comment for AuthConfig.Email
Relates to [cli@27b2797], which forked this type from the Moby API, and [moby@6cfff7e], which made the same change on the API side. The Email field was originally used to create a new Docker Hub account through the `docker login` command. The `docker login` command could be used both to log in to an existing account (providing only username and password), or to create a new account (providing desired username and password, and an e-mail address to use for the new account). This functionality was confusing, because it was implemented when Docker Hub was the only registry, but the same functionality could not be used for other registries. This functionality was removed in Docker 1.11 (API version 1.23) through [moby@aee260d], which also removed the Email field ([engine-api@9a9e468]) as it was no longer used. However, this caused issues when using a new CLI connecting with an old daemon, as the field would no longer be serialized, and the deprecation may not yet be picked up by custom registries, so [engine-api@167efc7] added the field back, deprecated it, and added an "omitempty". There was no official "deprecated" format yet at the time, so let's make sure the deprecation follows the proper format to make sure it gets noticed. [cli@27b2797]: 27b2797 [moby@6cfff7e]: moby/moby@6cfff7e [moby@aee260d]: moby/moby@aee260d [engine-api@9a9e468]: docker-archive-public/docker.engine-api@9a9e468 [engine-api@167efc7]: docker-archive-public/docker.engine-api@167efc7 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 5ab12e6 commit ab80541

File tree

3 files changed

+30
-61
lines changed

3 files changed

+30
-61
lines changed

cli/config/credentials/file_store_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ func TestFileStoreIdempotent(t *testing.T) {
4343
},
4444
})
4545
authOne := types.AuthConfig{
46+
Username: "foo@example.com",
4647
Auth: "super_secret_token",
47-
Email: "foo@example.com",
4848
ServerAddress: "https://example.com",
4949
}
5050
authTwo := types.AuthConfig{
51+
Username: "bar@example.com",
5152
Auth: "also_super_secret_token",
52-
Email: "bar@example.com",
5353
ServerAddress: "https://other.example.com",
5454
}
5555

@@ -106,8 +106,8 @@ func TestFileStoreAddCredentials(t *testing.T) {
106106

107107
s := NewFileStore(f)
108108
auth := types.AuthConfig{
109+
Username: "foo@example.com",
109110
Auth: "super_secret_token",
110-
Email: "foo@example.com",
111111
ServerAddress: "https://example.com",
112112
}
113113
err := s.Store(auth)
@@ -122,8 +122,8 @@ func TestFileStoreAddCredentials(t *testing.T) {
122122
func TestFileStoreGet(t *testing.T) {
123123
f := &fakeStore{configs: map[string]types.AuthConfig{
124124
"https://example.com": {
125+
Username: "foo@example.com",
125126
Auth: "super_secret_token",
126-
Email: "foo@example.com",
127127
ServerAddress: "https://example.com",
128128
},
129129
}}
@@ -136,8 +136,8 @@ func TestFileStoreGet(t *testing.T) {
136136
if a.Auth != "super_secret_token" {
137137
t.Fatalf("expected auth `super_secret_token`, got %s", a.Auth)
138138
}
139-
if a.Email != "foo@example.com" {
140-
t.Fatalf("expected email `foo@example.com`, got %s", a.Email)
139+
if a.Username != "foo@example.com" {
140+
t.Fatalf("expected username `foo@example.com`, got %s", a.Username)
141141
}
142142
}
143143

@@ -146,13 +146,13 @@ func TestFileStoreGetAll(t *testing.T) {
146146
s2 := "https://example2.example.com"
147147
f := &fakeStore{configs: map[string]types.AuthConfig{
148148
s1: {
149+
Username: "foo@example.com",
149150
Auth: "super_secret_token",
150-
Email: "foo@example.com",
151151
ServerAddress: "https://example.com",
152152
},
153153
s2: {
154+
Username: "foo@example2.com",
154155
Auth: "super_secret_token2",
155-
Email: "foo@example2.com",
156156
ServerAddress: "https://example2.example.com",
157157
},
158158
}}
@@ -168,22 +168,22 @@ func TestFileStoreGetAll(t *testing.T) {
168168
if as[s1].Auth != "super_secret_token" {
169169
t.Fatalf("expected auth `super_secret_token`, got %s", as[s1].Auth)
170170
}
171-
if as[s1].Email != "foo@example.com" {
172-
t.Fatalf("expected email `foo@example.com`, got %s", as[s1].Email)
171+
if as[s1].Username != "foo@example.com" {
172+
t.Fatalf("expected username `foo@example.com`, got %s", as[s1].Username)
173173
}
174174
if as[s2].Auth != "super_secret_token2" {
175175
t.Fatalf("expected auth `super_secret_token2`, got %s", as[s2].Auth)
176176
}
177-
if as[s2].Email != "foo@example2.com" {
178-
t.Fatalf("expected email `foo@example2.com`, got %s", as[s2].Email)
177+
if as[s2].Username != "foo@example2.com" {
178+
t.Fatalf("expected username `foo@example2.com`, got %s", as[s2].Username)
179179
}
180180
}
181181

182182
func TestFileStoreErase(t *testing.T) {
183183
f := &fakeStore{configs: map[string]types.AuthConfig{
184184
"https://example.com": {
185+
Username: "foo@example.com",
185186
Auth: "super_secret_token",
186-
Email: "foo@example.com",
187187
ServerAddress: "https://example.com",
188188
},
189189
}}

cli/config/credentials/native_store_test.go

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func TestNativeStoreAddInvalidCredentials(t *testing.T) {
124124
err := s.Store(types.AuthConfig{
125125
Username: "foo",
126126
Password: "bar",
127-
Email: "foo@example.com",
128127
ServerAddress: invalidServerAddress,
129128
})
130129
assert.ErrorContains(t, err, "program failed")
@@ -134,7 +133,7 @@ func TestNativeStoreAddInvalidCredentials(t *testing.T) {
134133
func TestNativeStoreGet(t *testing.T) {
135134
f := &fakeStore{configs: map[string]types.AuthConfig{
136135
validServerAddress: {
137-
Email: "foo@example.com",
136+
Username: "foo@example.com",
138137
},
139138
}}
140139
s := &nativeStore{
@@ -147,17 +146,14 @@ func TestNativeStoreGet(t *testing.T) {
147146
expected := types.AuthConfig{
148147
Username: "foo",
149148
Password: "bar",
150-
Email: "foo@example.com",
151149
ServerAddress: validServerAddress,
152150
}
153151
assert.Check(t, is.DeepEqual(expected, actual))
154152
}
155153

156154
func TestNativeStoreGetIdentityToken(t *testing.T) {
157155
f := &fakeStore{configs: map[string]types.AuthConfig{
158-
validServerAddress2: {
159-
Email: "foo@example2.com",
160-
},
156+
validServerAddress2: {},
161157
}}
162158

163159
s := &nativeStore{
@@ -169,17 +165,14 @@ func TestNativeStoreGetIdentityToken(t *testing.T) {
169165

170166
expected := types.AuthConfig{
171167
IdentityToken: "abcd1234",
172-
Email: "foo@example2.com",
173168
ServerAddress: validServerAddress2,
174169
}
175170
assert.Check(t, is.DeepEqual(expected, actual))
176171
}
177172

178173
func TestNativeStoreGetAll(t *testing.T) {
179174
f := &fakeStore{configs: map[string]types.AuthConfig{
180-
validServerAddress: {
181-
Email: "foo@example.com",
182-
},
175+
validServerAddress: {},
183176
}}
184177

185178
s := &nativeStore{
@@ -189,38 +182,20 @@ func TestNativeStoreGetAll(t *testing.T) {
189182
as, err := s.GetAll()
190183
assert.NilError(t, err)
191184
assert.Check(t, is.Len(as, 2))
192-
193-
if as[validServerAddress].Username != "foo" {
194-
t.Fatalf("expected username `foo` for %s, got %s", validServerAddress, as[validServerAddress].Username)
195-
}
196-
if as[validServerAddress].Password != "bar" {
197-
t.Fatalf("expected password `bar` for %s, got %s", validServerAddress, as[validServerAddress].Password)
198-
}
199-
if as[validServerAddress].IdentityToken != "" {
200-
t.Fatalf("expected identity to be empty for %s, got %s", validServerAddress, as[validServerAddress].IdentityToken)
201-
}
202-
if as[validServerAddress].Email != "foo@example.com" {
203-
t.Fatalf("expected email `foo@example.com` for %s, got %s", validServerAddress, as[validServerAddress].Email)
204-
}
205-
if as[validServerAddress2].Username != "" {
206-
t.Fatalf("expected username to be empty for %s, got %s", validServerAddress2, as[validServerAddress2].Username)
207-
}
208-
if as[validServerAddress2].Password != "" {
209-
t.Fatalf("expected password to be empty for %s, got %s", validServerAddress2, as[validServerAddress2].Password)
210-
}
211-
if as[validServerAddress2].IdentityToken != "abcd1234" {
212-
t.Fatalf("expected identity token `abcd1324` for %s, got %s", validServerAddress2, as[validServerAddress2].IdentityToken)
213-
}
214-
if as[validServerAddress2].Email != "" {
215-
t.Fatalf("expected no email for %s, got %s", validServerAddress2, as[validServerAddress2].Email)
185+
expected := types.AuthConfig{
186+
Username: "foo",
187+
Password: "bar",
188+
ServerAddress: "https://index.docker.io/v1",
189+
IdentityToken: "",
216190
}
191+
actual, ok := as[validServerAddress]
192+
assert.Check(t, ok)
193+
assert.Check(t, is.DeepEqual(expected, actual))
217194
}
218195

219196
func TestNativeStoreGetMissingCredentials(t *testing.T) {
220197
f := &fakeStore{configs: map[string]types.AuthConfig{
221-
validServerAddress: {
222-
Email: "foo@example.com",
223-
},
198+
validServerAddress: {},
224199
}}
225200

226201
s := &nativeStore{
@@ -233,9 +208,7 @@ func TestNativeStoreGetMissingCredentials(t *testing.T) {
233208

234209
func TestNativeStoreGetInvalidAddress(t *testing.T) {
235210
f := &fakeStore{configs: map[string]types.AuthConfig{
236-
validServerAddress: {
237-
Email: "foo@example.com",
238-
},
211+
validServerAddress: {},
239212
}}
240213

241214
s := &nativeStore{
@@ -248,9 +221,7 @@ func TestNativeStoreGetInvalidAddress(t *testing.T) {
248221

249222
func TestNativeStoreErase(t *testing.T) {
250223
f := &fakeStore{configs: map[string]types.AuthConfig{
251-
validServerAddress: {
252-
Email: "foo@example.com",
253-
},
224+
validServerAddress: {},
254225
}}
255226

256227
s := &nativeStore{
@@ -264,9 +235,7 @@ func TestNativeStoreErase(t *testing.T) {
264235

265236
func TestNativeStoreEraseInvalidAddress(t *testing.T) {
266237
f := &fakeStore{configs: map[string]types.AuthConfig{
267-
validServerAddress: {
268-
Email: "foo@example.com",
269-
},
238+
validServerAddress: {},
270239
}}
271240

272241
s := &nativeStore{

cli/config/types/authconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ type AuthConfig struct {
77
Auth string `json:"auth,omitempty"`
88

99
// Email is an optional value associated with the username.
10-
// This field is deprecated and will be removed in a later
11-
// version of docker.
10+
//
11+
// Deprecated: This field is deprecated since docker 1.11 (API v1.23) and will be removed in the next release.
1212
Email string `json:"email,omitempty"`
1313

1414
ServerAddress string `json:"serveraddress,omitempty"`

0 commit comments

Comments
 (0)