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

Function refreshGcpAuth

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

Source from the content-addressed store, hash-verified

916const GCP_AUTH_REFRESH_TIMEOUT_MS = 3 * 60 * 1000
917
918export function refreshGcpAuth(gcpAuthRefresh: string): Promise<boolean> {
919 logForDebugging('Running GCP auth refresh command')
920 // Start tracking authentication status. AwsAuthStatusManager is cloud-provider-agnostic
921 // despite the name — print.ts emits its updates as generic SDK 'auth_status' messages.
922 const authStatusManager = AwsAuthStatusManager.getInstance()
923 authStatusManager.startAuthentication()
924
925 return new Promise(resolve => {
926 const refreshProc = exec(gcpAuthRefresh, {
927 timeout: GCP_AUTH_REFRESH_TIMEOUT_MS,
928 })
929 refreshProc.stdout!.on('data', data => {
930 const output = data.toString().trim()
931 if (output) {
932 // Add output to status manager for UI display
933 authStatusManager.addOutput(output)
934 // Also log for debugging
935 logForDebugging(output, { level: 'debug' })
936 }
937 })
938
939 refreshProc.stderr!.on('data', data => {
940 const error = data.toString().trim()
941 if (error) {
942 authStatusManager.setError(error)
943 logForDebugging(error, { level: 'error' })
944 }
945 })
946
947 refreshProc.on('close', (code, signal) => {
948 if (code === 0) {
949 logForDebugging('GCP auth refresh completed successfully')
950 authStatusManager.endAuthentication(true)
951 void resolve(true)
952 } else {
953 const timedOut = signal === 'SIGTERM'
954 const message = timedOut
955 ? chalk.red(
956 'GCP auth refresh timed out after 3 minutes. Run your auth command manually in a separate terminal.',
957 )
958 : chalk.red(
959 'Error running gcpAuthRefresh (in settings or ~/.claude.json):',
960 )
961 // biome-ignore lint/suspicious/noConsole:: intentional console output
962 console.error(message)
963 authStatusManager.endAuthentication(false)
964 void resolve(false)
965 }
966 })
967 })
968}
969
970/**
971 * Refresh GCP authentication if needed.

Callers 1

runGcpAuthRefreshFunction · 0.85

Calls 10

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

Tested by

no test coverage detected