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

Function runGcpAuthRefresh

src/utils/auth.ts:876–912  ·  view source on GitHub ↗

* Run gcpAuthRefresh to perform interactive authentication (e.g., gcloud auth application-default login) * Streams output in real-time for user visibility

()

Source from the content-addressed store, hash-verified

874 * Streams output in real-time for user visibility
875 */
876async function runGcpAuthRefresh(): Promise<boolean> {
877 const gcpAuthRefresh = getConfiguredGcpAuthRefresh()
878
879 if (!gcpAuthRefresh) {
880 return false // Not configured, treat as success
881 }
882
883 // SECURITY: Check if gcpAuthRefresh is from project settings
884 if (isGcpAuthRefreshFromProjectSettings()) {
885 // Check if trust has been established for this project
886 // Pass true to indicate this is a dangerous feature that requires trust
887 const hasTrust = checkHasTrustDialogAccepted()
888 if (!hasTrust && !getIsNonInteractiveSession()) {
889 const error = new Error(
890 `Security: gcpAuthRefresh executed before workspace trust is confirmed. If you see this message, post in ${MACRO.FEEDBACK_CHANNEL}.`,
891 )
892 logAntError('gcpAuthRefresh invoked before trust check', error)
893 logEvent('tengu_gcpAuthRefresh_missing_trust', {})
894 return false
895 }
896 }
897
898 try {
899 logForDebugging('Checking GCP credentials validity for auth refresh')
900 const isValid = await checkGcpCredentialsValid()
901 if (isValid) {
902 logForDebugging(
903 'GCP credentials are valid, skipping auth refresh command',
904 )
905 return false
906 }
907 } catch {
908 // Credentials check failed, proceed with refresh
909 }
910
911 return refreshGcpAuth(gcpAuthRefresh)
912}
913
914// Timeout for GCP auth refresh command (3 minutes).
915// Long enough for browser-based auth flows, short enough to prevent indefinite hangs.

Callers 1

auth.tsFile · 0.85

Calls 9

logAntErrorFunction · 0.85
logEventFunction · 0.85
logForDebuggingFunction · 0.85
checkGcpCredentialsValidFunction · 0.85
refreshGcpAuthFunction · 0.85

Tested by

no test coverage detected