/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5752.3.8 by John Arbash Meinel
Merge bzr.dev 5764 to resolve release-notes (aka NEWS) conflicts
1
# Copyright (C) 2008-2011 Canonical Ltd
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
16
5131.2.2 by Martin
Catch a couple of missed plugin module docstrings, note need for assignment to __doc__ in developer documentation and NEWS
17
__doc__ = """Use ~/.netrc as a credential store for authentication.conf."""
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
# Since we are a built-in plugin we share the breezy version
7143.11.1 by Jelmer Vernooij
Remove some unused imports.
20
from ... import version_info  # noqa: F401
4283.3.1 by Vincent Ladeuil
Make built-in plugins display the same version than bzrlib.
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from ... import (
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
23
    config,
7413.8.11 by Jelmer Vernooij
Don't lazy-import errors.
24
    errors,
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
25
    lazy_import,
26
    )
27
28
lazy_import.lazy_import(globals(), """
5753.2.2 by Jelmer Vernooij
Remove some unnecessary imports, clean up lazy imports.
29
import errno
30
import netrc
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
31
""")
32
33
34
class NetrcCredentialStore(config.CredentialStore):
35
36
    def __init__(self):
37
        super(NetrcCredentialStore, self).__init__()
38
        try:
39
            self._netrc = netrc.netrc()
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
40
        except IOError as e:
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
41
            if e.args[0] == errno.ENOENT:
42
                raise errors.NoSuchFile(e.filename)
43
            else:
44
                raise
45
46
    def decode_password(self, credentials):
47
        auth = self._netrc.authenticators(credentials['host'])
48
        password = None
49
        if auth is not None:
50
            user, account, password = auth
51
            cred_user = credentials.get('user', None)
52
            if cred_user is None or user != cred_user:
3757.3.3 by Vincent Ladeuil
Aaron's feedback.
53
                # We don't use the netrc ability to provide a user since there
54
                # is no way to give it back to AuthConfig. So if the user
55
                # doesn't match, we don't return a password.
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
56
                password = None
57
        return password
58
59
60
config.credential_store_registry.register_lazy(
61
    'netrc', __name__, 'NetrcCredentialStore', help=__doc__)
62
63
6625.1.5 by Martin
Drop custom load_tests implementation and use unittest signature
64
def load_tests(loader, basic_tests, pattern):
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
65
    testmod_names = [
66
        'tests',
67
        ]
68
    basic_tests.addTest(loader.loadTestsFromModuleNames(
7143.15.2 by Jelmer Vernooij
Run autopep8.
69
        ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
70
    return basic_tests