Skip to content

Commit 78562c7

Browse files
authored
feat: show user details (#255)
1 parent eda0756 commit 78562c7

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

alertaclient/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def create_user(self, name, email, password, status, roles=None, attributes=None
354354
r = self.http.post('/user', data)
355355
return User.parse(r['user'])
356356

357-
def get_user(self):
357+
def get_user(self, id):
358358
return User.parse(self.http.get('/user/%s' % id)['user'])
359359

360360
def get_user_groups(self, id):

alertaclient/commands/cmd_user.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22

33
import click
4+
from tabulate import tabulate
45

56

67
class CommandWithOptionalPassword(click.Command):
@@ -30,23 +31,29 @@ def parse_args(self, ctx, args):
3031
@click.option('--delete', '-D', metavar='UUID', help='Delete user using ID')
3132
@click.pass_obj
3233
def cli(obj, id, name, email, password, status, roles, text, email_verified, delete):
33-
"""Create user or update user details, including password reset."""
34+
"""Create user, show or update user details, including password reset."""
3435
client = obj['client']
3536
if delete:
3637
client.delete_user(delete)
3738
elif id:
3839
if not any([name, email, password, status, roles, text, (email_verified is not None)]):
39-
click.echo('Nothing to update.')
40-
sys.exit(1)
41-
try:
42-
user = client.update_user(
43-
id, name=name, email=email, password=password, status=status,
44-
roles=roles, attributes=None, text=text, email_verified=email_verified
45-
)
46-
except Exception as e:
47-
click.echo('ERROR: {}'.format(e), err=True)
48-
sys.exit(1)
49-
click.echo(user.id)
40+
user = client.get_user(id)
41+
timezone = obj['timezone']
42+
headers = {'id': 'ID', 'name': 'USER', 'email': 'EMAIL', 'roles': 'ROLES', 'status': 'STATUS',
43+
'text': 'TEXT',
44+
'createTime': 'CREATED', 'updateTime': 'LAST UPDATED', 'lastLogin': 'LAST LOGIN',
45+
'email_verified': 'VERIFIED'}
46+
click.echo(tabulate([user.tabular(timezone)], headers=headers, tablefmt=obj['output']))
47+
else:
48+
try:
49+
user = client.update_user(
50+
id, name=name, email=email, password=password, status=status,
51+
roles=roles, attributes=None, text=text, email_verified=email_verified
52+
)
53+
except Exception as e:
54+
click.echo('ERROR: {}'.format(e), err=True)
55+
sys.exit(1)
56+
click.echo(user.id)
5057
else:
5158
if not email:
5259
raise click.UsageError('Need "--email" to create user.')

0 commit comments

Comments
 (0)