def execute(self, args):
        mgr = SshKeyManager(self.client)

        key_id = resolve_id(mgr.resolve_ids,
                            args.get('<identifier>'), 'SshKey')

        if not mgr.edit_key(key_id,
                            label=args['--label'],
                            notes=args['--notes']):
            raise CLIAbort('Failed to edit SSH key')
Beispiel #2
0
    def execute(self, args):
        mgr = SshKeyManager(self.client)

        key_id = resolve_id(mgr.resolve_ids, args.get("<identifier>"), "SshKey")

        data = {}
        if args.get("--label"):
            data["label"] = args["--label"]
        if args.get("--notes"):
            data["notes"] = args["--notes"]

        if not mgr.edit_key(key_id, **data):
            raise CLIAbort("Failed to edit SSH key")
    def execute(self, args):
        mgr = SshKeyManager(self.client)

        key_id = resolve_id(mgr.resolve_ids,
                            args.get('<identifier>'), 'SshKey')

        data = {}
        if args.get('--label'):
            data['label'] = args['--label']
        if args.get('--notes'):
            data['notes'] = args['--notes']

        if not mgr.edit_key(key_id, **data):
            raise CLIAbort('Failed to edit SSH key')
class SshKeyTests(unittest.TestCase):

    def setUp(self):
        self.client = FixtureClient()
        self.sshkey = SshKeyManager(self.client)

    def test_add_key(self):
        key = 'pretend this is a public SSH key'
        label = 'Test label'
        notes = 'My notes'

        data = {
            'key': key,
            'label': label,
            'notes': notes,
        }
        mcall = call(data)
        service = self.client['Security_Ssh_Key']

        self.sshkey.add_key(key=key, label=label, notes=notes)
        service.createObject.assert_has_calls(mcall)

    def test_delete_key(self):
        id = 1234
        mcall = call(id=id)
        service = self.client['Security_Ssh_Key']

        self.sshkey.delete_key(id)
        service.deleteObject.assert_has_calls(mcall)

    def test_edit_key(self):
        id = 1234
        label = 'Test label'
        notes = 'My notes'

        data = {
            'label': label,
            'notes': notes,
        }
        mcall = call(data, id=id)
        service = self.client['Security_Ssh_Key']

        self.sshkey.edit_key(id, label=label, notes=notes)
        service.editObject.assert_has_calls(mcall)

    def test_get_key(self):
        id = 1234
        mcall = call(id=id)
        service = self.client['Security_Ssh_Key']

        self.sshkey.get_key(id)
        service.getObject.assert_has_calls(mcall)

    def test_list_keys(self):
        service = self.client['Account']
        self.sshkey.list_keys(label='some label')
        service.getSshKeys.assert_called_with(
            filter={'sshKeys': {'label': {'operation': '_= some label'}}})

    def test_resolve_ids_label(self):
        _id = self.sshkey._get_ids_from_label('Test 1')
        self.assertEqual(_id, ['100'])

        _id = self.sshkey._get_ids_from_label('nope')
        self.assertEqual(_id, [])