MCPcopy
hub / github.com/docker/docker-py / load_config

Method load_config

docker/auth.py:144–189  ·  view source on GitHub ↗

Loads authentication data from a Docker configuration file in the given root directory or if config_path is passed use given path. Lookup priority: explicit config_path parameter > DOCKER_CONFIG environment variable > ~/.docker/config.json > ~/.docker

(cls, config_path, config_dict, credstore_env=None)

Source from the content-addressed store, hash-verified

142
143 @classmethod
144 def load_config(cls, config_path, config_dict, credstore_env=None):
145 """
146 Loads authentication data from a Docker configuration file in the given
147 root directory or if config_path is passed use given path.
148 Lookup priority:
149 explicit config_path parameter > DOCKER_CONFIG environment
150 variable > ~/.docker/config.json > ~/.dockercfg
151 """
152
153 if not config_dict:
154 config_file = config.find_config_file(config_path)
155
156 if not config_file:
157 return cls({}, credstore_env)
158 try:
159 with open(config_file) as f:
160 config_dict = json.load(f)
161 except (OSError, KeyError, ValueError) as e:
162 # Likely missing new Docker config file or it's in an
163 # unknown format, continue to attempt to read old location
164 # and format.
165 log.debug(e)
166 return cls(_load_legacy_config(config_file), credstore_env)
167
168 res = {}
169 if config_dict.get('auths'):
170 log.debug("Found 'auths' section")
171 res.update({
172 'auths': cls.parse_auth(
173 config_dict.pop('auths'), raise_on_error=True
174 )
175 })
176 if config_dict.get('credsStore'):
177 log.debug("Found 'credsStore' section")
178 res.update({'credsStore': config_dict.pop('credsStore')})
179 if config_dict.get('credHelpers'):
180 log.debug("Found 'credHelpers' section")
181 res.update({'credHelpers': config_dict.pop('credHelpers')})
182 if res:
183 return cls(res, credstore_env)
184
185 log.debug(
186 "Couldn't find auth-related section ; attempting to interpret "
187 "as auth-only file"
188 )
189 return cls({'auths': cls.parse_auth(config_dict)}, credstore_env)
190
191 @property
192 def auths(self):

Calls 5

_load_legacy_configFunction · 0.85
loadMethod · 0.80
parse_authMethod · 0.80
getMethod · 0.45
updateMethod · 0.45