diff options
| author | Aaron Lehmann <aaron.lehmann@docker.com> | 2016-02-03 10:55:33 -0800 |
|---|---|---|
| committer | Aaron Lehmann <aaron.lehmann@docker.com> | 2016-02-03 11:01:29 -0800 |
| commit | ff17cd0bf07fb8fbd811b3a1bf472d701405b1d1 (patch) | |
| tree | 5aa0543a781a366571dd204db270d81d4cdeb311 /api/client/utils.go | |
| parent | 8ee7ad2209502f43496ff65e32fbcd7573b13c26 (diff) | |
| download | docker-ff17cd0bf07fb8fbd811b3a1bf472d701405b1d1.tar.gz | |
Introduce a client-side version of resolveAuthConfig
This is similar to the version in the registry package, but uses the
daemon's default index (as opposed to the default for the client's
platform) if using the "official index".
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Diffstat (limited to 'api/client/utils.go')
| -rw-r--r-- | api/client/utils.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/api/client/utils.go b/api/client/utils.go index 913955983c..e87e593fe2 100644 --- a/api/client/utils.go +++ b/api/client/utils.go @@ -10,6 +10,7 @@ import ( gosignal "os/signal" "path/filepath" "runtime" + "strings" "time" "github.com/Sirupsen/logrus" @@ -176,3 +177,42 @@ func copyToFile(outfile string, r io.Reader) error { return nil } + +// 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. +func (cli *DockerCli) resolveAuthConfig(authConfigs map[string]types.AuthConfig, index *registrytypes.IndexInfo) types.AuthConfig { + configKey := index.Name + if index.Official { + configKey = cli.electAuthServer() + } + + // First try the happy case + if c, found := authConfigs[configKey]; found || index.Official { + return c + } + + convertToHostname := func(url string) string { + stripped := url + if strings.HasPrefix(url, "http://") { + stripped = strings.Replace(url, "http://", "", 1) + } else if strings.HasPrefix(url, "https://") { + stripped = strings.Replace(url, "https://", "", 1) + } + + nameParts := strings.SplitN(stripped, "/", 2) + + return nameParts[0] + } + + // Maybe they have a legacy config file, we will iterate the keys converting + // them to the new format and testing + for registry, ac := range authConfigs { + if configKey == convertToHostname(registry) { + return ac + } + } + + // When all else fails, return an empty auth config + return types.AuthConfig{} +} |
