()
| 895 | * This uses the same authentication chain that the Vertex SDK uses. |
| 896 | */ |
| 897 | export async function checkGcpCredentialsValid(): Promise<boolean> { |
| 898 | try { |
| 899 | // Dynamically import to avoid loading google-auth-library unnecessarily |
| 900 | const { GoogleAuth } = await import('google-auth-library') |
| 901 | const auth = new GoogleAuth({ |
| 902 | scopes: ['https://www.googleapis.com/auth/cloud-platform'], |
| 903 | }) |
| 904 | const probe = (async () => { |
| 905 | const client = await auth.getClient() |
| 906 | await client.getAccessToken() |
| 907 | })() |
| 908 | const timeout = sleep(GCP_CREDENTIALS_CHECK_TIMEOUT_MS).then(() => { |
| 909 | throw new GcpCredentialsTimeoutError('GCP credentials check timed out') |
| 910 | }) |
| 911 | await Promise.race([probe, timeout]) |
| 912 | return true |
| 913 | } catch { |
| 914 | return false |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | /** Default GCP credential TTL - 1 hour to match typical ADC token lifetime */ |
| 919 | const DEFAULT_GCP_CREDENTIAL_TTL = 60 * 60 * 1000 |
no test coverage detected