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

Function checkGcpCredentialsValid

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

Source from the content-addressed store, hash-verified

919 * This uses the same authentication chain that the Vertex SDK uses.
920 */
921export 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 */
943const DEFAULT_GCP_CREDENTIAL_TTL = 60 * 60 * 1000

Callers 1

runGcpAuthRefreshFunction · 0.85

Calls 1

sleepFunction · 0.70

Tested by

no test coverage detected