Fetch an identity token for the given audience via gcloud.
(audience: str)
| 57 | |
| 58 | |
| 59 | def _get_identity_token(audience: str) -> str | None: |
| 60 | """Fetch an identity token for the given audience via gcloud.""" |
| 61 | try: |
| 62 | result = subprocess.run( |
| 63 | [ |
| 64 | "gcloud", |
| 65 | "auth", |
| 66 | "print-identity-token", |
| 67 | f"--audiences={audience}", |
| 68 | ], |
| 69 | capture_output=True, |
| 70 | text=True, |
| 71 | check=True, |
| 72 | ) |
| 73 | return result.stdout.strip() |
| 74 | except (FileNotFoundError, subprocess.CalledProcessError): |
| 75 | return None |
| 76 | |
| 77 | |
| 78 | # --------------------------------------------------------------------------- |
no test coverage detected