Skip to content

Commit 230f4ba

Browse files
author
Brian Flores
committed
fix observations
1 parent ee3b0dc commit 230f4ba

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

SoftLayer/CLI/user/apikey.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,10 @@ def cli(env, identifier, add, remove, refresh):
3838
mgr = SoftLayer.UserManager(env.client)
3939
user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username')
4040

41-
if add:
41+
if remove or refresh:
42+
mgr.remove_api_authentication_key(user_id)
43+
click.secho('Successfully removed API authentication key', fg='green')
44+
45+
if add or refresh:
4246
api_authentication_key = mgr.add_api_authentication_key(user_id)
4347
click.secho(f'Successfully added. New API Authentication Key: {api_authentication_key}', fg='green')
44-
else:
45-
api_authentication_keys = mgr.get_api_authentication_keys(user_id)
46-
if len(api_authentication_keys) == 0:
47-
raise exceptions.CLIAbort('The user has not API authentication keys')
48-
49-
mgr.remove_api_authentication_key(api_authentication_keys[0]['id'])
50-
if remove:
51-
click.secho('Successfully removed API authentication key', fg='green')
52-
else:
53-
api_authentication_key = mgr.add_api_authentication_key(user_id)
54-
click.secho(f'Successfully refreshed. New API Authentication Key: {api_authentication_key}', fg='green')

SoftLayer/managers/user.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,18 @@ def get_api_authentication_keys(self, user_id):
339339
"""
340340
return self.user_service.getApiAuthenticationKeys(id=user_id)
341341

342-
def remove_api_authentication_key(self, api_key_id):
343-
"""Calls SoftLayer_User_Customer::removeApiAuthenticationKey
342+
def remove_api_authentication_key(self, user_id):
343+
"""Calls SoftLayer_User_Customer::getApiAuthenticationKeys and
344344
345-
:param int api_key_id: API key to remove
345+
SoftLayer_User_Customer::removeApiAuthenticationKey
346+
347+
:param int user_id: User to remove API key
346348
"""
347-
return self.user_service.removeApiAuthenticationKey(api_key_id)
349+
api_authentication_keys = self.get_api_authentication_keys(user_id)
350+
if len(api_authentication_keys) == 0:
351+
return True
352+
353+
return self.user_service.removeApiAuthenticationKey(api_authentication_keys[0]['id'])
348354

349355
def vpn_manual(self, user_id, value):
350356
"""Enable or disable the manual config of subnets.

tests/CLI/modules/user_tests.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from unittest import mock as mock
1212

13-
from SoftLayer.fixtures import SoftLayer_User_Customer
1413
from SoftLayer import testing
1514

1615

@@ -407,13 +406,6 @@ def test_remove_api_authentication_key(self):
407406
result = self.run_command(['user', 'apikey', '123456', '--remove'])
408407
self.assert_no_fail(result)
409408

410-
def test_remove_api_authentication_key_does_not_exist(self):
411-
mock = self.set_mock('SoftLayer_User_Customer', 'getApiAuthenticationKeys')
412-
mock.return_value = SoftLayer_User_Customer.getEmptyApiAuthenticationKeys
413-
result = self.run_command(['user', 'apikey', '123456', '--remove'])
414-
self.assertEqual(2, result.exit_code)
415-
self.assertIn('The user has not API authentication keys', result.exception.message)
416-
417409
def test_refresh_api_authentication_key(self):
418410
result = self.run_command(['user', 'apikey', '123456', '--refresh'])
419411
self.assert_no_fail(result)

0 commit comments

Comments
 (0)