Browse code

Remove RetrieveAuthConfigs

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/09/09 23:49:52
Showing 4 changed files
... ...
@@ -64,6 +64,15 @@ func (cli *DockerCli) ConfigFile() *configfile.ConfigFile {
64 64
 	return cli.configFile
65 65
 }
66 66
 
67
+// CredentialsStore returns a new credentials store based
68
+// on the settings provided in the configuration file.
69
+func (cli *DockerCli) CredentialsStore() credentials.Store {
70
+	if cli.configFile.CredentialsStore != "" {
71
+		return credentials.NewNativeStore(cli.configFile)
72
+	}
73
+	return credentials.NewFileStore(cli.configFile)
74
+}
75
+
67 76
 // Initialize the dockerCli runs initialization that must happen after command
68 77
 // line flags are parsed.
69 78
 func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
... ...
@@ -13,13 +13,6 @@ func GetCredentials(c *configfile.ConfigFile, serverAddress string) (types.AuthC
13 13
 	return s.Get(serverAddress)
14 14
 }
15 15
 
16
-// GetAllCredentials loads all credentials from a credentials store.
17
-// The store is determined by the config file settings.
18
-func GetAllCredentials(c *configfile.ConfigFile) (map[string]types.AuthConfig, error) {
19
-	s := LoadCredentialsStore(c)
20
-	return s.GetAll()
21
-}
22
-
23 16
 // StoreCredentials saves the user credentials in a credentials store.
24 17
 // The store is determined by the config file settings.
25 18
 func StoreCredentials(c *configfile.ConfigFile, auth types.AuthConfig) error {
... ...
@@ -266,6 +266,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
266 266
 		}
267 267
 	}
268 268
 
269
+	authConfig, _ := dockerCli.CredentialsStore().GetAll()
269 270
 	buildOptions := types.ImageBuildOptions{
270 271
 		Memory:         memory,
271 272
 		MemorySwap:     memorySwap,
... ...
@@ -286,7 +287,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
286 286
 		ShmSize:        shmSize,
287 287
 		Ulimits:        options.ulimits.GetList(),
288 288
 		BuildArgs:      runconfigopts.ConvertKVStringsToMap(options.buildArgs.GetAll()),
289
-		AuthConfigs:    dockerCli.RetrieveAuthConfigs(),
289
+		AuthConfigs:    authConfig,
290 290
 		Labels:         runconfigopts.ConvertKVStringsToMap(options.labels),
291 291
 	}
292 292
 
... ...
@@ -20,6 +20,7 @@ import (
20 20
 )
21 21
 
22 22
 // ElectAuthServer returns the default registry to use (by asking the daemon)
