~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

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