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

Method parse_auth

docker/auth.py:84–141  ·  view source on GitHub ↗

Parses authentication entries Args: entries: Dict of authentication entries. raise_on_error: If set to true, an invalid format will raise InvalidConfigFile Returns: Authentication registry.

(cls, entries, raise_on_error=False)

Source from the content-addressed store, hash-verified

82
83 @classmethod
84 def parse_auth(cls, entries, raise_on_error=False):
85 """
86 Parses authentication entries
87
88 Args:
89 entries: Dict of authentication entries.
90 raise_on_error: If set to true, an invalid format will raise
91 InvalidConfigFile
92
93 Returns:
94 Authentication registry.
95 """
96
97 conf = {}
98 for registry, entry in entries.items():
99 if not isinstance(entry, dict):
100 log.debug(
101 f'Config entry for key {registry} is not auth config'
102 )
103 # We sometimes fall back to parsing the whole config as if it
104 # was the auth config by itself, for legacy purposes. In that
105 # case, we fail silently and return an empty conf if any of the
106 # keys is not formatted properly.
107 if raise_on_error:
108 raise errors.InvalidConfigFile(
109 f'Invalid configuration for registry {registry}'
110 )
111 return {}
112 if 'identitytoken' in entry:
113 log.debug(f'Found an IdentityToken entry for registry {registry}')
114 conf[registry] = {
115 'IdentityToken': entry['identitytoken']
116 }
117 continue # Other values are irrelevant if we have a token
118
119 if 'auth' not in entry:
120 # Starting with engine v1.11 (API 1.23), an empty dictionary is
121 # a valid value in the auths config.
122 # https://github.com/docker/compose/issues/3265
123 log.debug(
124 f'Auth data for {registry} is absent. '
125 f'Client might be using a credentials store instead.'
126 )
127 conf[registry] = {}
128 continue
129
130 username, password = decode_auth(entry['auth'])
131 log.debug(
132 f'Found entry (registry={registry!r}, username={username!r})'
133 )
134
135 conf[registry] = {
136 'username': username,
137 'password': password,
138 'email': entry.get('email'),
139 'serveraddress': registry,
140 }
141 return conf

Callers 4

ResolveAuthTestClass · 0.80
load_configMethod · 0.80
parse_authFunction · 0.80

Calls 2

decode_authFunction · 0.85
getMethod · 0.45