@@ -18,9 +18,15 @@ import (
18
18
"github.com/spf13/cobra"
19
19
)
20
20
21
- const unencryptedWarning = `WARNING! Your password will be stored unencrypted in %s.
21
+ // unencryptedWarning warns the user when using an insecure credential storage.
22
+ // After a deprecation period, user will get prompted if stdin and stderr are a terminal.
23
+ // Otherwise, we'll assume they want it (sadly), because people may have been scripting
24
+ // insecure logins and we don't want to break them. Maybe they'll see the warning in their
25
+ // logs and fix things.
26
+ const unencryptedWarning = `
27
+ WARNING! Your credentials are stored unencrypted in '%s'.
22
28
Configure a credential helper to remove this warning. See
23
- https://docs.docker.com/engine/reference/commandline/login/# credential-stores
29
+ https://docs.docker.com/go/ credential-store/
24
30
`
25
31
26
32
type loginOptions struct {
@@ -60,17 +66,6 @@ func NewLoginCommand(dockerCli command.Cli) *cobra.Command {
60
66
return cmd
61
67
}
62
68
63
- // displayUnencryptedWarning warns the user when using an insecure credential storage.
64
- // After a deprecation period, user will get prompted if stdin and stderr are a terminal.
65
- // Otherwise, we'll assume they want it (sadly), because people may have been scripting
66
- // insecure logins and we don't want to break them. Maybe they'll see the warning in their
67
- // logs and fix things.
68
- func displayUnencryptedWarning (dockerCli command.Streams , filename string ) error {
69
- _ , err := fmt .Fprintln (dockerCli .Err (), fmt .Sprintf (unencryptedWarning , filename ))
70
-
71
- return err
72
- }
73
-
74
69
type isFileStore interface {
75
70
IsFileStore () bool
76
71
GetFilename () string
@@ -143,19 +138,15 @@ func runLogin(ctx context.Context, dockerCli command.Cli, opts loginOptions) err
143
138
144
139
creds := dockerCli .ConfigFile ().GetCredentialsStore (serverAddress )
145
140
146
- store , isDefault := creds .(isFileStore )
147
- // Display a warning if we're storing the users password (not a token)
148
- if isDefault && authConfig .Password != "" {
149
- err = displayUnencryptedWarning (dockerCli , store .GetFilename ())
150
- if err != nil {
151
- return err
152
- }
153
- }
154
-
155
141
if err := creds .Store (configtypes .AuthConfig (authConfig )); err != nil {
156
142
return errors .Errorf ("Error saving credentials: %v" , err )
157
143
}
158
144
145
+ if store , isDefault := creds .(isFileStore ); isDefault && authConfig .Password != "" {
146
+ // Display a warning if we're storing the users password (not a token)
147
+ _ , _ = fmt .Fprintln (dockerCli .Err (), fmt .Sprintf (unencryptedWarning , store .GetFilename ()))
148
+ }
149
+
159
150
if response .Status != "" {
160
151
fmt .Fprintln (dockerCli .Out (), response .Status )
161
152
}
0 commit comments