mirror of https://github.com/docker/cli.git
Remove RetrieveAuthConfigs
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
5fe882a494
commit
ed55f00674
|
@ -64,6 +64,15 @@ func (cli *DockerCli) ConfigFile() *configfile.ConfigFile {
|
||||||
return cli.configFile
|
return cli.configFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CredentialsStore returns a new credentials store based
|
||||||
|
// on the settings provided in the configuration file.
|
||||||
|
func (cli *DockerCli) CredentialsStore() credentials.Store {
|
||||||
|
if cli.configFile.CredentialsStore != "" {
|
||||||
|
return credentials.NewNativeStore(cli.configFile)
|
||||||
|
}
|
||||||
|
return credentials.NewFileStore(cli.configFile)
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the dockerCli runs initialization that must happen after command
|
// Initialize the dockerCli runs initialization that must happen after command
|
||||||
// line flags are parsed.
|
// line flags are parsed.
|
||||||
func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
|
func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
|
||||||
|
|
|
@ -13,13 +13,6 @@ func GetCredentials(c *configfile.ConfigFile, serverAddress string) (types.AuthC
|
||||||
return s.Get(serverAddress)
|
return s.Get(serverAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllCredentials loads all credentials from a credentials store.
|
|
||||||
// The store is determined by the config file settings.
|
|
||||||
func GetAllCredentials(c *configfile.ConfigFile) (map[string]types.AuthConfig, error) {
|
|
||||||
s := LoadCredentialsStore(c)
|
|
||||||
return s.GetAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
// StoreCredentials saves the user credentials in a credentials store.
|
// StoreCredentials saves the user credentials in a credentials store.
|
||||||
// The store is determined by the config file settings.
|
// The store is determined by the config file settings.
|
||||||
func StoreCredentials(c *configfile.ConfigFile, auth types.AuthConfig) error {
|
func StoreCredentials(c *configfile.ConfigFile, auth types.AuthConfig) error {
|
||||||
|
|
|
@ -266,6 +266,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authConfig, _ := dockerCli.CredentialsStore().GetAll()
|
||||||
buildOptions := types.ImageBuildOptions{
|
buildOptions := types.ImageBuildOptions{
|
||||||
Memory: memory,
|
Memory: memory,
|
||||||
MemorySwap: memorySwap,
|
MemorySwap: memorySwap,
|
||||||
|
@ -286,7 +287,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
|
||||||
ShmSize: shmSize,
|
ShmSize: shmSize,
|
||||||
Ulimits: options.ulimits.GetList(),
|
Ulimits: options.ulimits.GetList(),
|
||||||
BuildArgs: runconfigopts.ConvertKVStringsToMap(options.buildArgs.GetAll()),
|
BuildArgs: runconfigopts.ConvertKVStringsToMap(options.buildArgs.GetAll()),
|
||||||
AuthConfigs: dockerCli.RetrieveAuthConfigs(),
|
AuthConfigs: authConfig,
|
||||||
Labels: runconfigopts.ConvertKVStringsToMap(options.labels),
|
Labels: runconfigopts.ConvertKVStringsToMap(options.labels),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ElectAuthServer returns the default registry to use (by asking the daemon)
|
// ElectAuthServer returns the default registry to use (by asking the daemon)
|
||||||
|
// TODO: only used in registry package and from ResolveAuthConfig
|
||||||
func (cli *DockerCli) ElectAuthServer(ctx context.Context) string {
|
func (cli *DockerCli) ElectAuthServer(ctx context.Context) string {
|
||||||
// The daemon `/info` endpoint informs us of the default registry being
|
// The daemon `/info` endpoint informs us of the default registry being
|
||||||
// used. This is essential in cross-platforms environment, where for
|
// used. This is essential in cross-platforms environment, where for
|
||||||
|
@ -35,6 +36,7 @@ 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 {
|
||||||
|
@ -45,6 +47,7 @@ func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
|
||||||
|
|
||||||
// RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info
|
// RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info
|
||||||
// for the given command.
|
// for the given command.
|
||||||
|
// TODO: image/plugin
|
||||||
func (cli *DockerCli) RegistryAuthenticationPrivilegedFunc(index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc {
|
func (cli *DockerCli) RegistryAuthenticationPrivilegedFunc(index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc {
|
||||||
return func() (string, error) {
|
return func() (string, error) {
|
||||||
fmt.Fprintf(cli.out, "\nPlease login prior to %s:\n", cmdName)
|
fmt.Fprintf(cli.out, "\nPlease login prior to %s:\n", cmdName)
|
||||||
|
@ -58,17 +61,10 @@ func (cli *DockerCli) RegistryAuthenticationPrivilegedFunc(index *registrytypes.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) promptWithDefault(prompt string, configDefault string) {
|
|
||||||
if configDefault == "" {
|
|
||||||
fmt.Fprintf(cli.out, "%s: ", prompt)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(cli.out, "%s (%s): ", prompt, configDefault)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResolveAuthConfig is like registry.ResolveAuthConfig, but if using the
|
// ResolveAuthConfig is like registry.ResolveAuthConfig, but if using the
|
||||||
// default index, it uses the default index name for the daemon's platform,
|
// default index, it uses the default index name for the daemon's platform,
|
||||||
// not the client's platform.
|
// not the client's platform.
|
||||||
|
// TODO: plugin/image/container and from RetrieveAuthTokenFromImage
|
||||||
func (cli *DockerCli) ResolveAuthConfig(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
|
func (cli *DockerCli) ResolveAuthConfig(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
|
||||||
configKey := index.Name
|
configKey := index.Name
|
||||||
if index.Official {
|
if index.Official {
|
||||||
|
@ -79,13 +75,8 @@ func (cli *DockerCli) ResolveAuthConfig(ctx context.Context, index *registrytype
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveAuthConfigs return all credentials.
|
|
||||||
func (cli *DockerCli) RetrieveAuthConfigs() map[string]types.AuthConfig {
|
|
||||||
acs, _ := GetAllCredentials(cli.configFile)
|
|
||||||
return acs
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigureAuth returns an AuthConfig from the specified user, password and server.
|
// ConfigureAuth returns an AuthConfig from the specified user, password and server.
|
||||||
|
// TODO: only used in registry package
|
||||||
func (cli *DockerCli) ConfigureAuth(flUser, flPassword, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) {
|
func (cli *DockerCli) ConfigureAuth(flUser, flPassword, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) {
|
||||||
// On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210
|
// On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
|
@ -154,21 +145,26 @@ func (cli *DockerCli) ConfigureAuth(flUser, flPassword, serverAddress string, is
|
||||||
return authconfig, nil
|
return authconfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
|
func readInput(in io.Reader, out io.Writer) string {
|
||||||
func (cli *DockerCli) resolveAuthConfigFromImage(ctx context.Context, image string) (types.AuthConfig, error) {
|
reader := bufio.NewReader(in)
|
||||||
registryRef, err := reference.ParseNamed(image)
|
line, _, err := reader.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.AuthConfig{}, err
|
fmt.Fprintln(out, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
repoInfo, err := registry.ParseRepositoryInfo(registryRef)
|
return string(line)
|
||||||
if err != nil {
|
}
|
||||||
return types.AuthConfig{}, err
|
|
||||||
|
func (cli *DockerCli) promptWithDefault(prompt string, configDefault string) {
|
||||||
|
if configDefault == "" {
|
||||||
|
fmt.Fprintf(cli.out, "%s: ", prompt)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(cli.out, "%s (%s): ", prompt, configDefault)
|
||||||
}
|
}
|
||||||
authConfig := cli.ResolveAuthConfig(ctx, repoInfo.Index)
|
|
||||||
return authConfig, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete image
|
// RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete image
|
||||||
|
// TODO: used in service/stack packages
|
||||||
func (cli *DockerCli) RetrieveAuthTokenFromImage(ctx context.Context, image string) (string, error) {
|
func (cli *DockerCli) RetrieveAuthTokenFromImage(ctx context.Context, image string) (string, error) {
|
||||||
// Retrieve encoded auth token from the image reference
|
// Retrieve encoded auth token from the image reference
|
||||||
authConfig, err := cli.resolveAuthConfigFromImage(ctx, image)
|
authConfig, err := cli.resolveAuthConfigFromImage(ctx, image)
|
||||||
|
@ -182,12 +178,16 @@ func (cli *DockerCli) RetrieveAuthTokenFromImage(ctx context.Context, image stri
|
||||||
return encodedAuth, nil
|
return encodedAuth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readInput(in io.Reader, out io.Writer) string {
|
// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
|
||||||
reader := bufio.NewReader(in)
|
func (cli *DockerCli) resolveAuthConfigFromImage(ctx context.Context, image string) (types.AuthConfig, error) {
|
||||||
line, _, err := reader.ReadLine()
|
registryRef, err := reference.ParseNamed(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(out, err.Error())
|
return types.AuthConfig{}, err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
return string(line)
|
repoInfo, err := registry.ParseRepositoryInfo(registryRef)
|
||||||
|
if err != nil {
|
||||||
|
return types.AuthConfig{}, err
|
||||||
|
}
|
||||||
|
authConfig := cli.ResolveAuthConfig(ctx, repoInfo.Index)
|
||||||
|
return authConfig, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue