# HG changeset patch # User Christian Oyarzun # Date 2014-11-17 20:42:45 # Node ID e53f1db2b839caf4e6c4e3a04495237072942c13 # Parent 3b147c38b674f67a883e84e2515479d51e0620f9 ssh: when adding a new public key, if no description is provided and the SSH key itself has a comment, use that as description Based on work by Ilya Beda on https://bitbucket.org/ir4y/rhodecode/commits/branch/ssh_server_support , also heavily modified by Mads Kiilerich. diff --git a/kallithea/model/ssh_key.py b/kallithea/model/ssh_key.py --- a/kallithea/model/ssh_key.py +++ b/kallithea/model/ssh_key.py @@ -45,9 +45,11 @@ class SshKeyModel(object): Will raise SshKeyModelException on errors """ try: - ssh.parse_pub_key(public_key) + keytype, pub, comment = ssh.parse_pub_key(public_key) except ssh.SshKeyParseError as e: raise SshKeyModelException(_('SSH key %r is invalid: %s') % (safe_str(public_key), e.message)) + if not description.strip(): + description = comment.strip() user = User.guess_instance(user) diff --git a/kallithea/tests/functional/test_admin_users.py b/kallithea/tests/functional/test_admin_users.py --- a/kallithea/tests/functional/test_admin_users.py +++ b/kallithea/tests/functional/test_admin_users.py @@ -553,7 +553,7 @@ class TestAdminUsersController(TestContr self.checkSessionFlash(response, 'SSH key %s successfully added' % fingerprint) response.follow() ssh_key = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).one() - assert ssh_key.description == description + assert ssh_key.description == u'me@localhost' response = self.app.post(url('edit_user_ssh_keys_delete', id=user_id), {'del_public_key': ssh_key.public_key, diff --git a/kallithea/tests/functional/test_my_account.py b/kallithea/tests/functional/test_my_account.py --- a/kallithea/tests/functional/test_my_account.py +++ b/kallithea/tests/functional/test_my_account.py @@ -285,7 +285,7 @@ class TestMyAccountController(TestContro response.follow() user_id = response.session['authuser']['user_id'] ssh_key = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).one() - assert ssh_key.description == description + assert ssh_key.description == u'me@localhost' response = self.app.post(url('my_account_ssh_keys_delete'), {'del_public_key': ssh_key.public_key,