Skip to content

Commit 5eb3275

Browse files
committed
filestore: don't print warning multiple times
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
1 parent e662467 commit 5eb3275

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

‎cli/config/credentials/file_store.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/url"
77
"os"
88
"strings"
9+
"sync/atomic"
910

1011
"github.com/docker/cli/cli/config/types"
1112
)
@@ -65,6 +66,10 @@ Configure a credential helper to remove this warning. See
6566
https://docs.docker.com/go/credential-store/
6667
`
6768

69+
// alreadyPrinted ensures that we only print the unencryptedWarning once per
70+
// CLI invocation (no need to warn the user multiple times per command).
71+
var alreadyPrinted atomic.Bool
72+
6873
// Store saves the given credentials in the file store.
6974
func (c *fileStore) Store(authConfig types.AuthConfig) error {
7075
authConfigs := c.file.GetAuthConfigs()
@@ -73,11 +78,12 @@ func (c *fileStore) Store(authConfig types.AuthConfig) error {
7378
return err
7479
}
7580

76-
if authConfig.Password != "" {
81+
if !alreadyPrinted.Load() && authConfig.Password != "" {
7782
// Display a warning if we're storing the users password (not a token).
7883
//
7984
// FIXME(thaJeztah): make output configurable instead of hardcoding to os.Stderr
8085
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf(unencryptedWarning, c.file.GetFilename()))
86+
alreadyPrinted.Store(true)
8187
}
8288

8389
return nil

0 commit comments

Comments
 (0)