* Run gcpAuthRefresh to perform interactive authentication (e.g., gcloud auth application-default login) * Streams output in real-time for user visibility
()
| 923 | * Streams output in real-time for user visibility |
| 924 | */ |
| 925 | async function runGcpAuthRefresh(): Promise<boolean> { |
| 926 | const gcpAuthRefresh = getConfiguredGcpAuthRefresh() |
| 927 | |
| 928 | if (!gcpAuthRefresh) { |
| 929 | return false // Not configured, treat as success |
| 930 | } |
| 931 | |
| 932 | // SECURITY: Check if gcpAuthRefresh is from project settings |
| 933 | if (isGcpAuthRefreshFromProjectSettings()) { |
| 934 | // Check if trust has been established for this project |
| 935 | // Pass true to indicate this is a dangerous feature that requires trust |
| 936 | const hasTrust = checkHasTrustDialogAccepted() |
| 937 | if (!hasTrust && !getIsNonInteractiveSession()) { |
| 938 | const error = new Error( |
| 939 | `Security: gcpAuthRefresh executed before workspace trust is confirmed. If you see this message, post in ${MACRO.FEEDBACK_CHANNEL}.`, |
| 940 | ) |
| 941 | logAntError('gcpAuthRefresh invoked before trust check', error) |
| 942 | logEvent('tengu_gcpAuthRefresh_missing_trust', {}) |
| 943 | return false |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | try { |
| 948 | logForDebugging('Checking GCP credentials validity for auth refresh') |
| 949 | const isValid = await checkGcpCredentialsValid() |
| 950 | if (isValid) { |
| 951 | logForDebugging( |
| 952 | 'GCP credentials are valid, skipping auth refresh command', |
| 953 | ) |
| 954 | return false |
| 955 | } |
| 956 | } catch { |
| 957 | // Credentials check failed, proceed with refresh |
| 958 | } |
| 959 | |
| 960 | return refreshGcpAuth(gcpAuthRefresh) |
| 961 | } |
| 962 | |
| 963 | // Timeout for GCP auth refresh command (3 minutes). |
| 964 | // Long enough for browser-based auth flows, short enough to prevent indefinite hangs. |
no test coverage detected