23
+// TODO: only used in registry package and from ResolveAuthConfig
23 24
 func (cli *DockerCli) ElectAuthServer(ctx context.Context) string {
24 25
 	// The daemon `/info` endpoint informs us of the default registry being
25 26
 	// used. This is essential in cross-platforms environment, where for
... ...
@@ -35,6 +36,7 @@ func (cli *DockerCli) ElectAuthServer(ctx context.Context) string {
35 35
 }
36 36
 
37 37
 // EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload
38
+// TODO: move to client/encode ?
38 39
 func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
39 40
 	buf, err := json.Marshal(authConfig)
40 41
 	if err != nil {
... ...
@@ -45,6 +47,7 @@ func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
45 45
 
46 46
 // RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info
47 47
 // for the given command.
48
+// TODO: image/plugin
48 49
 func (cli *DockerCli) RegistryAuthenticationPrivilegedFunc(index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc {
49 50
 	return func() (string, error) {
50 51
 		fmt.Fprintf(cli.out, "\nPlease login prior to %s:\n", cmdName)
... ...
@@ -58,17 +61,10 @@ func (cli *DockerCli) RegistryAuthenticationPrivilegedFunc(index *registrytypes.
58 58
 	}
59 59
 }
60 60
 
61
-func (cli *DockerCli) promptWithDefault(prompt string, configDefault string) {
62
-	if configDefault == "" {
63
-		fmt.Fprintf(cli.out, "%s: ", prompt)
64
-	} else {
65
-		fmt.Fprintf(cli.out, "%s (%s): ", prompt, configDefault)
66
-	}
67
-}
68
-
69 61
 // ResolveAuthConfig is like registry.ResolveAuthConfig, but if using the
70 62
 // default index, it uses the default index name for the daemon's platform,
71 63
 // not the client's platform.
64
+// TODO: plugin/image/container and from RetrieveAuthTokenFromImage
72 65
 func (cli *DockerCli) ResolveAuthConfig(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
73 66
 	configKey := index.Name
74 67
 	if index.Official {
... ...
@@ -79,13 +75,8 @@ func (cli *DockerCli) ResolveAuthConfig(ctx context.Context, index *registrytype
79 79
 	return a
80 80
 }
81 81
 
82
-// RetrieveAuthConfigs return all credentials.
83
-func (cli *DockerCli) RetrieveAuthConfigs() map[string]types.AuthConfig {
84
-	acs, _ := GetAllCredentials(cli.configFile)
85
-	return acs
86
-}
87
-
88 82
 // ConfigureAuth returns an AuthConfig from the specified user, password and server.
83
+// TODO: only used in registry package
89 84
 func (cli *DockerCli) ConfigureAuth(flUser, flPassword, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) {
90 85
 	// On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210
91 86
 	if runtime.GOOS == "windows" {
... ...
@@ -154,21 +145,26 @@ func (cli *DockerCli) ConfigureAuth(flUser, flPassword, serverAddress string, is
154 154
 	return authconfig, nil
155 155
 }
156 156
 
157
-// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
158
-func (cli *DockerCli) resolveAuthConfigFromImage(ctx context.Context, image string) (types.AuthConfig, error) {
159
-	registryRef, err := reference.ParseNamed(image)
157
+func readInput(in io.Reader, out io.Writer) string {
158
+	reader := bufio.NewReader(in)
159
+	line, _, err := reader.ReadLine()
160 160
 	if err != nil {
161
-		return types.AuthConfig{}, err
161
+		fmt.Fprintln(out, err.Error())
162
+		os.Exit(1)
162 163
 	}
163
-	repoInfo, err := registry.ParseRepositoryInfo(registryRef)
164
-	if err != nil {
165
-		return types.AuthConfig{}, err
164
+	return string(line)
165
+}
166
+
167
+func (cli *DockerCli) promptWithDefault(prompt string, configDefault string) {
168
+	if configDefault == "" {
169
+		fmt.Fprintf(cli.out, "%s: ", prompt)
170
+	} else {
171
+		fmt.Fprintf(cli.out, "%s (%s): ", prompt, configDefault)
166 172
 	}
167
-	authConfig := cli.ResolveAuthConfig(ctx, repoInfo.Index)
168
-	return authConfig, nil
169 173
 }
170 174
 
171 175
 // RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete image
176
+// TODO: used in service/stack packages
172 177
 func (cli *DockerCli) RetrieveAuthTokenFromImage(ctx context.Context, image string) (string, error) {
173 178
 	// Retrieve encoded auth token from the image reference
174 179
 	authConfig, err := cli.resolveAuthConfigFromImage(ctx, image)
... ...
@@ -182,12 +178,16 @@ func (cli *DockerCli) RetrieveAuthTokenFromImage(ctx context.Context, image stri
182 182
 	return encodedAuth, nil
183 183
 }
184 184
 
185
-func readInput(in io.Reader, out io.Writer) string {
186
-	reader := bufio.NewReader(in)
187
-	line, _, err := reader.ReadLine()
185
+// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
186
+func (cli *DockerCli) resolveAuthConfigFromImage(ctx context.Context, image string) (types.AuthConfig, error) {
187
+	registryRef, err := reference.ParseNamed(image)
188 188
 	if err != nil {
189
-		fmt.Fprintln(out, err.Error())
190
-		os.Exit(1)
189
+		return types.AuthConfig{}, err
191 190
 	}
192
-	return string(line)
191
+	repoInfo, err := registry.ParseRepositoryInfo(registryRef)
192
+	if err != nil {
193
+		return types.AuthConfig{}, err
194
+	}
195
+	authConfig := cli.ResolveAuthConfig(ctx, repoInfo.Index)
196
+	return authConfig, nil
193 197
 }