Kaydet (Commit) 208fb036 authored tarafından shin-'s avatar shin-

Use pseudo-constant for index URL

üst 26933543
...@@ -18,6 +18,7 @@ import os ...@@ -18,6 +18,7 @@ import os
import six import six
INDEX_URL = 'https://index.docker.io/v1/'
def swap_protocol(url): def swap_protocol(url):
if url.startswith('http://'): if url.startswith('http://'):
...@@ -43,7 +44,7 @@ def resolve_repository_name(repo_name): ...@@ -43,7 +44,7 @@ def resolve_repository_name(repo_name):
parts = repo_name.split('/', 1) parts = repo_name.split('/', 1)
if not '.' in parts[0] and not ':' in parts[0] and parts[0] != 'localhost': if not '.' in parts[0] and not ':' in parts[0] and parts[0] != 'localhost':
# This is a docker index repo (ex: foo/bar or ubuntu) # This is a docker index repo (ex: foo/bar or ubuntu)
return 'https://index.docker.io/v1/', repo_name return INDEX_URL, repo_name
if len(parts) < 2: if len(parts) < 2:
raise ValueError('Invalid repository name ({0})'.format(repo_name)) raise ValueError('Invalid repository name ({0})'.format(repo_name))
...@@ -55,9 +56,9 @@ def resolve_repository_name(repo_name): ...@@ -55,9 +56,9 @@ def resolve_repository_name(repo_name):
def resolve_authconfig(authconfig, registry): def resolve_authconfig(authconfig, registry):
if registry == 'https://index.docker.io/v1/' or registry == '': if registry == INDEX_URL or registry == '':
# default to the index server # default to the index server
return authconfig['Configs']['https://index.docker.io/v1/'] return authconfig['Configs'][INDEX_URL]
# if its not the index server there are three cases: # if its not the index server there are three cases:
# #
# 1. this is a full config url -> it should be used as is # 1. this is a full config url -> it should be used as is
...@@ -112,7 +113,7 @@ def load_config(root=None): ...@@ -112,7 +113,7 @@ def load_config(root=None):
if len(buf) < 2: if len(buf) < 2:
raise Exception("The Auth config file is empty") raise Exception("The Auth config file is empty")
user, pwd = decode_auth(buf[0]) user, pwd = decode_auth(buf[0])
config_file['Configs']['https://index.docker.io/v1/'] = { config_file['Configs'][INDEX_URL] = {
'Username': user, 'Username': user,
'Password': pwd, 'Password': pwd,
'Email': buf[1] 'Email': buf[1]
......
...@@ -383,8 +383,8 @@ class TestLoadConfig(BaseTestCase): ...@@ -383,8 +383,8 @@ class TestLoadConfig(BaseTestCase):
f.write('email = sakuya@scarlet.net') f.write('email = sakuya@scarlet.net')
f.close() f.close()
cfg = docker.auth.load_config(folder) cfg = docker.auth.load_config(folder)
self.assertNotEqual(cfg['Configs']['https://index.docker.io/v1/'], None) self.assertNotEqual(cfg['Configs'][docker.auth.INDEX_URL], None)
cfg = cfg['Configs']['https://index.docker.io/v1/'] cfg = cfg['Configs'][docker.auth.INDEX_URL]
self.assertEqual(cfg['Username'], 'sakuya') self.assertEqual(cfg['Username'], 'sakuya')
self.assertEqual(cfg['Password'], 'izayoi') self.assertEqual(cfg['Password'], 'izayoi')
self.assertEqual(cfg['Email'], 'sakuya@scarlet.net') self.assertEqual(cfg['Email'], 'sakuya@scarlet.net')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment