~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/netrc_credential_store/__init__.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
2
 
#
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.
7
 
#
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.
12
 
#
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
16
 
 
17
 
from __future__ import absolute_import
18
 
 
19
 
__doc__ = """Use ~/.netrc as a credential store for authentication.conf."""
20
 
 
21
 
# Since we are a built-in plugin we share the bzrlib version
22
 
from bzrlib import version_info
23
 
 
24
 
from bzrlib import (
25
 
    config,
26
 
    lazy_import,
27
 
    )
28
 
 
29
 
lazy_import.lazy_import(globals(), """
30
 
import errno
31
 
import netrc
32
 
 
33
 
from bzrlib import (
34
 
    errors,
35
 
    )
36
 
""")
37
 
 
38
 
 
39
 
class NetrcCredentialStore(config.CredentialStore):
40
 
 
41
 
    def __init__(self):
42
 
        super(NetrcCredentialStore, self).__init__()
43
 
        try:
44
 
            self._netrc = netrc.netrc()
45
 
        except IOError, e:
46
 
            if e.args[0] == errno.ENOENT:
47
 
                raise errors.NoSuchFile(e.filename)
48
 
            else:
49
 
                raise
50
 
 
51
 
    def decode_password(self, credentials):
52
 
        auth = self._netrc.authenticators(credentials['host'])
53
 
        password = None
54
 
        if auth is not None:
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.
61
 
                password = None
62
 
        return password
63
 
 
64
 
 
65
 
config.credential_store_registry.register_lazy(
66
 
    'netrc', __name__, 'NetrcCredentialStore', help=__doc__)
67
 
 
68
 
 
69
 
def load_tests(basic_tests, module, loader):
70
 
    testmod_names = [
71
 
        'tests',
72
 
        ]
73
 
    basic_tests.addTest(loader.loadTestsFromModuleNames(
74
 
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
75
 
    return basic_tests