Skip to content

Commit c3be2f1

Browse files
committed
request approve, request reject, ls approvals
1 parent 452ba3e commit c3be2f1

4 files changed

Lines changed: 70 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
All changes to the package starting with v0.3.1 will be logged here.
44

5-
## v1.3.1 [2023-04-XX]
5+
## v1.4.0 [2023-04-XX]
66
#### What's New
7-
* None
7+
* Command `request approve`
8+
* Command `request reject`
9+
* Command `ls approvals`
810

911
#### Enhancements
1012
* None
1113

1214
#### Bug Fixes
13-
* Resolved issue with profile alias names which included uppercase and special characters
15+
* Resolved issue with profile alias names which included uppercase and special characters.
16+
* Resolved an issue with `checkout --mode browser-*` that was not actually launching the browser.
1417

1518
#### Dependencies
16-
* None
19+
* `britive>=2.19.0`
1720

1821
#### Other
1922
* None

src/pybritive/britive_cli.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ def list_secrets(self):
205205
self.login()
206206
self.print(self.b.my_secrets.list(), ignore_silent=True)
207207

208+
def list_approvals(self):
209+
self.login()
210+
approvals = []
211+
for approval in self.b.my_access.list_approvals():
212+
approval.pop('resource', None)
213+
approval.pop('consumer', None)
214+
approval.pop('timeToApprove', None)
215+
approval.pop('validFor', None)
216+
approval.pop('action', None)
217+
approval.pop('approvers', None)
218+
approval.pop('expirationTimeApproval', None)
219+
approval.pop('updatedAt', None)
220+
approval.pop('actionBy', None)
221+
approval.pop('validForInDays', None)
222+
approvals.append(approval)
223+
224+
approvals = sorted(approvals, key=lambda x: x['createdAt'])
225+
approvals.reverse()
226+
self.print(approvals, ignore_silent=True)
227+
208228
def list_profiles(self, checked_out: bool = False):
209229
self.login()
210230
self._set_available_profiles()
@@ -1003,4 +1023,10 @@ def aws_console(profile, duration, browser):
10031023
browser = webbrowser.get(using=browser)
10041024
browser.open(console_url)
10051025

1026+
def request_disposition(self, request_id, decision):
1027+
self.login()
10061028

1029+
if decision == 'approve':
1030+
self.b.my_access.approve_request(request_id=request_id)
1031+
if decision == 'reject':
1032+
self.b.my_access.reject_request(request_id=request_id)

src/pybritive/commands/ls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ def secrets(ctx, output_format, tenant, token, silent, passphrase, federation_pr
4141
ctx.obj.britive.list_secrets()
4242

4343

44-
44+
@ls.command()
45+
@build_britive
46+
@britive_options(names='format,tenant,token,silent,passphrase,federation_provider')
47+
def approvals(ctx, output_format, tenant, token, silent, passphrase, federation_provider):
48+
"""List approvals for the currently authenticated identity."""
49+
ctx.obj.britive.list_approvals()

src/pybritive/commands/request.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,34 @@ def withdraw(ctx, tenant, token, silent, passphrase, federation_provider, profil
4747
ctx.obj.britive.request_withdraw(
4848
profile=profile
4949
)
50+
51+
52+
@request.command()
53+
@build_britive
54+
@britive_options(names='tenant,token,silent,passphrase,federation_provider')
55+
@click.argument('request-id')
56+
def approve(ctx, tenant, token, silent, passphrase, federation_provider, request_id):
57+
"""Approve a request to checkout a profile.
58+
59+
This command takes 1 required argument `request-id`. Find the `request-id` via `ls approvals`.
60+
"""
61+
62+
ctx.obj.britive.request_disposition(
63+
request_id=request_id,
64+
decision='approve'
65+
)
66+
67+
@request.command()
68+
@build_britive
69+
@britive_options(names='tenant,token,silent,passphrase,federation_provider')
70+
@click.argument('request-id')
71+
def reject(ctx, tenant, token, silent, passphrase, federation_provider, request_id):
72+
"""Reject a request to checkout a profile.
73+
74+
This command takes 1 required argument `request-id`. Find the `request-id` via `ls approvals`.
75+
"""
76+
77+
ctx.obj.britive.request_disposition(
78+
request_id=request_id,
79+
decision='reject'
80+
)

0 commit comments

Comments
 (0)