1
1
import base64
2
2
import json
3
3
import logging
4
- import os
5
4
6
5
import dockerpycreds
7
6
import six
8
7
9
8
from . import errors
10
- from .constants import IS_WINDOWS_PLATFORM
9
+ from .utils import config
11
10
12
11
INDEX_NAME = 'docker.io'
13
12
INDEX_URL = 'https://index.{0}/v1/' .format (INDEX_NAME )
14
- DOCKER_CONFIG_FILENAME = os .path .join ('.docker' , 'config.json' )
15
- LEGACY_DOCKER_CONFIG_FILENAME = '.dockercfg'
16
13
TOKEN_USERNAME = '<token>'
17
14
18
15
log = logging .getLogger (__name__ )
@@ -105,10 +102,10 @@ def resolve_authconfig(authconfig, registry=None):
105
102
log .debug ("Found {0}" .format (repr (registry )))
106
103
return authconfig [registry ]
107
104
108
- for key , config in six .iteritems (authconfig ):
105
+ for key , conf in six .iteritems (authconfig ):
109
106
if resolve_index_name (key ) == registry :
110
107
log .debug ("Found {0}" .format (repr (key )))
111
- return config
108
+ return conf
112
109
113
110
log .debug ("No entry found" )
114
111
return None
@@ -223,44 +220,6 @@ def parse_auth(entries, raise_on_error=False):
223
220
return conf
224
221
225
222
226
- def find_config_file (config_path = None ):
227
- paths = list (filter (None , [
228
- config_path , # 1
229
- config_path_from_environment (), # 2
230
- os .path .join (home_dir (), DOCKER_CONFIG_FILENAME ), # 3
231
- os .path .join (home_dir (), LEGACY_DOCKER_CONFIG_FILENAME ), # 4
232
- ]))
233
-
234
- log .debug ("Trying paths: {0}" .format (repr (paths )))
235
-
236
- for path in paths :
237
- if os .path .exists (path ):
238
- log .debug ("Found file at path: {0}" .format (path ))
239
- return path
240
-
241
- log .debug ("No config file found" )
242
-
243
- return None
244
-
245
-
246
- def config_path_from_environment ():
247
- config_dir = os .environ .get ('DOCKER_CONFIG' )
248
- if not config_dir :
249
- return None
250
- return os .path .join (config_dir , os .path .basename (DOCKER_CONFIG_FILENAME ))
251
-
252
-
253
- def home_dir ():
254
- """
255
- Get the user's home directory, using the same logic as the Docker Engine
256
- client - use %USERPROFILE% on Windows, $HOME/getuid on POSIX.
257
- """
258
- if IS_WINDOWS_PLATFORM :
259
- return os .environ .get ('USERPROFILE' , '' )
260
- else :
261
- return os .path .expanduser ('~' )
262
-
263
-
264
223
def load_config (config_path = None ):
265
224
"""
266
225
Loads authentication data from a Docker configuration file in the given
@@ -269,7 +228,7 @@ def load_config(config_path=None):
269
228
explicit config_path parameter > DOCKER_CONFIG environment variable >
270
229
~/.docker/config.json > ~/.dockercfg
271
230
"""
272
- config_file = find_config_file (config_path )
231
+ config_file = config . find_config_file (config_path )
273
232
274
233
if not config_file :
275
234
return {}
0 commit comments