13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Functions to manage the user's Launchpad user ID.
20
20
than once for each place that needs to take it into account.
23
from __future__ import absolute_import
23
from bzrlib import errors
24
from bzrlib.config import GlobalConfig
25
from bzrlib.transport import get_transport
30
from bzrlib.config import AuthenticationConfig, GlobalStack
31
from bzrlib.i18n import gettext
33
28
LAUNCHPAD_BASE = 'https://launchpad.net/'
40
35
class NoRegisteredSSHKeys(errors.BzrError):
41
_fmt = "The user %(user)s has not registered any SSH keys with Launchpad.\n" \
42
"See <https://launchpad.net/people/+me>"
45
class MismatchedUsernames(errors.BzrError):
47
_fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
48
' account name. Please re-run launchpad-login.')
36
_fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
51
39
def get_lp_login(_config=None):
52
"""Return the user's Launchpad username.
54
:raises: MismatchedUsername if authentication.conf and bazaar.conf
55
disagree about username.
58
_config = GlobalStack()
60
username = _config.get('launchpad_username')
61
if username is not None:
62
auth = AuthenticationConfig()
63
auth_username = _get_auth_user(auth)
65
if auth_username is None:
66
trace.note(gettext('Setting ssh/sftp usernames for launchpad.net.'))
67
_set_auth_user(username, auth)
68
elif auth_username != username:
69
raise MismatchedUsernames()
73
def _set_global_option(username, _config=None):
75
_config = GlobalStack()
76
_config.set('launchpad_username', username)
40
"""Return the user's Launchpad username"""
42
_config = GlobalConfig()
44
return _config.get_user_option('launchpad_username')
79
47
def set_lp_login(username, _config=None):
80
48
"""Set the user's Launchpad username"""
81
_set_global_option(username, _config)
82
_set_auth_user(username)
85
def _get_auth_user(auth=None):
87
auth = AuthenticationConfig()
88
username = auth.get_user('ssh', '.launchpad.net')
91
def _set_auth_user(username, auth=None):
93
auth = AuthenticationConfig()
95
'Launchpad', '.launchpad.net', username, 'ssh')
50
_config = GlobalConfig()
52
_config.set_user_option('launchpad_username', username)
98
55
def check_lp_login(username, _transport=None):