1
# Copyright (C) 2008-2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from __future__ import absolute_import
19
__doc__ = """Use ~/.netrc as a credential store for authentication.conf."""
21
# Since we are a built-in plugin we share the bzrlib version
22
from bzrlib import version_info
29
lazy_import.lazy_import(globals(), """
39
class NetrcCredentialStore(config.CredentialStore):
42
super(NetrcCredentialStore, self).__init__()
44
self._netrc = netrc.netrc()
46
if e.args[0] == errno.ENOENT:
47
raise errors.NoSuchFile(e.filename)
51
def decode_password(self, credentials):
52
auth = self._netrc.authenticators(credentials['host'])
55
user, account, password = auth
56
cred_user = credentials.get('user', None)
57
if cred_user is None or user != cred_user:
58
# We don't use the netrc ability to provide a user since there
59
# is no way to give it back to AuthConfig. So if the user
60
# doesn't match, we don't return a password.
65
config.credential_store_registry.register_lazy(
66
'netrc', __name__, 'NetrcCredentialStore', help=__doc__)
69
def load_tests(basic_tests, module, loader):
73
basic_tests.addTest(loader.loadTestsFromModuleNames(
74
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))