Skip to content

Commit 24771a7

Browse files
caberoscaberos
authored andcommitted
add user remove-access command
1 parent 963fe01 commit 24771a7

File tree

7 files changed

+100
-0
lines changed

7 files changed

+100
-0
lines changed

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@
364364
('user:delete', 'SoftLayer.CLI.user.delete:cli'),
365365
('user:vpn-manual', 'SoftLayer.CLI.user.vpn_manual:cli'),
366366
('user:vpn-subnet', 'SoftLayer.CLI.user.vpn_subnet:cli'),
367+
('user:remove-access', 'SoftLayer.CLI.user.remove_access:cli'),
367368

368369
('vlan', 'SoftLayer.CLI.vlan'),
369370
('vlan:create', 'SoftLayer.CLI.vlan.create:cli'),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""User remove access to devices."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
9+
10+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
11+
@click.argument('identifier')
12+
@click.option('--hardware', '-h',
13+
help="Display hardware this user has access to.")
14+
@click.option('--virtual', '-v',
15+
help="Display virtual guests this user has access to.")
16+
@click.option('--dedicated', '-l',
17+
help="dedicated host ID ")
18+
@environment.pass_env
19+
def cli(env, identifier, hardware, virtual, dedicated):
20+
"""User details."""
21+
22+
mgr = SoftLayer.UserManager(env.client)
23+
device = ''
24+
result = False
25+
if hardware:
26+
device = hardware
27+
result = mgr.remove_hardware_access(identifier, hardware)
28+
29+
if virtual:
30+
device = virtual
31+
result = mgr.remove_virtual_access(identifier, virtual)
32+
33+
if dedicated:
34+
device = dedicated
35+
result = mgr.remove_dedicated_access(identifier, dedicated)
36+
37+
if result:
38+
click.secho("Remove to access to device: %s" % device, fg='green')

SoftLayer/fixtures/SoftLayer_User_Customer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@
8686
editObject = True
8787
addApiAuthenticationKey = True
8888
updateVpnUser = True
89+
removeDedicatedHostAccess = True
90+
removeHardwareAccess = True
91+
removeVirtualGuestAccess = True

SoftLayer/managers/user.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,36 @@ def get_overrides_list(self, user_id, subnet_ids):
392392

393393
return overrides_list
394394

395+
def remove_hardware_access(self, user_id, hardware_id):
396+
"""Remove hardware from a portal user’s hardware access list.
397+
398+
:param int user_id:
399+
:param int hardware_id
400+
401+
:returns: true
402+
"""
403+
return self.user_service.removeHardwareAccess(hardware_id, id=user_id)
404+
405+
def remove_virtual_access(self, user_id, virtual_id):
406+
"""Remove hardware from a portal user’s virtual guests access list.
407+
408+
:param int user_id:
409+
:param int hardware_id
410+
411+
:returns: true
412+
"""
413+
return self.user_service.removeVirtualGuestAccess(virtual_id, id=user_id)
414+
415+
def remove_dedicated_access(self, user_id, dedicated_id):
416+
"""Remove hardware from a portal user’s dedicated host access list.
417+
418+
:param int user_id:
419+
:param int dedicated_id
420+
421+
:returns: true
422+
"""
423+
return self.user_service.removeDedicatedHostAccess(dedicated_id, id=user_id)
424+
395425

396426
def _keyname_search(haystack, needle):
397427
for item in haystack:

docs/cli/users.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ Version 5.6.0 introduces the ability to interact with user accounts from the cli
4848
:prog: user vpn-subnet
4949
:show-nested:
5050

51+
.. click:: SoftLayer.CLI.user.remove_access:cli
52+
:prog: user remove-access
53+
:show-nested:
54+
5155

tests/CLI/modules/user_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,15 @@ def test_edit_notification_off_failure(self, click):
336336
click.secho.assert_called_with('Failed to update notifications: Test notification', fg='red')
337337
self.assert_no_fail(result)
338338
self.assert_called_with('SoftLayer_Email_Subscription', 'disable', identifier=111)
339+
340+
def test_remove_access_hardware(self):
341+
result = self.run_command(['user', 'remove-access', '123456', '--hardware', '147258'])
342+
self.assert_no_fail(result)
343+
344+
def test_remove_access_virtual(self):
345+
result = self.run_command(['user', 'remove-access', '123456', '--virtual', '987456'])
346+
self.assert_no_fail(result)
347+
348+
def test_remove_access_dedicated(self):
349+
result = self.run_command(['user', 'remove-access', '123456', '--dedicated', '369852'])
350+
self.assert_no_fail(result)

tests/managers/user_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,15 @@ def test_gather_notifications_fail(self):
294294
self.manager.gather_notifications,
295295
['Test not exit'])
296296
self.assertEqual("Test not exit is not a valid notification name", str(ex))
297+
298+
def test_remove_hardware(self):
299+
self.manager.remove_hardware_access(123456, 369852)
300+
self.assert_called_with('SoftLayer_User_Customer', 'removeHardwareAccess')
301+
302+
def test_remove_virtual(self):
303+
self.manager.remove_virtual_access(123456, 369852)
304+
self.assert_called_with('SoftLayer_User_Customer', 'removeVirtualGuestAccess')
305+
306+
def test_remove_dedicated(self):
307+
self.manager.remove_dedicated_access(123456, 369852)
308+
self.assert_called_with('SoftLayer_User_Customer', 'removeDedicatedHostAccess')

0 commit comments

Comments
 (0)