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

Class AuthConfig

docker/auth.py:75–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74
75class AuthConfig(dict):
76 def __init__(self, dct, credstore_env=None):
77 if 'auths' not in dct:
78 dct['auths'] = {}
79 self.update(dct)
80 self._credstore_env = credstore_env
81 self._stores = {}
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})'

Callers 2

get_credential_storeFunction · 0.85
resolve_authconfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected