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

Function refreshGcpAuth

src/utils/auth.ts:991–1041  ·  view source on GitHub ↗
(gcpAuthRefresh: string)

Source from the content-addressed store, hash-verified

989const GCP_AUTH_REFRESH_TIMEOUT_MS = 3 * 60 * 1000
990
991export function refreshGcpAuth(gcpAuthRefresh: string): Promise<boolean> {
992 logForDebugging('Running GCP auth refresh command')
993 // Start tracking authentication status. AwsAuthStatusManager is cloud-provider-agnostic
994 // despite the name — print.ts emits its updates as generic SDK 'auth_status' messages.
995 const authStatusManager = AwsAuthStatusManager.getInstance()
996 authStatusManager.startAuthentication()
997
998 return new Promise(resolve => {
999 const refreshProc = exec(gcpAuthRefresh, {
1000 timeout: GCP_AUTH_REFRESH_TIMEOUT_MS,
1001 })
1002 refreshProc.stdout!.on('data', data => {
1003 const output = data.toString().trim()
1004 if (output) {
1005 // Add output to status manager for UI display
1006 authStatusManager.addOutput(output)
1007 // Also log for debugging
1008 logForDebugging(output, { level: 'debug' })
1009 }
1010 })
1011
1012 refreshProc.stderr!.on('data', data => {
1013 const error = data.toString().trim()
1014 if (error) {
1015 authStatusManager.setError(error)
1016 logForDebugging(error, { level: 'error' })
1017 }
1018 })
1019
1020 refreshProc.on('close', (code, signal) => {
1021 if (code === 0) {
1022 logForDebugging('GCP auth refresh completed successfully')
1023 authStatusManager.endAuthentication(true)
1024 void resolve(true)
1025 } else {
1026 const timedOut = signal === 'SIGTERM'
1027 const message = timedOut
1028 ? chalk.red(
1029 'GCP auth refresh timed out after 3 minutes. Run your auth command manually in a separate terminal.',
1030 )
1031 : chalk.red(
1032 'Error running gcpAuthRefresh (in settings or global config, typically ~/.ncode/.config.json):',
1033 )
1034 // biome-ignore lint/suspicious/noConsole:: intentional console output
1035 console.error(message)
1036 authStatusManager.endAuthentication(false)
1037 void resolve(false)
1038 }
1039 })
1040 })
1041}
1042
1043/**
1044 * Refresh GCP authentication if needed.

Callers 1

runGcpAuthRefreshFunction · 0.85

Calls 10

execFunction · 0.85
startAuthenticationMethod · 0.80
addOutputMethod · 0.80
setErrorMethod · 0.80
endAuthenticationMethod · 0.80
logForDebuggingFunction · 0.70
resolveFunction · 0.70
toStringMethod · 0.65
getInstanceMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected