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.
28
from bzrlib.config import AuthenticationConfig, GlobalConfig
23
from bzrlib import errors
24
from bzrlib.config import GlobalConfig
25
from bzrlib.transport import get_transport
31
28
LAUNCHPAD_BASE = 'https://launchpad.net/'
38
35
class NoRegisteredSSHKeys(errors.BzrError):
39
_fmt = "The user %(user)s has not registered any SSH keys with Launchpad.\n" \
40
"See <https://launchpad.net/people/+me>"
43
class MismatchedUsernames(errors.BzrError):
45
_fmt = ('bazaar.conf and authentication.conf disagree about launchpad'
46
' account name. Please re-run launchpad-login.')
36
_fmt = "The user %(user)s has not registered any SSH keys with Launchpad."
49
39
def get_lp_login(_config=None):
50
"""Return the user's Launchpad username.
52
:raises: MismatchedUsername if authentication.conf and bazaar.conf
53
disagree about username.
56
_config = GlobalConfig()
58
username = _config.get_user_option('launchpad_username')
59
if username is not None:
60
auth = AuthenticationConfig()
61
auth_username = _get_auth_user(auth)
63
if auth_username is None:
64
trace.note('Setting ssh/sftp usernames for launchpad.net.')
65
_set_auth_user(username, auth)
66
elif auth_username != username:
67
raise MismatchedUsernames()
71
def _set_global_option(username, _config=None):
73
_config = GlobalConfig()
74
_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')
77
47
def set_lp_login(username, _config=None):
78
48
"""Set the user's Launchpad username"""
79
_set_global_option(username, _config)
80
_set_auth_user(username)
83
def _get_auth_user(auth=None):
85
auth = AuthenticationConfig()
86
username = auth.get_user('ssh', '.launchpad.net')
89
def _set_auth_user(username, auth=None):
91
auth = AuthenticationConfig()
93
'Launchpad', '.launchpad.net', username, 'ssh')
50
_config = GlobalConfig()
52
_config.set_user_option('launchpad_username', username)
96
55
def check_lp_login(username, _transport=None):