Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions SoftLayer/CLI/sshkey/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions


@click.command()
Expand All @@ -19,6 +20,16 @@
def cli(env, label, in_file, key, note):
"""Add a new SSH key."""

if in_file is None and key is None:
raise exceptions.ArgumentError(
'Either [-f | --in-file] or [-k | --key] arguments are required to add a key'
)

if in_file and key:
raise exceptions.ArgumentError(
'[-f | --in-file] is not allowed with [-k | --key]'
)

if key:
key_text = key
else:
Expand Down
1 change: 1 addition & 0 deletions SoftLayer/managers/sshkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def add_key(self, key, label, notes=None):

:param string key: The SSH key to add
:param string label: The label for the key
:param string notes: Additional notes for the key
:returns: A dictionary of the new key's information.
"""
order = {
Expand Down
15 changes: 15 additions & 0 deletions tests/CLI/modules/sshkey_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,25 @@

import mock

from SoftLayer.CLI import exceptions
from SoftLayer import testing


class SshKeyTests(testing.TestCase):
def test_add_without_key_errors(self):
result = self.run_command(['sshkey', 'add', 'key1'])

self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.ArgumentError)

def test_add_with_key_file_and_key_argument_errors(self):
path = os.path.join(testing.FIXTURE_PATH, 'id_rsa.pub')
result = self.run_command(['sshkey', 'add', 'key1',
'--key=some_key',
'--in-file=%s' % path])

self.assertEqual(result.exit_code, 2)
self.assertIsInstance(result.exception, exceptions.ArgumentError)

def test_add_by_option(self):
service = self.client['Security_Ssh_Key']
Expand Down