1079
1079
trace.mutter("Using authentication section: %r", auth_def_name)
1082
if credentials is None:
1083
# No credentials were found in authentication.conf, try the fallback
1084
# credentials stores.
1085
credentials = credential_store_registry.get_fallback_credentials(
1086
scheme, host, port, user, path, realm)
1082
1088
return credentials
1084
1090
def set_credentials(self, name, host, user, scheme=None, password=None,
1227
1233
A credential store provides access to credentials via the password_encoding
1228
1234
field in authentication.conf sections.
1230
Except for stores provided by bzr itself,most stores are expected to be
1236
Except for stores provided by bzr itself, most stores are expected to be
1231
1237
provided by plugins that will therefore use
1232
1238
register_lazy(password_encoding, module_name, member_name, help=help,
1233
info=info) to install themselves.
1239
fallback=fallback) to install themselves.
1241
A fallback credential store is one that is queried if no credentials can be
1242
found via authentication.conf.
1236
1245
def get_credential_store(self, encoding=None):
1251
def is_fallback(self, name):
1252
"""Check if the named credentials store should be used as fallback."""
1253
return self.get_info(name)
1255
def get_fallback_credentials(self, scheme, host, port=None, user=None,
1256
path=None, realm=None):
1257
"""Request credentials from all fallback credentials stores.
1259
The first credentials store that can provide credentials wins.
1262
for name in self.keys():
1263
if not self.is_fallback(name):
1265
cs = self.get_credential_store(name)
1266
credentials = cs.get_credentials(scheme, host, port, user,
1268
if credentials is not None:
1269
# We found some credentials
1273
def register(self, key, obj, help=None, override_existing=False,
1275
"""Register a new object to a name.
1277
:param key: This is the key to use to request the object later.
1278
:param obj: The object to register.
1279
:param help: Help text for this entry. This may be a string or
1280
a callable. If it is a callable, it should take two
1281
parameters (registry, key): this registry and the key that
1282
the help was registered under.
1283
:param override_existing: Raise KeyErorr if False and something has
1284
already been registered for that key. If True, ignore if there
1285
is an existing key (always register the new value).
1286
:param fallback: Whether this credential store should be
1289
return super(CredentialStoreRegistry,
1290
self).register(key, obj, help, info=fallback,
1291
override_existing=override_existing)
1293
def register_lazy(self, key, module_name, member_name,
1294
help=None, override_existing=False,
1296
"""Register a new credential store to be loaded on request.
1298
:param module_name: The python path to the module. Such as 'os.path'.
1299
:param member_name: The member of the module to return. If empty or
1300
None, get() will return the module itself.
1301
:param help: Help text for this entry. This may be a string or
1303
:param override_existing: If True, replace the existing object
1304
with the new one. If False, if there is already something
1305
registered with the same key, raise a KeyError
1306
:param fallback: Whether this credential store should be
1309
return super(CredentialStoreRegistry, self).register_lazy(
1310
key, module_name, member_name, help,
1311
info=fallback, override_existing=override_existing)
1243
1314
credential_store_registry = CredentialStoreRegistry()
1247
1318
"""An abstract class to implement storage for credentials"""
1249
1320
def decode_password(self, credentials):
1250
"""Returns a password for the provided credentials in clear text."""
1321
"""Returns a clear text password for the provided credentials."""
1251
1322
raise NotImplementedError(self.decode_password)
1324
def get_credentials(self, scheme, host, port=None, user=None, path=None,
1326
"""Return the matching credentials from this credential store.
1328
This method is only called on fallback credential stores.
1330
raise NotImplementedError(self.get_credentials)
1254
1334
class PlainTextCredentialStore(CredentialStore):
1255
1335
"""Plain text credential store for the authentication.conf file."""