Skip to content

Commit 40437dc

Browse files
Merge pull request #1824 from BrianSantivanez/issue1823
`user remove-access` is not displaying all removed device access and its help command displaying error message
2 parents 16d877a + 044c973 commit 40437dc

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
1-
"""User remove access to devices."""
1+
"""Removes a user access to a given device."""
22
# :license: MIT, see LICENSE for more details.
33

44
import click
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import exceptions
89

910

1011
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1112
@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 ")
13+
@click.option('--hardware', help="Hardware ID")
14+
@click.option('--virtual', help="Virtual Guest ID")
15+
@click.option('--dedicated', help="Dedicated host ID ")
1816
@environment.pass_env
1917
def cli(env, identifier, hardware, virtual, dedicated):
20-
"""Remove access from a user to an specific device.
18+
"""Removes a user access to a given device.
2119
2220
Example: slcli user remove-access 123456 --hardware 123456789
2321
"""
2422

2523
mgr = SoftLayer.UserManager(env.client)
26-
device = ''
2724
result = False
2825
if hardware:
29-
device = hardware
3026
result = mgr.remove_hardware_access(identifier, hardware)
27+
if result:
28+
click.secho(f"Removed access to hardware: {hardware}.", fg='green')
3129

3230
if virtual:
33-
device = virtual
3431
result = mgr.remove_virtual_access(identifier, virtual)
32+
if result:
33+
click.secho(f"Removed access to virtual guest: {virtual}", fg='green')
3534

3635
if dedicated:
37-
device = dedicated
3836
result = mgr.remove_dedicated_access(identifier, dedicated)
39-
40-
if result:
41-
click.secho("Remove to access to device: %s" % device, fg='green')
42-
else:
43-
raise SoftLayer.exceptions.SoftLayerError('You need argument a hardware, virtual or dedicated identifier.\n'
44-
'E.g slcli user 123456 --hardware 91803794\n'
45-
' slcli user 123456 --dedicated 91803793\n'
46-
' slcli user 123456 --virtual 91803792')
37+
if result:
38+
click.secho(f"Removed access to dedicated host: {dedicated}", fg='green')
39+
40+
if not result:
41+
raise exceptions.CLIAbort('A device option is required.\n'
42+
'E.g slcli user remove-access 123456 --hardware 91803794\n'
43+
' slcli user remove-access 123456 --dedicated 91803793\n'
44+
' slcli user remove-access 123456 --virtual 91803792')

tests/CLI/modules/user_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,8 @@ def test_remove_access_virtual(self):
373373
def test_remove_access_dedicated(self):
374374
result = self.run_command(['user', 'remove-access', '123456', '--dedicated', '369852'])
375375
self.assert_no_fail(result)
376+
377+
def test_remove_without_device(self):
378+
result = self.run_command(['user', 'remove-access', '123456'])
379+
self.assertEqual(2, result.exit_code)
380+
self.assertIn('A device option is required.', result.exception.message)

0 commit comments

Comments
 (0)