-
Notifications
You must be signed in to change notification settings - Fork 194
New Command: slcli security
#1951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""SSH Keys and SSL Certificates.""" | ||
# :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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
.. _cli_security: | ||
|
||
SSH Keys and SSL Certificates | ||
======== | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_add:cli | ||
:prog: security sshkey-add | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_add:cli | ||
:prog: sshkey add | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_remove:cli | ||
:prog: security sshkey-remove | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_remove:cli | ||
:prog: sshkey remove | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_edit:cli | ||
:prog: security sshkey-edit | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_edit:cli | ||
:prog: sshkey edit | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_list:cli | ||
:prog: security sshkey-list | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_list:cli | ||
:prog: sshkey list | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_print:cli | ||
:prog: security sshkey-print | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.sshkey_print:cli | ||
:prog: sshkey print | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_add:cli | ||
:prog: security cert-add | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_add:cli | ||
:prog: ssl add | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_download:cli | ||
:prog: security cert-download | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_download:cli | ||
:prog: ssl download | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_edit:cli | ||
:prog: security cert-edit | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_edit:cli | ||
:prog: ssl edit | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_list:cli | ||
:prog: security cert-list | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_list:cli | ||
:prog: ssl list | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_remove:cli | ||
:prog: security cert-remove | ||
:show-nested: | ||
|
||
.. click:: SoftLayer.CLI.security.cert_remove:cli | ||
:prog: ssl remove | ||
:show-nested: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
""" | ||
SoftLayer.tests.CLI.modules.security_tests | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
:license: MIT, see LICENSE for more details. | ||
""" | ||
import json | ||
import os.path | ||
import sys | ||
import tempfile | ||
|
||
from unittest import mock as mock | ||
|
||
from SoftLayer.CLI import exceptions | ||
from SoftLayer import testing | ||
|
||
|
||
class SecurityTests(testing.TestCase): | ||
def test_add_sshkey_without_key_errors(self): | ||
result = self.run_command(['security', 'sshkey-add', 'key1']) | ||
|
||
self.assertEqual(result.exit_code, 2) | ||
self.assertIsInstance(result.exception, exceptions.ArgumentError) | ||
|
||
def test_add_sshkey_with_key_file_and_key_argument_errors(self): | ||
path = os.path.join(testing.FIXTURE_PATH, 'id_rsa.pub') | ||
result = self.run_command(['security', '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_sshkey_by_option(self): | ||
service = self.client['Security_Ssh_Key'] | ||
mock_key = service.getObject()['key'] | ||
|
||
result = self.run_command(['security', 'sshkey-add', 'key1', | ||
'--key=%s' % mock_key, | ||
'--note=my key']) | ||
|
||
self.assert_no_fail(result) | ||
self.assertEqual(json.loads(result.output), | ||
"SSH key added: aa:bb:cc:dd") | ||
self.assert_called_with('SoftLayer_Security_Ssh_Key', 'createObject', | ||
args=({'notes': 'my key', | ||
'key': mock_key, | ||
'label': 'key1'},)) | ||
|
||
def test_add_sshkey_by_file(self): | ||
path = os.path.join(testing.FIXTURE_PATH, 'id_rsa.pub') | ||
|
||
result = self.run_command(['security', 'sshkey-add', 'key1', | ||
'--in-file=%s' % path]) | ||
|
||
self.assert_no_fail(result) | ||
self.assertEqual(json.loads(result.output), | ||
"SSH key added: aa:bb:cc:dd") | ||
service = self.client['Security_Ssh_Key'] | ||
mock_key = service.getObject()['key'] | ||
self.assert_called_with('SoftLayer_Security_Ssh_Key', 'createObject', | ||
args=({'notes': None, | ||
'key': mock_key, | ||
'label': 'key1'},)) | ||
|
||
def test_remove_sshkey_key(self): | ||
result = self.run_command(['--really', 'security', 'sshkey-remove', '1234']) | ||
|
||
self.assert_no_fail(result) | ||
self.assert_called_with('SoftLayer_Security_Ssh_Key', 'deleteObject', | ||
identifier=1234) | ||
|
||
@mock.patch('SoftLayer.CLI.formatting.no_going_back') | ||
def test_remove_sshkey_fail(self, ngb_mock): | ||
ngb_mock.return_value = False | ||
result = self.run_command(['security', 'sshkey-remove', '1234']) | ||
|
||
self.assertEqual(result.exit_code, 2) | ||
|
||
def test_edit_sshkey(self): | ||
result = self.run_command(['security', 'sshkey-edit', '1234', | ||
'--label=key1', '--note=my key']) | ||
|
||
self.assert_no_fail(result) | ||
self.assert_called_with('SoftLayer_Security_Ssh_Key', 'editObject', | ||
args=({'notes': 'my key', | ||
'label': 'key1'},), | ||
identifier=1234) | ||
|
||
def test_edit_sshkey_fail(self): | ||
fixture = self.set_mock('SoftLayer_Security_Ssh_Key', 'editObject') | ||
fixture.return_value = False | ||
|
||
result = self.run_command(['security', 'sshkey-edit', '1234', | ||
'--label=key1', '--note=my key']) | ||
|
||
self.assertEqual(result.exit_code, 2) | ||
|
||
def test_list_sshkeys(self): | ||
result = self.run_command(['security', 'sshkey-list']) | ||
|
||
self.assert_no_fail(result) | ||
self.assertEqual(json.loads(result.output), | ||
[{'notes': '-', | ||
'fingerprint': None, | ||
'id': '100', | ||
'label': 'Test 1'}, | ||
{'notes': 'my key', | ||
'fingerprint': None, | ||
'id': '101', | ||
'label': 'Test 2'}]) | ||
|
||
def test_print_sshkey(self): | ||
result = self.run_command(['security', 'sshkey-print', '1234']) | ||
|
||
self.assert_no_fail(result) | ||
self.assertEqual(json.loads(result.output), | ||
{'id': 1234, 'label': 'label', 'notes': 'notes'}) | ||
|
||
def test_print_sshkey_file(self): | ||
if sys.platform.startswith("win"): | ||
self.skipTest("Test doesn't work in Windows") | ||
with tempfile.NamedTemporaryFile() as sshkey_file: | ||
service = self.client['Security_Ssh_Key'] | ||
mock_key = service.getObject()['key'] | ||
result = self.run_command(['security', 'sshkey-print', '1234', | ||
'--out-file=%s' % sshkey_file.name]) | ||
|
||
self.assert_no_fail(result) | ||
self.assertEqual(mock_key, sshkey_file.read().decode("utf-8")) | ||
|
||
def test_list_certficates(self): | ||
result = self.run_command(['security', 'cert-list', '--status', 'all']) | ||
self.assert_no_fail(result) | ||
self.assertEqual(json.loads(result.output), [ | ||
{ | ||
"id": 1234, | ||
"common_name": "cert", | ||
"days_until_expire": 0, | ||
"notes": None | ||
} | ||
]) | ||
|
||
@mock.patch('SoftLayer.CLI.formatting.no_going_back') | ||
def test_remove_certficate(self, confirm_mock): | ||
confirm_mock.return_value = True | ||
result = self.run_command(['security', 'cert-remove', '123456']) | ||
self.assert_no_fail(result) | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
def test_download_certficate(self): | ||
result = self.run_command(['security', 'cert-download', '123456']) | ||
self.assert_no_fail(result) | ||
self.assertEqual(result.exit_code, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.