Skip to content

Commit ba95504

Browse files
author
Brian Flores
committed
added new command, unit tests and updated core test to work with commands that name starts with other command names
1 parent a45257a commit ba95504

20 files changed

+107
-125
lines changed

SoftLayer/CLI/environment.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def list_commands(self, *path):
138138

139139
# offset is used to exclude the path that the caller requested.
140140
offset = len(path_str) + 1 if path_str else 0
141-
commands.append(command[offset:])
141+
if ':' not in command[offset:]:
142+
commands.append(command[offset:])
142143

143144
return sorted(commands)
144145

SoftLayer/CLI/routes.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -331,19 +331,17 @@
331331
'SoftLayer.CLI.securitygroup.interface:remove'),
332332
('securitygroup:event-log', 'SoftLayer.CLI.securitygroup.event_log:get_by_request_id'),
333333

334-
('sshkey', 'SoftLayer.CLI.sshkey'),
335-
('sshkey:add', 'SoftLayer.CLI.sshkey.add:cli'),
336-
('sshkey:remove', 'SoftLayer.CLI.sshkey.remove:cli'),
337-
('sshkey:edit', 'SoftLayer.CLI.sshkey.edit:cli'),
338-
('sshkey:list', 'SoftLayer.CLI.sshkey.list:cli'),
339-
('sshkey:print', 'SoftLayer.CLI.sshkey.print:cli'),
340-
341-
('ssl', 'SoftLayer.CLI.ssl'),
342-
('ssl:add', 'SoftLayer.CLI.ssl.add:cli'),
343-
('ssl:download', 'SoftLayer.CLI.ssl.download:cli'),
344-
('ssl:edit', 'SoftLayer.CLI.ssl.edit:cli'),
345-
('ssl:list', 'SoftLayer.CLI.ssl.list:cli'),
346-
('ssl:remove', 'SoftLayer.CLI.ssl.remove:cli'),
334+
('security', 'SoftLayer.CLI.security'),
335+
('security:sshkey-add', 'SoftLayer.CLI.security.sshkey_add:cli'),
336+
('security:sshkey-remove', 'SoftLayer.CLI.security.sshkey_remove:cli'),
337+
('security:sshkey-edit', 'SoftLayer.CLI.security.sshkey_edit:cli'),
338+
('security:sshkey-list', 'SoftLayer.CLI.security.sshkey_list:cli'),
339+
('security:sshkey-print', 'SoftLayer.CLI.security.sshkey_print:cli'),
340+
('security:cert-add', 'SoftLayer.CLI.security.cert_add:cli'),
341+
('security:cert-download', 'SoftLayer.CLI.security.cert_download:cli'),
342+
('security:cert-edit', 'SoftLayer.CLI.security.cert_edit:cli'),
343+
('security:cert-list', 'SoftLayer.CLI.security.cert_list:cli'),
344+
('security:cert-remove', 'SoftLayer.CLI.security.cert_remove:cli'),
347345

348346
('subnet', 'SoftLayer.CLI.subnet'),
349347
('subnet:cancel', 'SoftLayer.CLI.subnet.cancel:cli'),

