Remove cli/command/credentials

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-09-09 15:24:10 -04:00
parent ed55f00674
commit 4ae4e66e3c
4 changed files with 4 additions and 42 deletions

View File

@ -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)
}

View File

@ -36,7 +36,6 @@ func (cli *DockerCli) ElectAuthServer(ctx context.Context) string {
} }
// EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload // EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload
// TODO: move to client/encode ?
func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) { func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
buf, err := json.Marshal(authConfig) buf, err := json.Marshal(authConfig)
if err != nil { if err != nil {
@ -71,7 +70,7 @@ func (cli *DockerCli) ResolveAuthConfig(ctx context.Context, index *registrytype
configKey = cli.ElectAuthServer(ctx) configKey = cli.ElectAuthServer(ctx)
} }
a, _ := GetCredentials(cli.configFile, configKey) a, _ := cli.CredentialsStore().Get(configKey)
return a return a
} }
@ -87,7 +86,7 @@ func (cli *DockerCli) ConfigureAuth(flUser, flPassword, serverAddress string, is
serverAddress = registry.ConvertToHostname(serverAddress) serverAddress = registry.ConvertToHostname(serverAddress)
} }
authconfig, err := GetCredentials(cli.configFile, serverAddress) authconfig, err := cli.CredentialsStore().Get(serverAddress)
if err != nil { if err != nil {
return authconfig, err return authconfig, err
} }

View File

@ -74,7 +74,7 @@ func runLogin(dockerCli *command.DockerCli, opts loginOptions) error {
authConfig.Password = "" authConfig.Password = ""
authConfig.IdentityToken = response.IdentityToken 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) return fmt.Errorf("Error saving credentials: %v", err)
} }

View File

@ -68,7 +68,7 @@ func runLogout(dockerCli *command.DockerCli, serverAddress string) error {
fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress) fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress)
for _, r := range regsToLogout { 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) fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err)
} }
} }