|
@@ -20,6 +20,7 @@ import (
|
|
|
)
|
|
|
|
|
|
// 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 {
|
|
|
// The daemon `/info` endpoint informs us of the default registry being
|
|
|
// 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
|
|
|
+// TODO: move to client/encode ?
|
|
|
func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
|
|
|
buf, err := json.Marshal(authConfig)
|
|
|
if err != nil {
|
|
@@ -45,6 +47,7 @@ func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
|
|
|
|
|
|
// RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info
|
|
|
// for the given command.
|
|
|
+// TODO: image/plugin
|
|
|
func (cli *DockerCli) RegistryAuthenticationPrivilegedFunc(index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc {
|
|
|
return func() (string, error) {
|
|
|
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
|
|
|
// default index, it uses the default index name for the daemon'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 {
|
|
|
configKey := index.Name
|
|
|
if index.Official {
|
|
@@ -79,13 +75,8 @@ func (cli *DockerCli) ResolveAuthConfig(ctx context.Context, index *registrytype
|
|
|
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.
|
|
|
+// TODO: only used in registry package
|
|
|
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
|
|
|
if runtime.GOOS == "windows" {
|
|
@@ -154,21 +145,26 @@ func (cli *DockerCli) ConfigureAuth(flUser, flPassword, serverAddress string, is
|
|
|
return authconfig, nil
|
|
|
}
|
|
|
|
|
|
-// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
|
|
|
-func (cli *DockerCli) resolveAuthConfigFromImage(ctx context.Context, image string) (types.AuthConfig, error) {
|
|
|
- registryRef, err := reference.ParseNamed(image)
|
|
|
+func readInput(in io.Reader, out io.Writer) string {
|
|
|
+ reader := bufio.NewReader(in)
|
|
|
+ line, _, err := reader.ReadLine()
|
|
|
if err != nil {
|
|
|
- return types.AuthConfig{}, err
|
|
|
+ fmt.Fprintln(out, err.Error())
|
|
|
+ os.Exit(1)
|
|
|
}
|
|
|
- repoInfo, err := registry.ParseRepositoryInfo(registryRef)
|
|
|
- if err != nil {
|
|
|
- return types.AuthConfig{}, err
|
|
|
+ return string(line)
|
|
|
+}
|
|
|
+
|
|
|
+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
|
|
|
+// TODO: used in service/stack packages
|
|
|
func (cli *DockerCli) RetrieveAuthTokenFromImage(ctx context.Context, image string) (string, error) {
|
|
|
// Retrieve encoded auth token from the image reference
|
|
|
authConfig, err := cli.resolveAuthConfigFromImage(ctx, image)
|
|
@@ -182,12 +178,16 @@ func (cli *DockerCli) RetrieveAuthTokenFromImage(ctx context.Context, image stri
|
|
|
return encodedAuth, nil
|
|
|
}
|
|
|
|
|
|
-func readInput(in io.Reader, out io.Writer) string {
|
|
|
- reader := bufio.NewReader(in)
|
|
|
- line, _, err := reader.ReadLine()
|
|
|
+// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
|
|
|
+func (cli *DockerCli) resolveAuthConfigFromImage(ctx context.Context, image string) (types.AuthConfig, error) {
|
|
|
+ registryRef, err := reference.ParseNamed(image)
|
|
|
if err != nil {
|
|
|
- fmt.Fprintln(out, err.Error())
|
|
|
- os.Exit(1)
|
|
|
+ return types.AuthConfig{}, err
|
|
|
}
|
|
|
- return string(line)
|
|
|
+ repoInfo, err := registry.ParseRepositoryInfo(registryRef)
|
|
|
+ if err != nil {
|
|
|
+ return types.AuthConfig{}, err
|
|
|
+ }
|
|
|
+ authConfig := cli.ResolveAuthConfig(ctx, repoInfo.Index)
|
|
|
+ return authConfig, nil
|
|
|
}
|