SoftLayer/CLI/security/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""SSH Keys and SSL Certificates."""
2+
# :license: MIT, see LICENSE for more details.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

SoftLayer/CLI/sshkey/__init__.py

-1
This file was deleted.

SoftLayer/CLI/ssl/__init__.py

-1
This file was deleted.

docs/cli/security.rst

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.. _cli_security:
2+
3+
SSH Keys and SSL Certificates
4+
========
5+
6+
.. click:: SoftLayer.CLI.security.sshkey_add:cli
7+
:prog: security sshkey-add
8+
:show-nested:
9+
10+
.. click:: SoftLayer.CLI.security.sshkey_remove:cli
11+
:prog: security sshkey-remove
12+
:show-nested:
13+
14+
.. click:: SoftLayer.CLI.security.sshkey_edit:cli
15+
:prog: security sshkey-edit
16+
:show-nested:
17+
18+
.. click:: SoftLayer.CLI.security.sshkey_list:cli
19+
:prog: security sshkey-list
20+
:show-nested:
21+
22+
.. click:: SoftLayer.CLI.security.sshkey_print:cli
23+
:prog: security sshkey-print
24+
:show-nested:
25+
26+
.. click:: SoftLayer.CLI.security.cert_add:cli
27+
:prog: security cert-add
28+
:show-nested:
29+
30+
.. click:: SoftLayer.CLI.security.cert_download:cli
31+
:prog: security cert-download
32+
:show-nested:
33+
34+
.. click:: SoftLayer.CLI.security.cert_edit:cli
35+
:prog: security cert-edit
36+
:show-nested:
37+
38+
.. click:: SoftLayer.CLI.security.cert_list:cli
39+
:prog: security cert-list
40+
:show-nested:
41+
42+
.. click:: SoftLayer.CLI.security.cert_remove:cli
43+
:prog: security cert-remove
44+
:show-nested:

docs/cli/sshkey.rst

-24
This file was deleted.

docs/cli/ssl.rst

-25
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
SoftLayer.tests.CLI.modules.sshkey_tests
2+
SoftLayer.tests.CLI.modules.security_tests
33
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
55
:license: MIT, see LICENSE for more details.
@@ -15,27 +15,27 @@
1515
from SoftLayer import testing
1616

1717

18-
class SshKeyTests(testing.TestCase):
19-
def test_add_without_key_errors(self):
20-
result = self.run_command(['sshkey', 'add', 'key1'])
18+
class SecurityTests(testing.TestCase):
19+
def test_add_sshkey_without_key_errors(self):
20+
result = self.run_command(['security', 'sshkey-add', 'key1'])
2121

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

25-
def test_add_with_key_file_and_key_argument_errors(self):
25+
def test_add_sshkey_with_key_file_and_key_argument_errors(self):
2626
path = os.path.join(testing.FIXTURE_PATH, 'id_rsa.pub')
27-
result = self.run_command(['sshkey', 'add', 'key1',
27+
result = self.run_command(['security', 'sshkey-add', 'key1',
2828
'--key=some_key',
2929
'--in-file=%s' % path])
3030

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

34-
def test_add_by_option(self):
34+
def test_add_sshkey_by_option(self):
3535
service = self.client['Security_Ssh_Key']
3636
mock_key = service.getObject()['key']
3737

38-
result = self.run_command(['sshkey', 'add', 'key1',
38+
result = self.run_command(['security', 'sshkey-add', 'key1',
3939
'--key=%s' % mock_key,
4040
'--note=my key'])
4141

@@ -47,10 +47,10 @@ def test_add_by_option(self):
4747
'key': mock_key,
4848
'label': 'key1'},))
4949

50-
def test_add_by_file(self):
50+
def test_add_sshkey_by_file(self):
5151
path = os.path.join(testing.FIXTURE_PATH, 'id_rsa.pub')
5252

53-
result = self.run_command(['sshkey', 'add', 'key1',
53+
result = self.run_command(['security', 'sshkey-add', 'key1',
5454
'--in-file=%s' % path])
5555

5656
self.assert_no_fail(result)
@@ -63,22 +63,22 @@ def test_add_by_file(self):
6363
'key': mock_key,
6464
'label': 'key1'},))
6565

66-
def test_remove_key(self):
67-
result = self.run_command(['--really', 'sshkey', 'remove', '1234'])
66+
def test_remove_sshkey_key(self):
67+
result = self.run_command(['--really', 'security', 'sshkey-remove', '1234'])
6868

6969
self.assert_no_fail(result)
7070
self.assert_called_with('SoftLayer_Security_Ssh_Key', 'deleteObject',
7171
identifier=1234)
7272

7373
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
74-
def test_remove_key_fail(self, ngb_mock):
74+
def test_remove_sshkey_fail(self, ngb_mock):
7575
ngb_mock.return_value = False
76-
result = self.run_command(['sshkey', 'remove', '1234'])
76+
result = self.run_command(['security', 'sshkey-remove', '1234'])
7777

7878
self.assertEqual(result.exit_code, 2)
7979

80-
def test_edit_key(self):
81-
result = self.run_command(['sshkey', 'edit', '1234',
80+
def test_edit_sshkey(self):
81+
result = self.run_command(['security', 'sshkey-edit', '1234',
8282
'--label=key1', '--note=my key'])
8383

8484
self.assert_no_fail(result)
@@ -87,17 +87,17 @@ def test_edit_key(self):
8787
'label': 'key1'},),
8888
identifier=1234)
8989

90-
def test_edit_key_fail(self):
90+
def test_edit_sshkey_fail(self):
9191
fixture = self.set_mock('SoftLayer_Security_Ssh_Key', 'editObject')
9292
fixture.return_value = False
9393

94-
result = self.run_command(['sshkey', 'edit', '1234',
94+
result = self.run_command(['security', 'sshkey-edit', '1234',
9595
'--label=key1', '--note=my key'])
9696

9797
self.assertEqual(result.exit_code, 2)
9898

99-
def test_list_keys(self):
100-
result = self.run_command(['sshkey', 'list'])
99+
def test_list_sshkeys(self):
100+
result = self.run_command(['security', 'sshkey-list'])
101101

102102
self.assert_no_fail(result)
103103
self.assertEqual(json.loads(result.output),
@@ -110,21 +110,45 @@ def test_list_keys(self):
110110
'id': '101',
111111
'label': 'Test 2'}])
112112

113-
def test_print_key(self):
114-
result = self.run_command(['sshkey', 'print', '1234'])
113+
def test_print_sshkey(self):
114+
result = self.run_command(['security', 'sshkey-print', '1234'])
115115

116116
self.assert_no_fail(result)
117117
self.assertEqual(json.loads(result.output),
118118
{'id': 1234, 'label': 'label', 'notes': 'notes'})
119119

120-
def test_print_key_file(self):
120+
def test_print_sshkey_file(self):
121121
if sys.platform.startswith("win"):
122122
self.skipTest("Test doesn't work in Windows")
123123
with tempfile.NamedTemporaryFile() as sshkey_file:
124124
service = self.client['Security_Ssh_Key']
125125
mock_key = service.getObject()['key']
126-
result = self.run_command(['sshkey', 'print', '1234',
126+
result = self.run_command(['security', 'sshkey-print', '1234',
127127
'--out-file=%s' % sshkey_file.name])
128128

129129
self.assert_no_fail(result)
130130
self.assertEqual(mock_key, sshkey_file.read().decode("utf-8"))
131+
132+
def test_list_certficates(self):
133+
result = self.run_command(['security', 'cert-list', '--status', 'all'])
134+
self.assert_no_fail(result)
135+
self.assertEqual(json.loads(result.output), [
136+
{
137+
"id": 1234,
138+
"common_name": "cert",
139+
"days_until_expire": 0,
140+
"notes": None
141+
}
142+
])
143+
144+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
145+
def test_remove_certficate(self, confirm_mock):
146+
confirm_mock.return_value = True
147+
result = self.run_command(['security', 'cert-remove', '123456'])
148+
self.assert_no_fail(result)
149+
self.assertEqual(result.exit_code, 0)
150+
151+
def test_download_certficate(self):
152+
result = self.run_command(['security', 'cert-download', '123456'])
153+
self.assert_no_fail(result)
154+
self.assertEqual(result.exit_code, 0)

tests/CLI/modules/ssl_tests.py

-36
This file was deleted.

0 commit comments

Comments
 (0)