(gcpAuthRefresh: string)
| 989 | const GCP_AUTH_REFRESH_TIMEOUT_MS = 3 * 60 * 1000 |
| 990 | |
| 991 | export 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. |
no test coverage detected