20
20
than once for each place that needs to take it into account.
23
from bzrlib import errors, trace
24
from bzrlib.config import AuthenticationConfig, GlobalConfig
23
from bzrlib import errors
24
from bzrlib.config import GlobalConfig
25
25
from bzrlib.transport import get_transport
36
36
_fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
39
class MismatchedUsernames(errors.BzrError):
41
_fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
42
' account name. Please re-run launchpad-login.')
45
39
def get_lp_login(_config=None):
46
"""Return the user's Launchpad username.
48
:raises: MismatchedUsername if authentication.conf and bazaar.conf
49
disagree about username.
52
_config = GlobalConfig()
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()
62
if None in auth_usernames.values():
63
trace.note('Setting ssh/sftp usernames for launchpad.net.')
64
_set_auth_user(username, auth)
68
def _set_global_option(username, _config=None):
70
_config = GlobalConfig()
71
_config.set_user_option('launchpad_username', username)
40
"""Return the user's Launchpad username"""
42
_config = GlobalConfig()
44
return _config.get_user_option('launchpad_username')
74
47
def set_lp_login(username, _config=None):
75
48
"""Set the user's Launchpad username"""
76
_set_global_option(username, _config)
77
_set_auth_user(username)
80
def _get_auth_user(auth=None):
82
auth = AuthenticationConfig()
83
return {'production': auth.get_user('ssh', 'bazaar.launchpad.net'),
84
'staging': auth.get_user('ssh', 'bazaar.staging.launchpad.net'),}
86
def _set_auth_user(username, auth=None):
88
auth = AuthenticationConfig()
90
'Launchpad', 'bazaar.launchpad.net', username, 'ssh')
92
'Launchpad Staging', 'bazaar.staging.launchpad.net', username, 'ssh')
50
_config = GlobalConfig()
52
_config.set_user_option('launchpad_username', username)
95
55
def check_lp_login(username, _transport=None):