Skip to content

Commit 05f6224

Browse files
authored
Merge pull request #207 from britive/fix/gcp-console-fallback
fix/gcp-console-fallback
2 parents ee8b3a5 + 6ec1b17 commit 05f6224

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
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+
## v2.2.1 [2025-06-26]
7+
8+
__What's New:__
9+
10+
* None
11+
12+
__Enhancements:__
13+
14+
* None
15+
16+
__Bug Fixes:__
17+
18+
* Fixed output error when GCP checkout falls back to `console` mode for profiles with no programmatic access.
19+
* Fixed missing `responseTemplates` when listing resources.
20+
21+
__Dependencies:__
22+
23+
* None
24+
25+
__Other:__
26+
27+
* None
28+
629
## v2.2.0 [2025-05-08]
730

831
__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__ = '2.2.0'
1+
__version__ = '2.2.1'

src/pybritive/britive_cli.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,12 @@ def list_resources(self):
350350
name = item['resourceName']
351351
if name not in found_resource_names:
352352
resources.append(
353-
{'resourceId': item['resourceId'], 'resourceName': name, 'resourceLabels': item['resourceLabels']}
353+
{
354+
'resourceId': item['resourceId'],
355+
'resourceName': name,
356+
'resourceLabels': item['resourceLabels'],
357+
'responseTemplates': item['responseTemplates'],
358+
}
354359
)
355360
found_resource_names.append(name)
356361
self.print(resources, ignore_silent=True)
@@ -762,19 +767,22 @@ def _checkout(
762767
# attempt to automatically checkout console access instead
763768
# this is a cli only feature - not available in the sdk
764769
self.print('no programmatic access available - checking out console access instead')
765-
return self._checkout(
766-
app_name,
767-
blocktime,
768-
env_name,
769-
justification,
770-
maxpolltime,
771-
otp,
772-
profile_name,
773-
False,
774-
ticket_id,
775-
ticket_type,
776-
mode,
777-
)
770+
return {
771+
**self._checkout(
772+
app_name,
773+
blocktime,
774+
env_name,
775+
justification,
776+
maxpolltime,
777+
otp,
778+
profile_name,
779+
False,
780+
ticket_id,
781+
ticket_type,
782+
mode,
783+
),
784+
'console-fallback': True,
785+
}
778786
raise e
779787

780788
@staticmethod
@@ -861,11 +869,12 @@ def _access_checkout(
861869
self._extend_checkout(profile, console)
862870
return None
863871

864-
credentials = None
872+
self.verbose_checkout = verbose
865873
app_type = None
866874
cached_credentials_found = False
875+
console_fallback = False
876+
credentials = None
867877
k8s_processor = None
868-
self.verbose_checkout = verbose
869878

870879
# handle kube-exec since the profile is actually going to be passed in via another method
871880
# and perform some basic validation so we don't waste time performing a checkout when we
@@ -924,6 +933,7 @@ def _access_checkout(
924933
response = self._checkout(**params)
925934
app_type = self._get_app_type(response['appContainerId'])
926935
credentials = response['credentials']
936+
console_fallback = response.get('console-fallback')
927937

928938
# this handles the --force-renew flag
929939
# lets check to see if we should checkin this profile first and check it out again
@@ -937,12 +947,13 @@ def _access_checkout(
937947
response = self._checkout(**params)
938948
cached_credentials_found = False # need to write new creds to cache
939949
credentials = response['credentials']
950+
console_fallback = response.get('console-fallback')
940951

941952
if mode in self.cachable_modes and not cached_credentials_found:
942953
Cache(passphrase=passphrase).save_credentials(
943954
profile_name=alias or profile, credentials=credentials, mode=mode
944955
)
945-
return app_type, credentials, k8s_processor
956+
return app_type, console_fallback, credentials, k8s_processor
946957

947958
def checkout(
948959
self,
@@ -976,7 +987,7 @@ def checkout(
976987
ticket_type=ticket_type,
977988
)
978989
else:
979-
app_type, credentials, k8s_processor = self._access_checkout(
990+
app_type, console_fallback, credentials, k8s_processor = self._access_checkout(
980991
alias=alias,
981992
blocktime=blocktime,
982993
console=console,
@@ -998,7 +1009,7 @@ def checkout(
9981009

9991010
self.__get_cloud_credential_printer(
10001011
app_type,
1001-
console,
1012+
console or console_fallback,
10021013
mode,
10031014
alias or profile,
10041015
self.silent,

src/pybritive/helpers/cloud_credential_printer.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,12 @@ def __init__(self, console, mode, profile, silent, credentials, cli, gcloud_key_
253253
def print_json(self):
254254
self.cli.print(json.dumps(self.credentials, indent=2), ignore_silent=True)
255255
self.cli.print('', ignore_silent=True)
256-
self.cli.print(
257-
f"Run command: gcloud auth activate-service-account {self.credentials['client_email']} "
258-
"--key-file <path-where-above-json-is-stored>",
259-
ignore_silent=True,
260-
)
256+
if not self.console:
257+
self.cli.print(
258+
f'Run command: gcloud auth activate-service-account {self.credentials.get("client_email")} '
259+
'--key-file <path-where-above-json-is-stored>',
260+
ignore_silent=True,
261+
)
261262

262263
def print_gcloudauth(self):
263264
# get path to gcloud key file
@@ -271,7 +272,7 @@ def print_gcloudauth(self):
271272
path.write_text(json.dumps(self.credentials, indent=2), encoding='utf-8')
272273

273274
self.cli.print(
274-
f"gcloud auth activate-service-account {self.credentials['client_email']} --key-file {path!s}",
275+
f'gcloud auth activate-service-account {self.credentials["client_email"]} --key-file {path!s}',
275276
ignore_silent=True,
276277
)
277278

0 commit comments

Comments
 (0)