Skip to content

Commit 9b92ece

Browse files
edit user
1 parent 4f7670b commit 9b92ece

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

SoftLayer/CLI/routes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@
290290
('user:edit-details', 'SoftLayer.CLI.user.edit-details:cli'),
291291
('user:create', 'SoftLayer.CLI.user.create:cli'),
292292

293-
294293
('vlan', 'SoftLayer.CLI.vlan'),
295294
('vlan:detail', 'SoftLayer.CLI.vlan.detail:cli'),
296295
('vlan:list', 'SoftLayer.CLI.vlan.list:cli'),

SoftLayer/CLI/user/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
def cli(env, username, email, password, from_user, template, api_key):
3535
"""Creates a user Users.
3636
37-
slcli user create my@email.com -e my@email.com -p generate -a -t '{"firstName": "Test", "lastName": "Testerson"}'
37+
:Example: slcli user create my@email.com -e my@email.com -p generate -a -t '{"firstName": "Test", "lastName": "Testerson"}'
3838
Remember to set the permissions and access for this new user.
3939
"""
4040

SoftLayer/CLI/user/edit-details.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,39 @@
22
# :license: MIT, see LICENSE for more details.
33

44
import click
5+
import json
56

67
import SoftLayer
7-
from SoftLayer.CLI import columns as column_helper
88
from SoftLayer.CLI import environment
9-
from SoftLayer.CLI import formatting
10-
11-
12-
COLUMNS = [
13-
column_helper.Column('id', ('id',)),
14-
column_helper.Column('username', ('username',)),
15-
column_helper.Column('email', ('email',)),
16-
column_helper.Column('displayName', ('displayName',)),
17-
column_helper.Column('status', ('userStatus', 'name')),
18-
column_helper.Column('hardwareCount', ('hardwareCount',)),
19-
column_helper.Column('virtualGuestCount', ('virtualGuestCount',))
20-
]
21-
22-
DEFAULT_COLUMNS = [
23-
'id',
24-
'username',
25-
'email',
26-
'displayName'
27-
]
9+
from SoftLayer.CLI import helpers
2810

2911

3012
@click.command()
31-
@click.option('--columns',
32-
callback=column_helper.get_formatter(COLUMNS),
33-
help='Columns to display. [options: %s]' % ', '.join(column.name for column in COLUMNS),
34-
default=','.join(DEFAULT_COLUMNS),
35-
show_default=True)
13+
@click.argument('user')
14+
@click.option('--template', '-t', required=True,
15+
help="A json string describing https://softlayer.github.io/reference/datatypes/SoftLayer_User_Customer/")
3616
@environment.pass_env
37-
def cli(env, columns):
38-
"""List Users."""
17+
def cli(env, user, template):
18+
"""Edit a Users details
3919
40-
mgr = SoftLayer.UserManager(env.client)
41-
users = mgr.list_users()
42-
43-
table = formatting.Table(columns.columns)
44-
for user in users:
45-
table.add_row([value or formatting.blank()
46-
for value in columns.row(user)])
20+
JSON strings should be enclosed in '' and each item should be enclosed in ""
4721
48-
env.fout(table)
22+
:Example: slcli user edit-details testUser -t '{"firstName": "Test", "lastName": "Testerson"}'
23+
."""
24+
mgr = SoftLayer.UserManager(env.client)
25+
user_id = helpers.resolve_id(mgr.resolve_ids, user, 'username')
26+
27+
user_template = {}
28+
if template is not None:
29+
try:
30+
template_object = json.loads(template)
31+
for key in template_object:
32+
user_template[key] = template_object[key]
33+
except json.decoder.JSONDecodeError as ex:
34+
raise exceptions.ArgumentError("Unable to parse --template. %s" % ex.msg)
35+
36+
result = mgr.edit_user(user_id, user_template)
37+
if result:
38+
click.secho("%s updated successfully" % (user), fg='green')
39+
else:
40+
click.secho("Failed to update %s" % (user), fg='red')

SoftLayer/managers/user.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ def create_user(self, user_object, password):
245245
LOGGER.warning("Creating User %s", user_object['username'])
246246
return self.user_service.createObject(user_object, password, None)
247247

248+
def edit_user(self, user_id, user_object):
249+
"""Blindly sends user_object to SoftLayer_User_Customer::editObject
250+
251+
:param int user_id: User to edit
252+
:param dictionary user_object: https://softlayer.github.io/reference/datatypes/SoftLayer_User_Customer/
253+
"""
254+
return self.user_service.editObject(user_object, id=user_id)
255+
248256
def addApiAuthenticationKey(self, user_id):
249257
return self.user_service.addApiAuthenticationKey(id=user_id)
250258

0 commit comments

Comments
 (0)