cli/command/registry: minor cleanups: use Println, rename vars
- use Println to print newline instead of custom format - use dockerCLI with Go's standard camelCase casing. - suppress some errors to make my IDE and linters happier Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
53aed6119b
commit
016dbef449
@ -119,14 +119,14 @@ func runLogin(ctx context.Context, dockerCli command.Cli, opts loginOptions) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func loginWithStoredCredentials(ctx context.Context, dockerCli command.Cli, authConfig registrytypes.AuthConfig) (msg string, _ error) {
|
||||
_, _ = fmt.Fprintf(dockerCli.Out(), "Authenticating with existing credentials...\n")
|
||||
response, err := dockerCli.Client().RegistryLogin(ctx, authConfig)
|
||||
func loginWithStoredCredentials(ctx context.Context, dockerCLI command.Cli, authConfig registrytypes.AuthConfig) (msg string, _ error) {
|
||||
_, _ = fmt.Fprintln(dockerCLI.Out(), "Authenticating with existing credentials...")
|
||||
response, err := dockerCLI.Client().RegistryLogin(ctx, authConfig)
|
||||
if err != nil {
|
||||
if errdefs.IsUnauthorized(err) {
|
||||
_, _ = fmt.Fprintf(dockerCli.Err(), "Stored credentials invalid or expired\n")
|
||||
_, _ = fmt.Fprintln(dockerCLI.Err(), "Stored credentials invalid or expired")
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(dockerCli.Err(), "Login did not succeed, error: %s\n", err)
|
||||
_, _ = fmt.Fprintln(dockerCLI.Err(), "Login did not succeed, error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ func loginWithStoredCredentials(ctx context.Context, dockerCli command.Cli, auth
|
||||
authConfig.IdentityToken = response.IdentityToken
|
||||
}
|
||||
|
||||
if err := storeCredentials(dockerCli.ConfigFile(), authConfig); err != nil {
|
||||
if err := storeCredentials(dockerCLI.ConfigFile(), authConfig); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ func NewLogoutCommand(dockerCli command.Cli) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runLogout(ctx context.Context, dockerCli command.Cli, serverAddress string) error {
|
||||
func runLogout(ctx context.Context, dockerCLI command.Cli, serverAddress string) error {
|
||||
var isDefaultRegistry bool
|
||||
|
||||
if serverAddress == "" {
|
||||
@ -55,25 +55,25 @@ func runLogout(ctx context.Context, dockerCli command.Cli, serverAddress string)
|
||||
}
|
||||
|
||||
if isDefaultRegistry {
|
||||
store := dockerCli.ConfigFile().GetCredentialsStore(registry.IndexServer)
|
||||
store := dockerCLI.ConfigFile().GetCredentialsStore(registry.IndexServer)
|
||||
if err := manager.NewManager(store).Logout(ctx); err != nil {
|
||||
fmt.Fprintf(dockerCli.Err(), "WARNING: %v\n", err)
|
||||
_, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING:", err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress)
|
||||
_, _ = fmt.Fprintln(dockerCLI.Out(), "Removing login credentials for", hostnameAddress)
|
||||
errs := make(map[string]error)
|
||||
for _, r := range regsToLogout {
|
||||
if err := dockerCli.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil {
|
||||
if err := dockerCLI.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil {
|
||||
errs[r] = err
|
||||
}
|
||||
}
|
||||
|
||||
// if at least one removal succeeded, report success. Otherwise report errors
|
||||
if len(errs) == len(regsToLogout) {
|
||||
fmt.Fprintln(dockerCli.Err(), "WARNING: could not erase credentials:")
|
||||
_, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING: could not erase credentials:")
|
||||
for k, v := range errs {
|
||||
fmt.Fprintf(dockerCli.Err(), "%s: %s\n", k, v)
|
||||
_, _ = fmt.Fprintf(dockerCLI.Err(), "%s: %s\n", k, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user