Return GCP project ID from env or gcloud config.
()
| 40 | |
| 41 | |
| 42 | def _get_project_id() -> str | None: |
| 43 | """Return GCP project ID from env or gcloud config.""" |
| 44 | project = os.environ.get("GCP_PROJECT_ID") |
| 45 | if project: |
| 46 | return project |
| 47 | try: |
| 48 | result = subprocess.run( |
| 49 | ["gcloud", "config", "get-value", "project"], |
| 50 | capture_output=True, |
| 51 | text=True, |
| 52 | check=False, |
| 53 | ) |
| 54 | return result.stdout.strip() or None |
| 55 | except FileNotFoundError: |
| 56 | return None |
| 57 | |
| 58 | |
| 59 | def _get_identity_token(audience: str) -> str | None: |
no test coverage detected