@@ -116,10 +116,7 @@ func runLogin(ctx context.Context, dockerCLI command.Cli, opts loginOptions) err
116116
117117 maybePrintEnvAuthWarning (dockerCLI )
118118
119- var (
120- serverAddress string
121- msg string
122- )
119+ var serverAddress string
123120 if opts .serverAddress != "" && opts .serverAddress != registry .DefaultNamespace {
124121 serverAddress = opts .serverAddress
125122 } else {
@@ -130,25 +127,23 @@ func runLogin(ctx context.Context, dockerCLI command.Cli, opts loginOptions) err
130127 // attempt login with current (stored) credentials
131128 authConfig , err := command .GetDefaultAuthConfig (dockerCLI .ConfigFile (), opts .user == "" && opts .password == "" , serverAddress , isDefaultRegistry )
132129 if err == nil && authConfig .Username != "" && authConfig .Password != "" {
133- msg , err = loginWithStoredCredentials (ctx , dockerCLI , authConfig )
130+ err = loginWithStoredCredentials (ctx , dockerCLI , authConfig )
134131 }
135132
136133 // if we failed to authenticate with stored credentials (or didn't have stored credentials),
137134 // prompt the user for new credentials
138135 if err != nil || authConfig .Username == "" || authConfig .Password == "" {
139- msg , err = loginUser (ctx , dockerCLI , opts , authConfig .Username , authConfig .ServerAddress )
136+ err = loginUser (ctx , dockerCLI , opts , authConfig .Username , authConfig .ServerAddress )
140137 if err != nil {
141138 return err
142139 }
143140 }
144141
145- if msg != "" {
146- _ , _ = fmt .Fprintln (dockerCLI .Out (), msg )
147- }
142+ _ , _ = fmt .Fprintln (dockerCLI .Out (), "Login Succeeded" )
148143 return nil
149144}
150145
151- func loginWithStoredCredentials (ctx context.Context , dockerCLI command.Cli , authConfig registrytypes.AuthConfig ) ( msg string , _ error ) {
146+ func loginWithStoredCredentials (ctx context.Context , dockerCLI command.Cli , authConfig registrytypes.AuthConfig ) error {
152147 _ , _ = fmt .Fprintf (dockerCLI .Err (), "Authenticating with existing credentials..." )
153148 if authConfig .Username != "" {
154149 _ , _ = fmt .Fprintf (dockerCLI .Err (), " [Username: %s]" , authConfig .Username )
@@ -181,14 +176,10 @@ func loginWithStoredCredentials(ctx context.Context, dockerCLI command.Cli, auth
181176 authConfig .IdentityToken = resp .Auth .IdentityToken
182177 }
183178
184- if err := storeCredentials (dockerCLI .ConfigFile (), authConfig ); err != nil {
185- return "" , err
186- }
187-
188- return resp .Auth .Status , err
179+ return storeCredentials (dockerCLI .ConfigFile (), authConfig )
189180}
190181
191- func loginUser (ctx context.Context , dockerCLI command.Cli , opts loginOptions , defaultUsername , serverAddress string ) ( msg string , _ error ) {
182+ func loginUser (ctx context.Context , dockerCLI command.Cli , opts loginOptions , defaultUsername , serverAddress string ) error {
192183 // Some links documenting this:
193184 // - https://code.google.com/archive/p/mintty/issues/56
194185 // - https://github.com/docker/docker/issues/15272
@@ -197,29 +188,28 @@ func loginUser(ctx context.Context, dockerCLI command.Cli, opts loginOptions, de
197188 // will hit this if you attempt docker login from mintty where stdin
198189 // is a pipe, not a character based console.
199190 if (opts .user == "" || opts .password == "" ) && ! dockerCLI .In ().IsTerminal () {
200- return "" , errors .New ("error: cannot perform an interactive login from a non-TTY device" )
191+ return errors .New ("error: cannot perform an interactive login from a non-TTY device" )
201192 }
202193
203194 // If we're logging into the index server and the user didn't provide a username or password, use the device flow
204195 if serverAddress == registry .IndexServer && opts .user == "" && opts .password == "" {
205- var err error
206- msg , err = loginWithDeviceCodeFlow (ctx , dockerCLI )
196+ err := loginWithDeviceCodeFlow (ctx , dockerCLI )
207197 // if the error represents a failure to initiate the device-code flow,
208198 // then we fallback to regular cli credentials login
209199 if ! errors .Is (err , manager .ErrDeviceLoginStartFail ) {
210- return msg , err
200+ return err
211201 }
212202 _ , _ = fmt .Fprint (dockerCLI .Err (), "Failed to start web-based login - falling back to command line login...\n \n " )
213203 }
214204
215205 return loginWithUsernameAndPassword (ctx , dockerCLI , opts , defaultUsername , serverAddress )
216206}
217207
218- func loginWithUsernameAndPassword (ctx context.Context , dockerCLI command.Cli , opts loginOptions , defaultUsername , serverAddress string ) ( msg string , _ error ) {
208+ func loginWithUsernameAndPassword (ctx context.Context , dockerCLI command.Cli , opts loginOptions , defaultUsername , serverAddress string ) error {
219209 // Prompt user for credentials
220210 authConfig , err := command .PromptUserForCredentials (ctx , dockerCLI , opts .user , opts .password , defaultUsername , serverAddress )
221211 if err != nil {
222- return "" , err
212+ return err
223213 }
224214
225215 res , err := loginWithRegistry (ctx , dockerCLI .Client (), client.RegistryLoginOptions {
@@ -230,28 +220,24 @@ func loginWithUsernameAndPassword(ctx context.Context, dockerCLI command.Cli, op
230220 RegistryToken : authConfig .RegistryToken ,
231221 })
232222 if err != nil {
233- return "" , err
223+ return err
234224 }
235225
236226 if res .Auth .IdentityToken != "" {
237227 authConfig .Password = ""
238228 authConfig .IdentityToken = res .Auth .IdentityToken
239229 }
240- if err = storeCredentials (dockerCLI .ConfigFile (), authConfig ); err != nil {
241- return "" , err
242- }
243-
244- return res .Auth .Status , nil
230+ return storeCredentials (dockerCLI .ConfigFile (), authConfig )
245231}
246232
247- func loginWithDeviceCodeFlow (ctx context.Context , dockerCLI command.Cli ) ( msg string , _ error ) {
233+ func loginWithDeviceCodeFlow (ctx context.Context , dockerCLI command.Cli ) error {
248234 store := dockerCLI .ConfigFile ().GetCredentialsStore (registry .IndexServer )
249235 authConfig , err := manager .NewManager (store ).LoginDevice (ctx , dockerCLI .Err ())
250236 if err != nil {
251- return "" , err
237+ return err
252238 }
253239
254- response , err : = loginWithRegistry (ctx , dockerCLI .Client (), client.RegistryLoginOptions {
240+ _ , err = loginWithRegistry (ctx , dockerCLI .Client (), client.RegistryLoginOptions {
255241 Username : authConfig .Username ,
256242 Password : authConfig .Password ,
257243 ServerAddress : authConfig .ServerAddress ,
@@ -262,10 +248,10 @@ func loginWithDeviceCodeFlow(ctx context.Context, dockerCLI command.Cli) (msg st
262248 RegistryToken : authConfig .RegistryToken ,
263249 })
264250 if err != nil {
265- return "" , err
251+ return err
266252 }
267253
268- if err = storeCredentials (dockerCLI .ConfigFile (), registrytypes.AuthConfig {
254+ return storeCredentials (dockerCLI .ConfigFile (), registrytypes.AuthConfig {
269255 Username : authConfig .Username ,
270256 Password : authConfig .Password ,
271257 ServerAddress : authConfig .ServerAddress ,
@@ -274,11 +260,7 @@ func loginWithDeviceCodeFlow(ctx context.Context, dockerCLI command.Cli) (msg st
274260 Auth : authConfig .Auth ,
275261 IdentityToken : authConfig .IdentityToken ,
276262 RegistryToken : authConfig .RegistryToken ,
277- }); err != nil {
278- return "" , err
279- }
280-
281- return response .Auth .Status , nil
263+ })
282264}
283265
284266func storeCredentials (cfg * configfile.ConfigFile , authConfig registrytypes.AuthConfig ) error {
@@ -333,7 +315,6 @@ func loginClientSide(ctx context.Context, options client.RegistryLoginOptions) (
333315
334316 return client.RegistryLoginResult {
335317 Auth : registrytypes.AuthResponse {
336- Status : "Login Succeeded" ,
337318 IdentityToken : token ,
338319 },
339320 }, nil
0 commit comments