16
16
import fileinput
17
17
import json
18
18
import os
19
+ import warnings
19
20
20
21
import six
21
22
22
- from ..utils import utils
23
+ from .. import constants
23
24
from .. import errors
24
25
25
- INDEX_URL = 'https://index.docker.io/v1/'
26
+ INDEX_NAME = 'index.docker.io'
27
+ INDEX_URL = 'https://{0}/v1/' .format (INDEX_NAME )
26
28
DOCKER_CONFIG_FILENAME = os .path .join ('.docker' , 'config.json' )
27
29
LEGACY_DOCKER_CONFIG_FILENAME = '.dockercfg'
28
30
29
31
30
- def expand_registry_url (hostname , insecure = False ):
31
- if hostname .startswith ('http:' ) or hostname .startswith ('https:' ):
32
- return hostname
33
- if utils .ping_registry ('https://' + hostname ):
34
- return 'https://' + hostname
35
- elif insecure :
36
- return 'http://' + hostname
37
- else :
38
- raise errors .DockerException (
39
- "HTTPS endpoint unresponsive and insecure mode isn't enabled."
32
+ def resolve_repository_name (repo_name , insecure = False ):
33
+ if insecure :
34
+ warnings .warn (
35
+ constants .INSECURE_REGISTRY_DEPRECATION_WARNING .format (
36
+ 'resolve_repository_name()'
37
+ ), DeprecationWarning
40
38
)
41
39
42
-
43
- def resolve_repository_name (repo_name , insecure = False ):
44
40
if '://' in repo_name :
45
41
raise errors .InvalidRepository (
46
42
'Repository name cannot contain a scheme ({0})' .format (repo_name ))
47
43
parts = repo_name .split ('/' , 1 )
48
44
if '.' not in parts [0 ] and ':' not in parts [0 ] and parts [0 ] != 'localhost' :
49
45
# This is a docker index repo (ex: foo/bar or ubuntu)
50
- return INDEX_URL , repo_name
46
+ return INDEX_NAME , repo_name
51
47
if len (parts ) < 2 :
52
48
raise errors .InvalidRepository (
53
49
'Invalid repository name ({0})' .format (repo_name ))
@@ -57,7 +53,7 @@ def resolve_repository_name(repo_name, insecure=False):
57
53
'Invalid repository name, try "{0}" instead' .format (parts [1 ])
58
54
)
59
55
60
- return expand_registry_url ( parts [0 ], insecure ) , parts [1 ]
56
+ return parts [0 ], parts [1 ]
61
57
62
58
63
59
def resolve_authconfig (authconfig , registry = None ):
@@ -68,7 +64,7 @@ def resolve_authconfig(authconfig, registry=None):
68
64
Returns None if no match was found.
69
65
"""
70
66
# Default to the public index server
71
- registry = convert_to_hostname (registry ) if registry else INDEX_URL
67
+ registry = convert_to_hostname (registry ) if registry else INDEX_NAME
72
68
73
69
if registry in authconfig :
74
70
return authconfig [registry ]
@@ -102,12 +98,6 @@ def encode_header(auth):
102
98
return base64 .b64encode (auth_json )
103
99
104
100
105
- def encode_full_header (auth ):
106
- """ Returns the given auth block encoded for the X-Registry-Config header.
107
- """
108
- return encode_header ({'configs' : auth })
109
-
110
-
111
101
def parse_auth (entries ):
112
102
"""
113
103
Parses authentication entries
@@ -185,7 +175,7 @@ def load_config(config_path=None):
185
175
'Invalid or empty configuration file!' )
186
176
187
177
username , password = decode_auth (data [0 ])
188
- conf [INDEX_URL ] = {
178
+ conf [INDEX_NAME ] = {
189
179
'username' : username ,
190
180
'password' : password ,
191
181
'email' : data [1 ],
0 commit comments