()
| 919 | * This uses the same authentication chain that the Vertex SDK uses. |
| 920 | */ |
| 921 | export async function checkGcpCredentialsValid(): Promise<boolean> { |
| 922 | try { |
| 923 | // Dynamically import to avoid loading google-auth-library unnecessarily |
| 924 | const { GoogleAuth } = await import('google-auth-library') |
| 925 | const auth = new GoogleAuth({ |
| 926 | scopes: ['https://www.googleapis.com/auth/cloud-platform'], |
| 927 | }) |
| 928 | const probe = (async () => { |
| 929 | const client = await auth.getClient() |
| 930 | await client.getAccessToken() |
| 931 | })() |
| 932 | const timeout = sleep(GCP_CREDENTIALS_CHECK_TIMEOUT_MS).then(() => { |
| 933 | throw new GcpCredentialsTimeoutError('GCP credentials check timed out') |
| 934 | }) |
| 935 | await Promise.race([probe, timeout]) |
| 936 | return true |
| 937 | } catch { |
| 938 | return false |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /** Default GCP credential TTL - 1 hour to match typical ADC token lifetime */ |
| 943 | const DEFAULT_GCP_CREDENTIAL_TTL = 60 * 60 * 1000 |
no test coverage detected