Repository: softlayer/softlayer-python
Pull request #926 (2018-01-15 21:30:08)

Improve error handling when adding SSH keys
Fixes the messaging confusion shown in #925 when a new SSH key is added from the CLI.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 10a25a02..faed08f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,35 +1,7 @@
 # Change Log
 
-
-## [5.4.0] - 2018-01-15
- - Changes: https://github.com/softlayer/softlayer-python/compare/v5.3.2...master
-
- - Upgraded Requests and Urllib3 library to latest. This allows the library to make use of connection retries, and connection pools. This should prevent the client from crashing if the API gives a connection reset / connection timeout error
- - reworked wait_for_ready function for virtual, and added to hardware managers. 
- - fixed block/file iops in the `slcli block|file detail` view
- - Added sub items to `hw detail --price`, removed reverse PTR entries
-
-### Added to CLI
-- slcli order
-```
-$ ./slcli order
-Usage: slcli order [OPTIONS] COMMAND [ARGS]...
-
-Options:
-  -h, --help  Show this message and exit.
-
-Commands:
-  category-list      List the categories of a package.
-  item-list          List package items used for ordering.
-  package-list       List packages that can be ordered via the...
-  package-locations  List Datacenters a package can be ordered in.
-  place              Place or verify an order.
-  preset-list        List package presets.
-```
-
-
 ## [5.3.2] - 2017-12-18
- - Changes: https://github.com/softlayer/softlayer-python/compare/v5.3.1...v5.3.2
+ - Changes: https://github.com/softlayer/softlayer-python/compare/v5.3.1...master
 
  - Expanded `@retry` useage to a few areas in the hardware manager
  - Added INTERVAL options to block and file replication
diff --git a/README.rst b/README.rst
index 9d53e9f3..e703c4b4 100644
--- a/README.rst
+++ b/README.rst
@@ -31,8 +31,6 @@ Additional API documentation can be found on the SoftLayer Development Network:
   <http://developer.softlayer.com/reference/softlayerapi>`_
 * `Object mask information and examples
   <http://developer.softlayer.com/article/Object-Masks>`_
-* `Code Examples
-  <https://softlayer.github.io/python/>`_
 
 Installation
 ------------
@@ -57,12 +55,6 @@ InsecurePlatformWarning Notice
 ------------------------------
 This library relies on the `requests <http://docs.python-requests.org/>`_ library to make HTTP requests. On Python versions below Python 2.7.9, requests has started emitting a security warning (InsecurePlatformWarning) due to insecurities with creating SSL connections. To resolve this, upgrade to Python 2.7.9+ or follow the instructions here: http://stackoverflow.com/a/29099439.
 
-Getting Help
-------------
-Bugs and feature requests about this library should have a `GitHub issue <https://github.com/softlayer/softlayer-python/issues>`_ opened about them. 
-
-Issues with the Softlayer API itself should be addressed by opening a ticket.
-
 System Requirements
 -------------------
 * Python 2.7, 3.3, 3.4, 3.5 or 3.6.
@@ -70,18 +62,9 @@ System Requirements
 * A connection to SoftLayer's private network is required to use
   our private network API endpoints.
 
-Python Packages
----------------
-* six >= 1.7.0
-* prettytable >= 0.7.0
-* click >= 5
-* requests >= 2.18.4
-* prompt_toolkit >= 0.53
-* pygments >= 2.0.0
-* urllib3 >= 1.22
 
 Copyright
 ---------
-This software is Copyright (c) 2016-2018 SoftLayer Technologies, Inc.
+This software is Copyright (c) 2016 SoftLayer Technologies, Inc.
 
 See the bundled LICENSE file for more information.
diff --git a/SoftLayer/CLI/sshkey/add.py b/SoftLayer/CLI/sshkey/add.py
index 49920a07..a3a3c6cc 100644
--- a/SoftLayer/CLI/sshkey/add.py
+++ b/SoftLayer/CLI/sshkey/add.py
@@ -6,6 +6,7 @@
 
 import SoftLayer
 from SoftLayer.CLI import environment
+from SoftLayer.CLI import exceptions
 
 
 @click.command()
@@ -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:
diff --git a/SoftLayer/consts.py b/SoftLayer/consts.py
index ee476835..5e69fe26 100644
--- a/SoftLayer/consts.py
+++ b/SoftLayer/consts.py
@@ -5,7 +5,7 @@
 
     :license: MIT, see LICENSE for more details.
 """
-VERSION = 'v5.4.0'
+VERSION = 'v5.3.2'
 API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3.1/'
 API_PRIVATE_ENDPOINT = 'https://api.service.softlayer.com/xmlrpc/v3.1/'
 API_PUBLIC_ENDPOINT_REST = 'https://api.softlayer.com/rest/v3.1/'
diff --git a/SoftLayer/managers/sshkey.py b/SoftLayer/managers/sshkey.py
index a294d525..8aac6347 100644
--- a/SoftLayer/managers/sshkey.py
+++ b/SoftLayer/managers/sshkey.py
@@ -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 = {
diff --git a/setup.py b/setup.py
index 91955a83..23db6ab6 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@
 
 setup(
     name='SoftLayer',
-    version='5.4.0',
+    version='5.3.2',
     description=DESCRIPTION,
     long_description=LONG_DESCRIPTION,
     author='SoftLayer Technologies, Inc.',
diff --git a/tools/requirements.txt b/tools/requirements.txt
index d28b39b9..4663c430 100644
--- a/tools/requirements.txt
+++ b/tools/requirements.txt
@@ -1,4 +1,4 @@
-requests >= 2.18.4
+requests
 click >= 5
 prettytable >= 0.7.0
 six >= 1.7.0


Test patch:
diff --git a/tests/CLI/modules/sshkey_tests.py b/tests/CLI/modules/sshkey_tests.py
index e0e79b4c..253309c0 100644
--- a/tests/CLI/modules/sshkey_tests.py
+++ b/tests/CLI/modules/sshkey_tests.py
@@ -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']
diff --git a/tools/test-requirements.txt b/tools/test-requirements.txt
index c9a94de2..fc3f7571 100644
--- a/tools/test-requirements.txt
+++ b/tools/test-requirements.txt
@@ -5,4 +5,3 @@ mock
 sphinx
 testtools
 urllib3
-requests >= 2.18.4