20
20
than once for each place that needs to take it into account.
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
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.')
39
45
def get_lp_login(_config=None):
40
"""Return the user's Launchpad username"""
42
_config = GlobalConfig()
44
return _config.get_user_option('launchpad_username')
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_username = _get_auth_user(auth)
59
if auth_username is None:
60
trace.note('Setting ssh/sftp username for bazaar.launchpad.net.')
61
_set_auth_user(username, auth)
62
elif auth_username != username:
63
raise MismatchedUsernames()
67
def _set_global_option(username, _config=None):
69
_config = GlobalConfig()
70
_config.set_user_option('launchpad_username', username)
47
73
def set_lp_login(username, _config=None):
48
74
"""Set the user's Launchpad username"""
50
_config = GlobalConfig()
52
_config.set_user_option('launchpad_username', username)
75
_set_global_option(username, _config)
76
_set_auth_user(username)
79
def _get_auth_user(auth=None):
81
auth = AuthenticationConfig()
82
return auth.get_user('ssh', 'bazaar.launchpad.net')
84
def _set_auth_user(username, auth=None):
86
auth = AuthenticationConfig()
88
'Launchpad', 'bazaar.launchpad.net', username, 'ssh')
55
91
def check_lp_login(username, _transport=None):