~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-01-08 16:12:07 UTC
  • mfrom: (3926.1.1 bzr.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090108161207-d95v7ouel5ibahh0
(vila) Authentication.conf supports credential stores. '.netrc' is
        supported with a new plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
    errors,
79
79
    mail_client,
80
80
    osutils,
 
81
    registry,
81
82
    symbol_versioning,
82
83
    trace,
83
84
    ui,
1176
1177
        return password
1177
1178
 
1178
1179
    def decode_password(self, credentials, encoding):
 
1180
        try:
 
1181
            cs = credential_store_registry.get_credential_store(encoding)
 
1182
        except KeyError:
 
1183
            raise ValueError('%r is not a known password_encoding' % encoding)
 
1184
        credentials['password'] = cs.decode_password(credentials)
1179
1185
        return credentials
1180
1186
 
1181
1187
 
 
1188
class CredentialStoreRegistry(registry.Registry):
 
1189
    """A class that registers credential stores.
 
1190
 
 
1191
    A credential store provides access to credentials via the password_encoding
 
1192
    field in authentication.conf sections.
 
1193
 
 
1194
    Except for stores provided by bzr itself,most stores are expected to be
 
1195
    provided by plugins that will therefore use
 
1196
    register_lazy(password_encoding, module_name, member_name, help=help,
 
1197
    info=info) to install themselves.
 
1198
    """
 
1199
 
 
1200
    def get_credential_store(self, encoding=None):
 
1201
        cs = self.get(encoding)
 
1202
        if callable(cs):
 
1203
            cs = cs()
 
1204
        return cs
 
1205
 
 
1206
 
 
1207
credential_store_registry = CredentialStoreRegistry()
 
1208
 
 
1209
 
 
1210
class CredentialStore(object):
 
1211
    """An abstract class to implement storage for credentials"""
 
1212
 
 
1213
    def decode_password(self, credentials):
 
1214
        """Returns a password for the provided credentials in clear text."""
 
1215
        raise NotImplementedError(self.decode_password)
 
1216
 
 
1217
 
 
1218
class PlainTextCredentialStore(CredentialStore):
 
1219
    """Plain text credential store for the authentication.conf file."""
 
1220
 
 
1221
    def decode_password(self, credentials):
 
1222
        """See CredentialStore.decode_password."""
 
1223
        return credentials['password']
 
1224
 
 
1225
 
 
1226
credential_store_registry.register('plain', PlainTextCredentialStore,
 
1227
                                   help=PlainTextCredentialStore.__doc__)
 
1228
credential_store_registry.default_key = 'plain'
 
1229
 
 
1230
 
1182
1231
class BzrDirConfig(object):
1183
1232
 
1184
1233
    def __init__(self, transport):