Store saves the given credentials in the file store. This function is idempotent and does not update the file if credentials did not change.
(authConfig types.AuthConfig)
| 78 | // Store saves the given credentials in the file store. This function is |
| 79 | // idempotent and does not update the file if credentials did not change. |
| 80 | func (c *fileStore) Store(authConfig types.AuthConfig) error { |
| 81 | authConfigs := c.file.GetAuthConfigs() |
| 82 | if oldAuthConfig, ok := authConfigs[authConfig.ServerAddress]; ok && oldAuthConfig == authConfig { |
| 83 | // Credentials didn't change, so skip updating the configuration file. |
| 84 | return nil |
| 85 | } |
| 86 | authConfigs[authConfig.ServerAddress] = authConfig |
| 87 | if err := c.file.Save(); err != nil { |
| 88 | return err |
| 89 | } |
| 90 | |
| 91 | if !alreadyPrinted.Load() && authConfig.Password != "" { |
| 92 | // Display a warning if we're storing the users password (not a token). |
| 93 | // |
| 94 | // FIXME(thaJeztah): make output configurable instead of hardcoding to os.Stderr |
| 95 | _, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf(unencryptedWarning, c.file.GetFilename())) |
| 96 | alreadyPrinted.Store(true) |
| 97 | } |
| 98 | |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | // ConvertToHostname normalizes a registry URL which has http|https prepended |
| 103 | // to just its hostname. It is used to match credentials, which may be either |
nothing calls this directly
no test coverage detected