@@ -118,10 +118,7 @@ func runLogin(ctx context.Context, dockerCLI command.Cli, opts loginOptions) err
118118
119119 maybePrintEnvAuthWarning (dockerCLI )
120120
121- var (
122- serverAddress string
123- msg string
124- )
121+ var serverAddress string
125122 if opts .serverAddress != "" && opts .serverAddress != registry .DefaultNamespace {
126123 serverAddress = opts .serverAddress
127124 } else {
@@ -132,25 +129,23 @@ func runLogin(ctx context.Context, dockerCLI command.Cli, opts loginOptions) err
132129 // attempt login with current (stored) credentials
133130 authConfig , err := command .GetDefaultAuthConfig (dockerCLI .ConfigFile (), opts .user == "" && opts .password == "" , serverAddress , isDefaultRegistry )
134131 if err == nil && authConfig .Username != "" && authConfig .Password != "" {
135- msg , err = loginWithStoredCredentials (ctx , dockerCLI , authConfig )
132+ err = loginWithStoredCredentials (ctx , dockerCLI , authConfig )
136133 }
137134
138135 // if we failed to authenticate with stored credentials (or didn't have stored credentials),
139136 // prompt the user for new credentials
140137 if err != nil || authConfig .Username == "" || authConfig .Password == "" {
141- msg , err = loginUser (ctx , dockerCLI , opts , authConfig .Username , authConfig .ServerAddress )
138+ err = loginUser (ctx , dockerCLI , opts , authConfig .Username , authConfig .ServerAddress )
142139 if err != nil {
143140 return err
144141 }
145142 }
146143
147- if msg != "" {
148- _ , _ = fmt .Fprintln (dockerCLI .Out (), msg )
149- }
144+ _ , _ = fmt .Fprintln (dockerCLI .Out (), "Login Succeeded" )
150145 return nil
151146}
152147
153- func loginWithStoredCredentials (ctx context.Context , dockerCLI command.Cli , authConfig registrytypes.AuthConfig ) ( msg string , _ error ) {
148+ func loginWithStoredCredentials (ctx context.Context , dockerCLI command.Cli , authConfig registrytypes.AuthConfig ) error {
154149 _ , _ = fmt .Fprintf (dockerCLI .Err (), "Authenticating with existing credentials..." )
155150 if authConfig .Username != "" {
156151 _ , _ = fmt .Fprintf (dockerCLI .Err (), " [Username: %s]" , authConfig .Username )
@@ -176,11 +171,7 @@ func loginWithStoredCredentials(ctx context.Context, dockerCLI command.Cli, auth
176171 authConfig .IdentityToken = response .IdentityToken
177172 }
178173
179- if err := storeCredentials (dockerCLI .ConfigFile (), authConfig ); err != nil {
180- return "" , err
181- }
182-
183- return response .Status , err
174+ return storeCredentials (dockerCLI .ConfigFile (), authConfig )
184175}
185176
186177// OauthLoginEscapeHatchEnvVar disables the browser-based OAuth login workflow.
@@ -201,7 +192,7 @@ func isOauthLoginDisabled() bool {
201192 return false
202193}
203194
204- func loginUser (ctx context.Context , dockerCLI command.Cli , opts loginOptions , defaultUsername , serverAddress string ) ( msg string , _ error ) {
195+ func loginUser (ctx context.Context , dockerCLI command.Cli , opts loginOptions , defaultUsername , serverAddress string ) error {
205196 // Some links documenting this:
206197 // - https://code.google.com/archive/p/mintty/issues/56
207198 // - https://github.com/docker/docker/issues/15272
@@ -210,64 +201,55 @@ func loginUser(ctx context.Context, dockerCLI command.Cli, opts loginOptions, de
210201 // will hit this if you attempt docker login from mintty where stdin
211202 // is a pipe, not a character based console.
212203 if (opts .user == "" || opts .password == "" ) && ! dockerCLI .In ().IsTerminal () {
213- return "" , errors .New ("error: cannot perform an interactive login from a non TTY device" )
204+ return errors .New ("error: cannot perform an interactive login from a non- TTY device" )
214205 }
215206
216207 // If we're logging into the index server and the user didn't provide a username or password, use the device flow
217208 if serverAddress == registry .IndexServer && opts .user == "" && opts .password == "" && ! isOauthLoginDisabled () {
218- var err error
219- msg , err = loginWithDeviceCodeFlow (ctx , dockerCLI )
209+ err := loginWithDeviceCodeFlow (ctx , dockerCLI )
220210 // if the error represents a failure to initiate the device-code flow,
221211 // then we fallback to regular cli credentials login
222212 if ! errors .Is (err , manager .ErrDeviceLoginStartFail ) {
223- return msg , err
213+ return err
224214 }
225215 _ , _ = fmt .Fprint (dockerCLI .Err (), "Failed to start web-based login - falling back to command line login...\n \n " )
226216 }
227217
228218 return loginWithUsernameAndPassword (ctx , dockerCLI , opts , defaultUsername , serverAddress )
229219}
230220
231- func loginWithUsernameAndPassword (ctx context.Context , dockerCLI command.Cli , opts loginOptions , defaultUsername , serverAddress string ) ( msg string , _ error ) {
221+ func loginWithUsernameAndPassword (ctx context.Context , dockerCLI command.Cli , opts loginOptions , defaultUsername , serverAddress string ) error {
232222 // Prompt user for credentials
233223 authConfig , err := command .PromptUserForCredentials (ctx , dockerCLI , opts .user , opts .password , defaultUsername , serverAddress )
234224 if err != nil {
235- return "" , err
225+ return err
236226 }
237227
238228 response , err := loginWithRegistry (ctx , dockerCLI .Client (), authConfig )
239229 if err != nil {
240- return "" , err
230+ return err
241231 }
242232
243233 if response .IdentityToken != "" {
244234 authConfig .Password = ""
245235 authConfig .IdentityToken = response .IdentityToken
246236 }
247- if err = storeCredentials (dockerCLI .ConfigFile (), authConfig ); err != nil {
248- return "" , err
249- }
250-
251- return response .Status , nil
237+ return storeCredentials (dockerCLI .ConfigFile (), authConfig )
252238}
253239
254- func loginWithDeviceCodeFlow (ctx context.Context , dockerCLI command.Cli ) ( msg string , _ error ) {
240+ func loginWithDeviceCodeFlow (ctx context.Context , dockerCLI command.Cli ) error {
255241 store := dockerCLI .ConfigFile ().GetCredentialsStore (registry .IndexServer )
256242 authConfig , err := manager .NewManager (store ).LoginDevice (ctx , dockerCLI .Err ())
257243 if err != nil {
258- return "" , err
244+ return err
259245 }
260246
261- response , err : = loginWithRegistry (ctx , dockerCLI .Client (), registrytypes .AuthConfig (* authConfig ))
247+ _ , err = loginWithRegistry (ctx , dockerCLI .Client (), registrytypes .AuthConfig (* authConfig ))
262248 if err != nil {
263- return "" , err
264- }
265-
266- if err = storeCredentials (dockerCLI .ConfigFile (), registrytypes .AuthConfig (* authConfig )); err != nil {
267- return "" , err
249+ return err
268250 }
269251
270- return response . Status , nil
252+ return storeCredentials ( dockerCLI . ConfigFile (), registrytypes . AuthConfig ( * authConfig ))
271253}
272254
273255func storeCredentials (cfg * configfile.ConfigFile , authConfig registrytypes.AuthConfig ) error {
@@ -304,7 +286,6 @@ func loginClientSide(ctx context.Context, auth registrytypes.AuthConfig) (*regis
304286 }
305287
306288 return & registrytypes.AuthenticateOKBody {
307- Status : "Login Succeeded" ,
308289 IdentityToken : token ,
309290 }, nil
310291}
0 commit comments