Skip to content

Commit 14cbcb4

Browse files
authored
Merge pull request #114 from britive/develop
v1.6.0rc4
2 parents 4391f7a + 8b9f194 commit 14cbcb4

File tree

8 files changed

+89
-17
lines changed

8 files changed

+89
-17
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
* As of v1.4.0 release candidates will be published in an effort to get new features out faster while still allowing time for full QA testing before moving the release candidate to a full release.
44

5+
## v1.6.0rc4 [2023-11-03]
6+
#### What's New
7+
* None
8+
9+
#### Enhancements
10+
* For command `ls profiles -c` show the time remaining for the checkout
11+
* Add new flag `-e/--extend` to command `checkout` which will extend the expiration time of a currently checked out profile (only applicable to specific application types)
12+
13+
#### Bug Fixes
14+
* Fix bug in `configure import` related to the default AWS checkout mode
15+
16+
#### Dependencies
17+
* None
18+
19+
#### Other
20+
* None
21+
522
## v1.6.0rc3 [2023-10-31]
623
#### What's New
724
* None

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
boto3
2-
britive>=2.22.0
2+
britive==2.23.0rc1
33
certifi>=2022.12.7
44
charset-normalizer==2.1.0
55
click~=8.1.3

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pybritive
3-
version = 1.6.0rc3
3+
version = 1.6.0rc4
44
author = Britive Inc.
55
author_email = support@britive.com
66
description = A pure Python CLI for Britive
@@ -27,7 +27,7 @@ install_requires =
2727
toml
2828
cryptography>=41.0.0
2929
python-dateutil
30-
britive>=2.22.0
30+
britive==2.23.0rc1
3131
jmespath
3232
pyjwt
3333

src/pybritive/britive_cli.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,26 +262,50 @@ def list_profiles(self, checked_out: bool = False):
262262
self.login()
263263
self._set_available_profiles()
264264
data = []
265-
checked_out_profiles = [
266-
f'{p["papId"]}-{p["environmentId"]}'
267-
for p in self.b.my_access.list_checked_out_profiles()
268-
] if checked_out else []
265+
checked_out_profiles = {}
266+
if checked_out: # only make this call if we have to
267+
now = datetime.utcnow()
268+
for p in self.b.my_access.list_checked_out_profiles():
269+
expiration_str = p['expiration']
270+
expiration_timestamp = datetime.fromisoformat(expiration_str.replace('Z', ''))
271+
seconds_until_expiration = int((expiration_timestamp - now).total_seconds())
272+
key = f'{p["papId"]}-{p["environmentId"]}'
273+
checked_out_profiles[key] = {
274+
'expiration': expiration_str,
275+
'expires_in_seconds': seconds_until_expiration
276+
}
269277

270278
for profile in self.available_profiles:
271-
if not checked_out or f'{profile["profile_id"]}-{profile["env_id"]}' in checked_out_profiles:
279+
key = f'{profile["profile_id"]}-{profile["env_id"]}'
280+
profile_is_checked_out = key in checked_out_profiles
281+
if not checked_out or profile_is_checked_out:
272282
row = {
273283
'Application': profile['app_name'],
274284
'Environment': profile['env_name'],
275285
'Profile': profile['profile_name'],
276286
'Description': profile['profile_description'],
277287
'Type': profile['app_type']
278288
}
289+
290+
if profile_is_checked_out:
291+
row['Expiration'] = checked_out_profiles[key]['expiration']
292+
total_seconds = checked_out_profiles[key]['expires_in_seconds']
293+
294+
hours, remainder = divmod(total_seconds, 3600)
295+
minutes, seconds = divmod(remainder, 60)
296+
time_format = '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds)
297+
row['TimeRemaining'] = time_format
298+
row['TimeRemainingSeconds'] = total_seconds
299+
279300
if self.output_format == 'list':
280301
self.list_separator = '/'
281-
row.pop('Description')
282-
row.pop('Type')
302+
row.pop('Description', None)
303+
row.pop('Type', None)
304+
row.pop('TimeRemaining', None)
305+
row.pop('TimeRemainingSeconds', None)
306+
row.pop('Expiration', None)
283307
if profile['2_part_profile_format_allowed']:
284-
row.pop('Environment')
308+
row.pop('Environment', None)
285309
data.append(row)
286310

