MCPcopy Create free account
hub / github.com/freecodexyz/free-code / checkGcpCredentialsValid

Function checkGcpCredentialsValid

src/utils/auth.ts:848–867  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

runGcpAuthRefreshFunction · 0.85

Calls 1

sleepFunction · 0.85

Tested by

no test coverage detected