From 4ae4e66e3cfed8e8dfb11e97c2ae32b914b700c0 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 9 Sep 2016 15:24:10 -0400 Subject: [PATCH] Remove cli/command/credentials Signed-off-by: Daniel Nephin --- command/credentials.go | 37 ------------------------------------- command/registry.go | 5 ++--- command/registry/login.go | 2 +- command/registry/logout.go | 2 +- 4 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 command/credentials.go diff --git a/command/credentials.go b/command/credentials.go deleted file mode 100644 index e4a4981458..0000000000 --- a/command/credentials.go +++ /dev/null @@ -1,37 +0,0 @@ -package command - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig/configfile" - "github.com/docker/docker/cliconfig/credentials" -) - -// GetCredentials loads the user credentials from a credentials store. -// The store is determined by the config file settings. -func GetCredentials(c *configfile.ConfigFile, serverAddress string) (types.AuthConfig, error) { - s := LoadCredentialsStore(c) - return s.Get(serverAddress) -} - -// StoreCredentials saves the user credentials in a credentials store. -// The store is determined by the config file settings. -func StoreCredentials(c *configfile.ConfigFile, auth types.AuthConfig) error { - s := LoadCredentialsStore(c) - return s.Store(auth) -} - -// EraseCredentials removes the user credentials from a credentials store. -// The store is determined by the config file settings. -func EraseCredentials(c *configfile.ConfigFile, serverAddress string) error { - s := LoadCredentialsStore(c) - return s.Erase(serverAddress) -} - -// LoadCredentialsStore initializes a new credentials store based -// in the settings provided in the configuration file. -func LoadCredentialsStore(c *configfile.ConfigFile) credentials.Store { - if c.CredentialsStore != "" { - return credentials.NewNativeStore(c) - } - return credentials.NewFileStore(c) -} diff --git a/command/registry.go b/command/registry.go index 65d8f3d8b9..3c78d47d8c 100644 --- a/command/registry.go +++ b/command/registry.go @@ -36,7 +36,6 @@ func (cli *DockerCli) ElectAuthServer(ctx context.Context) string { } // EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload -// TODO: move to client/encode ? func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) { buf, err := json.Marshal(authConfig) if err != nil { @@ -71,7 +70,7 @@ func (cli *DockerCli) ResolveAuthConfig(ctx context.Context, index *registrytype configKey = cli.ElectAuthServer(ctx) } - a, _ := GetCredentials(cli.configFile, configKey) + a, _ := cli.CredentialsStore().Get(configKey) return a } @@ -87,7 +86,7 @@ func (cli *DockerCli) ConfigureAuth(flUser, flPassword, serverAddress string, is serverAddress = registry.ConvertToHostname(serverAddress) } - authconfig, err := GetCredentials(cli.configFile, serverAddress) + authconfig, err := cli.CredentialsStore().Get(serverAddress) if err != nil { return authconfig, err } diff --git a/command/registry/login.go b/command/registry/login.go index dccf538474..f97bb557f2 100644 --- a/command/registry/login.go +++ b/command/registry/login.go @@ -74,7 +74,7 @@ func runLogin(dockerCli *command.DockerCli, opts loginOptions) error { authConfig.Password = "" authConfig.IdentityToken = response.IdentityToken } - if err := command.StoreCredentials(dockerCli.ConfigFile(), authConfig); err != nil { + if err := dockerCli.CredentialsStore().Store(authConfig); err != nil { return fmt.Errorf("Error saving credentials: %v", err) } diff --git a/command/registry/logout.go b/command/registry/logout.go index 1e0c5170a6..3fc59dea7c 100644 --- a/command/registry/logout.go +++ b/command/registry/logout.go @@ -68,7 +68,7 @@ func runLogout(dockerCli *command.DockerCli, serverAddress string) error { fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress) for _, r := range regsToLogout { - if err := command.EraseCredentials(dockerCli.ConfigFile(), r); err != nil { + if err := dockerCli.CredentialsStore().Erase(r); err != nil { fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err) } }