Skip to content

Commit b136c52

Browse files
authored
Merge pull request #170 from britive/develop
v1.8.2
2 parents 3365a8b + 98c88d3 commit b136c52

File tree

9 files changed

+124
-86
lines changed

9 files changed

+124
-86
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
* As of v1.4.0 release candidates will be published in an effort to get new features out faster while still allowing
44
time for full QA testing before moving the release candidate to a full release.
55

6+
## v1.8.2 [2024-07-26]
7+
8+
__What's New:__
9+
10+
* None
11+
12+
__Enhancements:__
13+
14+
* None
15+
16+
__Bug Fixes:__
17+
18+
* Fixed a bug where checked out `my-resources` profiles weren't included.
19+
20+
__Dependencies:__
21+
22+
* None
23+
24+
__Other:__
25+
26+
* None
27+
628
## v1.8.1 [2024-07-11]
729

830
__What's New:__

src/pybritive/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.8.1'
1+
__version__ = '1.8.2'

src/pybritive/britive_cli.py

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,7 @@ def list_resources(self):
337337
name = item['resourceName']
338338
if name not in found_resource_names:
339339
resources.append(
340-
{
341-
'resourceId': item['resourceId'],
342-
'resourceName': name,
343-
'resourceLabels': item['resourceLabels']
344-
}
340+
{'resourceId': item['resourceId'], 'resourceName': name, 'resourceLabels': item['resourceLabels']}
345341
)
346342
found_resource_names.append(name)
347343
self.print(resources, ignore_silent=True)
@@ -353,11 +349,16 @@ def list_profiles(self, checked_out: bool = False, profile_type: str = None):
353349
checked_out_profiles = {}
354350
if checked_out: # only make this call if we have to
355351
now = datetime.utcnow()
356-
for p in self.b.my_access.list_checked_out_profiles():
357-
expiration_str = p['expiration']
352+
my_access = not profile_type or profile_type == 'my-access'
353+
my_resources = not profile_type or profile_type == 'my-resources'
354+
list_checked_out = (self.b.my_access.list_checked_out_profiles() if my_access else []) + (
355+
self.b.my_resources.list_checked_out_profiles() if my_resources else []
356+
)
357+
for p in list_checked_out:
358+
expiration_str = p.get('expiration', p.get('expirationDuration'))
358359
expiration_timestamp = datetime.fromisoformat(expiration_str.replace('Z', ''))
359360
seconds_until_expiration = int((expiration_timestamp - now).total_seconds())
360-
key = f'{p["papId"]}-{p["environmentId"]}'
361+
key = f'{p.get("papId", p.get("profileId"))}-{p.get("environmentId", p.get("resourceId"))}'
361362
checked_out_profiles[key] = {
362363
'expiration': expiration_str,
363364
'expires_in_seconds': seconds_until_expiration,
@@ -461,15 +462,15 @@ def _set_available_profiles(self, from_cache_command=False, profile_type: str =
461462
'app_description': app['appDescription'],
462463
'env_name': env['environmentName'],
463464
'env_id': env['environmentId'],
464-
'env_short_name': env['alternateEnvironmentName'],
465+
'env_short_name': env['alternateEnvironmentName'],
465466
'env_description': env['environmentDescription'],
466467
'profile_name': profile['profileName'],
467468
'profile_id': profile['profileId'],
468469
'profile_allows_console': profile['consoleAccess'],
469470
'profile_allows_programmatic': profile['programmaticAccess'],
470471
'profile_description': profile['profileDescription'],
471472
'2_part_profile_format_allowed': app['requiresHierarchicalModel'],
472-
'env_properties': env.get('profileEnvironmentProperties', {})
473+
'env_properties': env.get('profileEnvironmentProperties', {}),
473474
}
474475
data.append(row)
475476
if self.b.feature_flags.get('server-access') and (not profile_type or profile_type == 'my-resources'):
@@ -489,7 +490,7 @@ def _set_available_profiles(self, from_cache_command=False, profile_type: str =
489490
'profile_allows_programmatic': True,
490491
'profile_description': None,
491492
'2_part_profile_format_allowed': False,
492-
'env_properties': item.get('resourceLabels', {})
493+
'env_properties': item.get('resourceLabels', {}),
493494
}
494495
data.append(row)
495496
self.available_profiles = data
@@ -587,20 +588,10 @@ def __get_cloud_credential_printer(
587588
)
588589
if app_type in ['OpenShift']:
589590
return printer.OpenShiftCredentialPrinter(
590-
console=console,
591-
mode=mode,
592-
profile=profile,
593-
credentials=credentials,
594-
silent=silent,
595-
cli=self
591+
console=console, mode=mode, profile=profile, credentials=credentials, silent=silent, cli=self
596592
)
597593
if app_type in ['Resources']:
598-
return printer.ResourcesCredentialPrinter(
599-
profile=profile,
600-
credentials=credentials,
601-
silent=silent,
602-
cli=self
603-
)
594+
return printer.ResourcesCredentialPrinter(profile=profile, credentials=credentials, silent=silent, cli=self)
604595
return printer.GenericCloudCredentialPrinter(
605596
console=console,
606597
mode=mode,
@@ -609,13 +600,11 @@ def __get_cloud_credential_printer(
609600
silent=silent,
610601
cli=self,
611602
)
603+
612604
def _resource_checkin(self, profile):
613605
resource_name, profile_name = self._split_resource_profile_into_parts(profile=profile)
614606
self.login()
615-
self.b.my_resources.checkin_by_name(
616-
profile_name=profile_name,
617-
resource_name=resource_name
618-
)
607+
self.b.my_resources.checkin_by_name(profile_name=profile_name, resource_name=resource_name)
619608

620609
def _access_checkin(self, profile, console):
621610
self.login()
@@ -743,12 +732,25 @@ def _resource_checkout(self, blocktime, justification, maxpolltime, profile):
743732
justification=justification,
744733
wait_time=blocktime,
745734
max_wait_time=maxpolltime,
746-
progress_func=self.checkout_callback_printer # callback will handle silent, isatty, etc.
735+
progress_func=self.checkout_callback_printer, # callback will handle silent, isatty, etc.
747736
)
748737
return response['credentials']
749738

750-
def _access_checkout(self, alias, blocktime, console, justification, otp, mode, maxpolltime, profile, passphrase,
751-
force_renew, verbose, extend):
739+
def _access_checkout(
740+
self,
741+
alias,
742+
blocktime,
743+
console,
744+
justification,
745+
otp,
746+
mode,
747+
maxpolltime,
748+
profile,
749+
passphrase,
750+
force_renew,
751+
verbose,
752+
extend,
753+
):
752754
# handle this special use case and quit
753755
if extend:
754756
self._extend_checkout(profile, console)
@@ -834,16 +836,29 @@ def _access_checkout(self, alias, blocktime, console, justification, otp, mode,
834836
)
835837
return app_type, credentials, k8s_processor
836838

837-
def checkout(self, alias, blocktime, console, justification, otp, mode, maxpolltime, profile, passphrase,
838-
force_renew, aws_credentials_file, gcloud_key_file, verbose, extend, profile_type: str = 'my-access'):
839+
def checkout(
840+
self,
841+
alias,
842+
blocktime,
843+
console,
844+
justification,
845+
otp,
846+
mode,
847+
maxpolltime,
848+
profile,
849+
passphrase,
850+
force_renew,
851+
aws_credentials_file,
852+
gcloud_key_file,
853+
verbose,
854+
extend,
855+
profile_type: str = 'my-access',
856+
):
839857
if self._profile_is_for_resource(profile=profile, profile_type=profile_type):
840858
app_type = 'Resources'
841859
k8s_processor = None
842860
credentials = self._resource_checkout(
843-
blocktime=blocktime,
844-
justification=justification,
845-
maxpolltime=maxpolltime,
846-
profile=profile
861+
blocktime=blocktime, justification=justification, maxpolltime=maxpolltime, profile=profile
847862
)
848863
else:
849864
app_type, credentials, k8s_processor = self._access_checkout(
@@ -858,7 +873,7 @@ def checkout(self, alias, blocktime, console, justification, otp, mode, maxpollt
858873
passphrase=passphrase,
859874
force_renew=force_renew,
860875
verbose=verbose,
861-
extend=extend
876+
extend=extend,
862877
)
863878

864879
# do this down here, so we know that the profile is valid and a checkout was successful
@@ -1139,7 +1154,8 @@ def _convert_names_to_ids(self, profile_name: str, environment_name: str, applic
11391154

11401155
# collect relevant profile/environment combinations to which the identity is entitled
11411156
for profile in self.available_profiles:
1142-
if profile['app_name'] and profile['app_name'].lower() != application_name: # kick out all the unmatched applications
1157+
if profile['app_name'] and profile['app_name'].lower() != application_name:
1158+
# kick out all the unmatched applications
11431159
continue
11441160
if profile['profile_name'].lower() != profile_name: # kick out the unmatched profiles
11451161
continue

src/pybritive/choices/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
backend_choices = click.Choice(
55
[
6+
'encrypted-file',
67
'file',
7-
'encrypted-file'
88
],
99
case_sensitive=False
1010
)

src/pybritive/choices/browser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
[
88
c
99
for c in [
10-
'mozilla',
10+
'chrome',
11+
'chromium',
1112
'firefox',
12-
'windows-default',
1313
'macosx',
14+
'mozilla',
1415
'safari',
15-
'chrome',
16-
'chromium',
16+
'windows-default',
1717
os.getenv('PYBRITIVE_BROWSER'),
1818
]
1919
if c

src/pybritive/choices/mode.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@
44

55
mode_choices = click.Choice(
66
[
7-
'text', # text based output
8-
'json', # json based output
9-
'env', # environment variable output (suitable for eval)
10-
'integrate', # stick the credentials into the local CSP credentials file (AWS)
11-
'env-nix', # environment variable output specifying "export"
12-
'env-wincmd', # environment variable output specifying "set"
13-
'env-winps', # environment variable output specifying "$env:"
147
'awscredentialprocess', # aws credential process output with additional caching to make the credential process more performant
158
'azlogin', # azure az login command with all fields populated (suitable for eval)
169
'azps', # azure powershell script
1710
'browser', # checkout console access (without having to specify --console/-c) and open the default browser to the URL provided in the checkout
18-
'gcloudauth', # gcloud auth activate-service-account with all fields populated (suitable for eval)
19-
'console', # checkout console access (without having to specify --console/-c) and print the URL
20-
'browser-mozilla',
11+
'browser-chrome',
12+
'browser-chromium',
2113
'browser-firefox',
22-
'browser-windows-default',
2314
'browser-macosx',
15+
'browser-mozilla',
2416
'browser-safari',
25-
'browser-chrome',
26-
'browser-chromium',
27-
'kube-exec', # bake into kubeconfig with oidc exec output and additional caching to make kubectl more performant
17+
'browser-windows-default',
18+
'console', # checkout console access (without having to specify --console/-c) and print the URL
19+
'env', # environment variable output (suitable for eval)
20+
'env-nix', # environment variable output specifying "export"
21+
'env-wincmd', # environment variable output specifying "set"
22+
'env-winps', # environment variable output specifying "$env:"
23+
'gcloudauth', # gcloud auth activate-service-account with all fields populated (suitable for eval)
2824
'gcloudauthexec', # will effectively execute results of gcloudauth in a sub-shell
25+
'integrate', # stick the credentials into the local CSP credentials file (AWS)
26+
'json', # json based output
27+
'kube-exec', # bake into kubeconfig with oidc exec output and additional caching to make kubectl more performant
2928
'os-oclogin', # will attempt an oidc authorization code grant flow for generating the `oc login ...` command for OpenShift
3029
'os-ocloginexec', # will attempt an oidc authorization code grant flow for generating the `oc login ...` command for OpenShift and exec the result in a subshell
30+
'text', # text based output
3131
],
3232
case_sensitive=False
3333
)

src/pybritive/choices/output_format.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,42 @@
22

33
output_format_choices = click.Choice(
44
[
5-
'json',
6-
'yaml',
75
'csv',
8-
'table',
6+
'json',
97
'list',
10-
'table-plain',
11-
'table-simple',
12-
'table-github',
13-
'table-grid',
14-
'table-simple_grid',
15-
'table-rounded_grid',
8+
'table',
169
'table-double_grid',
17-
'table-fancy_grid',
18-
'table-outline',
19-
'table-simple_outline',
20-
'table-rounded_outline',
2110
'table-double_outline',
11+
'table-fancy_grid',
2212
'table-fancy_outline',
23-
'table-pipe',
24-
'table-orgtbl',
13+
'table-github',
14+
'table-grid',
15+
'table-html',
2516
'table-jira',
17+
'table-latex',
18+
'table-latex_booktabs',
19+
'table-latex_longtable',
20+
'table-latex_raw',
21+
'table-mediawiki',
22+
'table-moinmoin',
23+
'table-orgtbl',
24+
'table-outline',
25+
'table-pipe',
26+
'table-plain',
2627
'table-presto',
2728
'table-pretty',
2829
'table-psql',
30+
'table-rounded_grid',
31+
'table-rounded_outline',
2932
'table-rst',
30-
'table-mediawiki',
31-
'table-moinmoin',
32-
'table-youtrack',
33-
'table-html',
34-
'table-unsafehtml',
35-
'table-latex',
36-
'table-latex_raw',
37-
'table-latex_booktabs',
38-
'table-latex_longtable',
33+
'table-simple',
34+
'table-simple_grid',
35+
'table-simple_outline',
3936
'table-textile',
40-
'table-tsv'
37+
'table-tsv',
38+
'table-unsafehtml',
39+
'table-youtrack',
40+
'yaml',
4141
],
4242
case_sensitive=False
4343
)

src/pybritive/choices/profile_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
profile_type_choices = click.Choice(
66
[
77
'my-access',
8-
'my-resources'
8+
'my-resources',
99
],
1010
case_sensitive=False
1111
)

src/pybritive/choices/ssh_push_public_key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
ssh_push_public_key_choices = click.Choice(
66
[
7+
'default', # used in flag_value to make the option look like a flag - each CSP can determine what default means
78
'ec2-instance-connect',
8-
'os-login',
99
'instance-metadata',
10-
'default' # used in flag_value to make the option look like a flag - each CSP can determine what default means
10+
'os-login',
1111
],
1212
case_sensitive=False
1313
)

0 commit comments

Comments
 (0)