1
# Copyright (C) 2008 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
"""Use ~/.netrc as a credential store for authentication.conf."""
19
# Since we are a built-in plugin we share the bzrlib version
20
from bzrlib import version_info
27
lazy_import.lazy_import(globals(), """
37
class NetrcCredentialStore(config.CredentialStore):
40
super(NetrcCredentialStore, self).__init__()
42
self._netrc = netrc.netrc()
44
if e.args[0] == errno.ENOENT:
45
raise errors.NoSuchFile(e.filename)
49
def decode_password(self, credentials):
50
auth = self._netrc.authenticators(credentials['host'])
53
user, account, password = auth
54
cred_user = credentials.get('user', None)
55
if cred_user is None or user != cred_user:
56
# We don't use the netrc ability to provide a user since there
57
# is no way to give it back to AuthConfig. So if the user
58
# doesn't match, we don't return a password.
63
config.credential_store_registry.register_lazy(
64
'netrc', __name__, 'NetrcCredentialStore', help=__doc__)
67
def load_tests(basic_tests, module, loader):
71
basic_tests.addTest(loader.loadTestsFromModuleNames(
72
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))