|
26 | 26 | DOCKER_CONFIG_FILENAME = '.dockercfg'
|
27 | 27 |
|
28 | 28 |
|
29 |
| -def swap_protocol(url): |
30 |
| - if url.startswith('http://'): |
31 |
| - return url.replace('http://', 'https://', 1) |
32 |
| - if url.startswith('https://'): |
33 |
| - return url.replace('https://', 'http://', 1) |
34 |
| - return url |
35 |
| - |
36 |
| - |
37 | 29 | def expand_registry_url(hostname, insecure=False):
|
38 | 30 | if hostname.startswith('http:') or hostname.startswith('https:'):
|
39 | 31 | return hostname
|
@@ -68,29 +60,27 @@ def resolve_repository_name(repo_name, insecure=False):
|
68 | 60 |
|
69 | 61 |
|
70 | 62 | def resolve_authconfig(authconfig, registry=None):
|
71 |
| - """Return the authentication data from the given auth configuration for a |
72 |
| - specific registry. We'll do our best to infer the correct URL for the |
73 |
| - registry, trying both http and https schemes. Returns an empty dictionnary |
74 |
| - if no data exists.""" |
| 63 | + """ |
| 64 | + Returns the authentication data from the given auth configuration for a |
| 65 | + specific registry. As with the Docker client, legacy entries in the config |
| 66 | + with full URLs are stripped down to hostnames before checking for a match. |
| 67 | + Returns None if no match was found. |
| 68 | + """ |
75 | 69 | # Default to the public index server
|
76 |
| - registry = registry or INDEX_URL |
77 |
| - |
78 |
| - # If it's not the index server there are three cases: |
79 |
| - # |
80 |
| - # 1. this is a full config url -> it should be used as is |
81 |
| - # 2. it could be a full url, but with the wrong protocol |
82 |
| - # 3. it can be the hostname optionally with a port |
83 |
| - # |
84 |
| - # as there is only one auth entry which is fully qualified we need to start |
85 |
| - # parsing and matching |
86 |
| - if '/v1/' not in registry: |
87 |
| - registry = os.path.join(registry, 'v1/') |
88 |
| - if not registry.startswith('http:') and not registry.startswith('https:'): |
89 |
| - registry = 'https://' + registry |
| 70 | + registry = convert_to_hostname(registry) if registry else INDEX_URL |
90 | 71 |
|
91 | 72 | if registry in authconfig:
|
92 | 73 | return authconfig[registry]
|
93 |
| - return authconfig.get(swap_protocol(registry), None) |
| 74 | + |
| 75 | + for key, config in six.iteritems(authconfig): |
| 76 | + if convert_to_hostname(key) == registry: |
| 77 | + return config |
| 78 | + |
| 79 | + return None |
| 80 | + |
| 81 | + |
| 82 | +def convert_to_hostname(url): |
| 83 | + return url.replace('http://', '').replace('https://', '').split('/', 1)[0] |
94 | 84 |
|
95 | 85 |
|
96 | 86 | def encode_auth(auth_info):
|
|
0 commit comments