()
| 845 | * This uses the same authentication chain that the Vertex SDK uses. |
| 846 | */ |
| 847 | export async function checkGcpCredentialsValid(): Promise<boolean> { |
| 848 | try { |
| 849 | // Dynamically import to avoid loading google-auth-library unnecessarily |
| 850 | const { GoogleAuth } = await import('google-auth-library') |
| 851 | const auth = new GoogleAuth({ |
| 852 | scopes: ['https://www.googleapis.com/auth/cloud-platform'], |
| 853 | }) |
| 854 | const probe = (async () => { |
| 855 | const client = await auth.getClient() |
| 856 | await client.getAccessToken() |
| 857 | })() |
| 858 | const timeout = sleep(GCP_CREDENTIALS_CHECK_TIMEOUT_MS).then(() => { |
| 859 | throw new GcpCredentialsTimeoutError('GCP credentials check timed out') |
| 860 | }) |
| 861 | await Promise.race([probe, timeout]) |
| 862 | return true |
| 863 | } catch { |
| 864 | return false |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | /** Default GCP credential TTL - 1 hour to match typical ADC token lifetime */ |
| 869 | const DEFAULT_GCP_CREDENTIAL_TTL = 60 * 60 * 1000 |
no test coverage detected