@@ -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
0 commit comments