Skip to content

Commit 1c0bda6

Browse files
authored
fix: add scopes cmd and minor fixes (#257)
1 parent 273d862 commit 1c0bda6

5 files changed

Lines changed: 28 additions & 4 deletions

File tree

alertaclient/commands/cmd_alerts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tabulate import tabulate
55

66

7-
@click.command('alerts', short_help='List alert environments, services, groups and tags')
7+
@click.command('alerts', short_help='List environments, services, groups and tags')
88
@click.option('--environments', '-E', is_flag=True, help='List alert environments.')
99
@click.option('--services', '-S', is_flag=True, help='List alert services.')
1010
@click.option('--groups', '-g', is_flag=True, help='List alert groups.')

alertaclient/commands/cmd_blackout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@click.option('--start', metavar='DATETIME', help='Start time in ISO8601 eg. 2018-02-01T12:00:00.000Z')
1616
@click.option('--duration', metavar='SECONDS', type=int, help='Blackout period in seconds')
1717
@click.option('--text', help='Reason for blackout')
18-
@click.option('--delete', '-D', help='Delete blackout using ID')
18+
@click.option('--delete', '-D', metavar='ID', help='Delete blackout using ID')
1919
@click.pass_obj
2020
def cli(obj, environment, service, resource, event, group, tags, origin, customer, start, duration, text, delete):
2121
"""Suppress alerts for specified duration based on alert attributes."""
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import json
2+
3+
import click
4+
from tabulate import tabulate
5+
6+
7+
@click.command('scopes', short_help='List scopes')
8+
@click.pass_obj
9+
def cli(obj):
10+
"""List scopes."""
11+
client = obj['client']
12+
13+
if obj['output'] == 'json':
14+
r = client.http.get('/scopes')
15+
click.echo(json.dumps(r['scopes'], sort_keys=True, indent=4, ensure_ascii=False))
16+
else:
17+
headers = {'scope': 'SCOPE'}
18+
click.echo(tabulate([s.tabular() for s in client.get_scopes()], headers=headers, tablefmt=obj['output']))

alertaclient/commands/cmd_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def parse_args(self, ctx, args):
2828
@click.option('--role', 'roles', multiple=True, help='List of roles')
2929
@click.option('--text', help='Description of user')
3030
@click.option('--email-verified/--email-not-verified', default=None, help='Email address verified flag')
31-
@click.option('--delete', '-D', metavar='UUID', help='Delete user using ID')
31+
@click.option('--delete', '-D', metavar='ID', help='Delete user using ID')
3232
@click.pass_obj
3333
def cli(obj, id, name, email, password, status, roles, text, email_verified, delete):
3434
"""Create user, show or update user details, including password reset."""

alertaclient/models/enums.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from enum import Enum
22

33

4-
class Scope(str, Enum):
4+
class Scope(str):
55

66
read = 'read'
77
write = 'write'
88
admin = 'admin'
99
read_alerts = 'read:alerts'
1010
write_alerts = 'write:alerts'
11+
delete_alerts = 'delete:alerts'
1112
admin_alerts = 'admin:alerts'
1213
read_blackouts = 'read:blackouts'
1314
write_blackouts = 'write:blackouts'
@@ -58,6 +59,11 @@ def from_str(action: str, resource: str = None):
5859
else:
5960
return Scope(action)
6061

62+
def tabular(self):
63+
return {
64+
'scope': self
65+
}
66+
6167

6268
ADMIN_SCOPES = [Scope.admin, Scope.read, Scope.write]
6369

0 commit comments

Comments
 (0)