diff --git a/alertaclient/commands/cmd_alerts.py b/alertaclient/commands/cmd_alerts.py index dc5c990..7041b2b 100644 --- a/alertaclient/commands/cmd_alerts.py +++ b/alertaclient/commands/cmd_alerts.py @@ -4,7 +4,7 @@ from tabulate import tabulate -@click.command('alerts', short_help='List alert environments, services, groups and tags') +@click.command('alerts', short_help='List environments, services, groups and tags') @click.option('--environments', '-E', is_flag=True, help='List alert environments.') @click.option('--services', '-S', is_flag=True, help='List alert services.') @click.option('--groups', '-g', is_flag=True, help='List alert groups.') diff --git a/alertaclient/commands/cmd_blackout.py b/alertaclient/commands/cmd_blackout.py index c51ed06..2810efc 100644 --- a/alertaclient/commands/cmd_blackout.py +++ b/alertaclient/commands/cmd_blackout.py @@ -15,7 +15,7 @@ @click.option('--start', metavar='DATETIME', help='Start time in ISO8601 eg. 2018-02-01T12:00:00.000Z') @click.option('--duration', metavar='SECONDS', type=int, help='Blackout period in seconds') @click.option('--text', help='Reason for blackout') -@click.option('--delete', '-D', help='Delete blackout using ID') +@click.option('--delete', '-D', metavar='ID', help='Delete blackout using ID') @click.pass_obj def cli(obj, environment, service, resource, event, group, tags, origin, customer, start, duration, text, delete): """Suppress alerts for specified duration based on alert attributes.""" diff --git a/alertaclient/commands/cmd_scopes.py b/alertaclient/commands/cmd_scopes.py new file mode 100644 index 0000000..280d3f3 --- /dev/null +++ b/alertaclient/commands/cmd_scopes.py @@ -0,0 +1,18 @@ +import json + +import click +from tabulate import tabulate + + +@click.command('scopes', short_help='List scopes') +@click.pass_obj +def cli(obj): + """List scopes.""" + client = obj['client'] + + if obj['output'] == 'json': + r = client.http.get('/scopes') + click.echo(json.dumps(r['scopes'], sort_keys=True, indent=4, ensure_ascii=False)) + else: + headers = {'scope': 'SCOPE'} + click.echo(tabulate([s.tabular() for s in client.get_scopes()], headers=headers, tablefmt=obj['output'])) diff --git a/alertaclient/commands/cmd_user.py b/alertaclient/commands/cmd_user.py index 96a862d..34c391c 100644 --- a/alertaclient/commands/cmd_user.py +++ b/alertaclient/commands/cmd_user.py @@ -28,7 +28,7 @@ def parse_args(self, ctx, args): @click.option('--role', 'roles', multiple=True, help='List of roles') @click.option('--text', help='Description of user') @click.option('--email-verified/--email-not-verified', default=None, help='Email address verified flag') -@click.option('--delete', '-D', metavar='UUID', help='Delete user using ID') +@click.option('--delete', '-D', metavar='ID', help='Delete user using ID') @click.pass_obj def cli(obj, id, name, email, password, status, roles, text, email_verified, delete): """Create user, show or update user details, including password reset.""" diff --git a/alertaclient/models/enums.py b/alertaclient/models/enums.py index bb7b596..46eb45c 100644 --- a/alertaclient/models/enums.py +++ b/alertaclient/models/enums.py @@ -1,13 +1,14 @@ from enum import Enum -class Scope(str, Enum): +class Scope(str): read = 'read' write = 'write' admin = 'admin' read_alerts = 'read:alerts' write_alerts = 'write:alerts' + delete_alerts = 'delete:alerts' admin_alerts = 'admin:alerts' read_blackouts = 'read:blackouts' write_blackouts = 'write:blackouts' @@ -58,6 +59,11 @@ def from_str(action: str, resource: str = None): else: return Scope(action) + def tabular(self): + return { + 'scope': self + } + ADMIN_SCOPES = [Scope.admin, Scope.read, Scope.write]