Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alertaclient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def create_user(self, name, email, password, status, roles=None, attributes=None
r = self.http.post('/user', data)
return User.parse(r['user'])

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

def get_user_groups(self, id):
Expand Down
31 changes: 19 additions & 12 deletions alertaclient/commands/cmd_user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys

import click
from tabulate import tabulate


class CommandWithOptionalPassword(click.Command):
Expand Down Expand Up @@ -30,23 +31,29 @@ def parse_args(self, ctx, args):
@click.option('--delete', '-D', metavar='UUID', help='Delete user using ID')
@click.pass_obj
def cli(obj, id, name, email, password, status, roles, text, email_verified, delete):
"""Create user or update user details, including password reset."""
"""Create user, show or update user details, including password reset."""
client = obj['client']
if delete:
client.delete_user(delete)
elif id:
if not any([name, email, password, status, roles, text, (email_verified is not None)]):
click.echo('Nothing to update.')
sys.exit(1)
try:
user = client.update_user(
id, name=name, email=email, password=password, status=status,
roles=roles, attributes=None, text=text, email_verified=email_verified
)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
sys.exit(1)
click.echo(user.id)
user = client.get_user(id)
timezone = obj['timezone']
headers = {'id': 'ID', 'name': 'USER', 'email': 'EMAIL', 'roles': 'ROLES', 'status': 'STATUS',
'text': 'TEXT',
'createTime': 'CREATED', 'updateTime': 'LAST UPDATED', 'lastLogin': 'LAST LOGIN',
'email_verified': 'VERIFIED'}
click.echo(tabulate([user.tabular(timezone)], headers=headers, tablefmt=obj['output']))
else:
try:
user = client.update_user(
id, name=name, email=email, password=password, status=status,
roles=roles, attributes=None, text=text, email_verified=email_verified
)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
sys.exit(1)
click.echo(user.id)
else:
if not email:
raise click.UsageError('Need "--email" to create user.')
Expand Down