/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/account.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-22 19:07:07 UTC
  • mfrom: (3789 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3790.
  • Revision ID: john@arbash-meinel.com-20081022190707-qf5480pbkqp33d51
Merge bzr.dev 3789

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
than once for each place that needs to take it into account.
21
21
"""
22
22
 
23
 
from bzrlib import errors
24
 
from bzrlib.config import GlobalConfig
 
23
from bzrlib import errors, trace
 
24
from bzrlib.config import AuthenticationConfig, GlobalConfig
25
25
from bzrlib.transport import get_transport
26
26
 
27
27
 
36
36
    _fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
37
37
 
38
38
 
 
39
class MismatchedUsernames(errors.BzrError):
 
40
 
 
41
    _fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
 
42
            ' account name.  Please re-run launchpad-login.')
 
43
 
 
44
 
39
45
def get_lp_login(_config=None):
40
 
    """Return the user's Launchpad username"""
41
 
    if _config is None:
42
 
        _config = GlobalConfig()
43
 
 
44
 
    return _config.get_user_option('launchpad_username')
 
46
    """Return the user's Launchpad username.
 
47
 
 
48
    :raises: MismatchedUsername if authentication.conf and bazaar.conf
 
49
        disagree about username.
 
50
    """
 
51
    if _config is None:
 
52
        _config = GlobalConfig()
 
53
 
 
54
    username = _config.get_user_option('launchpad_username')
 
55
    if username is not None:
 
56
        auth = AuthenticationConfig()
 
57
        auth_usernames = _get_auth_user(auth)
 
58
        for auth_username in auth_usernames.values():
 
59
            if auth_username is not None and auth_username != username:
 
60
                raise MismatchedUsernames()
 
61
        # Auto-upgrading
 
62
        if None in auth_usernames.values():
 
63
            trace.note('Setting ssh/sftp usernames for launchpad.net.')
 
64
            _set_auth_user(username, auth)
 
65
    return username
 
66
 
 
67
 
 
68
def _set_global_option(username, _config=None):
 
69
    if _config is None:
 
70
        _config = GlobalConfig()
 
71
    _config.set_user_option('launchpad_username', username)
45
72
 
46
73
 
47
74
def set_lp_login(username, _config=None):
48
75
    """Set the user's Launchpad username"""
49
 
    if _config is None:
50
 
        _config = GlobalConfig()
51
 
 
52
 
    _config.set_user_option('launchpad_username', username)
 
76
    _set_global_option(username, _config)
 
77
    _set_auth_user(username)
 
78
 
 
79
 
 
80
def _get_auth_user(auth=None):
 
81
    if auth is None:
 
82
        auth = AuthenticationConfig()
 
83
    return {'production': auth.get_user('ssh', 'bazaar.launchpad.net'),
 
84
            'staging': auth.get_user('ssh', 'bazaar.staging.launchpad.net'),}
 
85
 
 
86
def _set_auth_user(username, auth=None):
 
87
    if auth is None:
 
88
        auth = AuthenticationConfig()
 
89
    auth.set_credentials(
 
90
        'Launchpad', 'bazaar.launchpad.net', username, 'ssh')
 
91
    auth.set_credentials(
 
92
        'Launchpad Staging', 'bazaar.staging.launchpad.net', username, 'ssh')
53
93
 
54
94
 
55
95
def check_lp_login(username, _transport=None):