287311
# set special list output if needed
@@ -545,8 +569,24 @@ def _split_profile_into_parts(self, profile):
545569
}
546570
return parts_dict
547571

572+
def _extend_checkout(self, profile, console):
573+
self.login()
574+
parts = self._split_profile_into_parts(profile)
575+
response = self.b.my_access.extend_checkout_by_name(
576+
profile_name=parts['profile'],
577+
environment_name=parts['env'],
578+
application_name=parts['app'],
579+
programmatic=not console
580+
)
581+
548582
def checkout(self, alias, blocktime, console, justification, mode, maxpolltime, profile, passphrase,
549-
force_renew, aws_credentials_file, gcloud_key_file, verbose):
583+
force_renew, aws_credentials_file, gcloud_key_file, verbose, extend):
584+
585+
# handle this special use case and quit
586+
if extend:
587+
self._extend_checkout(profile, console)
588+
return
589+
550590
credentials = None
551591
app_type = None
552592
cached_credentials_found = False

src/pybritive/commands/checkout.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
@click.command()
88
@build_britive
99
@britive_options(names='alias,blocktime,console,justification,mode,maxpolltime,silent,force_renew,aws_credentials_file,'
10-
'gcloud_key_file,verbose,tenant,token,passphrase,federation_provider')
10+
'gcloud_key_file,verbose,extend,tenant,token,passphrase,federation_provider')
1111
@click_smart_profile_argument
1212
def checkout(ctx, alias, blocktime, console, justification, mode, maxpolltime, silent, force_renew,
13-
aws_credentials_file, gcloud_key_file, verbose, tenant, token, passphrase, federation_provider, profile):
13+
aws_credentials_file, gcloud_key_file, verbose, extend, tenant, token, passphrase, federation_provider,
14+
profile):
1415
"""Checkout a profile.
1516
1617
This command takes 1 required argument `PROFILE`. This should be a string representation of the profile
@@ -30,5 +31,6 @@ def checkout(ctx, alias, blocktime, console, justification, mode, maxpolltime, s
3031
force_renew=force_renew,
3132
aws_credentials_file=aws_credentials_file,
3233
gcloud_key_file=gcloud_key_file,
33-
verbose=verbose
34+
verbose=verbose,
35+
extend=extend
3436
)

src/pybritive/helpers/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ def import_global_npm_config(self):
228228
if aws_section:
229229
checkout_mode = aws_section.get('checkoutMode')
230230
if checkout_mode:
231+
checkout_mode = checkout_mode.lower().replace('display', '')
231232
self.cli.print(f'Found aws default checkout mode of {checkout_mode}.')
232-
self.config['aws'] = {'default_checkout_mode': checkout_mode.lower()}
233+
self.config['aws'] = {'default_checkout_mode': checkout_mode}
233234

234235
self.save()
235236
self.load(force=True)

src/pybritive/options/britive_options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ..options.aws_profile import option as aws_profile
3232
from ..options.aws_console_duration import option as aws_console_duration
3333
from ..options.browser import option as browser
34+
from ..options.extend import option as extend
3435

3536
options_map = {
3637
'tenant': tenant,
@@ -65,7 +66,8 @@
6566
'ssh_key_source': ssh_key_source,
6667
'aws_profile': aws_profile,
6768
'aws_console_duration': aws_console_duration,
68-
'browser': browser
69+
'browser': browser,
70+
'extend': extend
6971
}
7072

7173

src/pybritive/options/extend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import click
2+
3+
4+
option = click.option(
5+
'--extend', '-e',
6+
default=False,
7+
is_flag=True,
8+
show_default=True,
9+
help='Extend the expiration time for a currently checked out profile.'
10+
)

0 commit comments

Comments
 (0)