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

Function runGcpAuthRefresh

src/utils/auth.ts:949–985  ·  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

947 * Streams output in real-time for user visibility
948 */
949async function runGcpAuthRefresh(): Promise<boolean> {
950 const gcpAuthRefresh = getConfiguredGcpAuthRefresh()
951
952 if (!gcpAuthRefresh) {
953 return false // Not configured, treat as success
954 }
955
956 // SECURITY: Check if gcpAuthRefresh is from project settings
957 if (isGcpAuthRefreshFromProjectSettings()) {
958 // Check if trust has been established for this project
959 // Pass true to indicate this is a dangerous feature that requires trust
960 const hasTrust = checkHasTrustDialogAccepted()
961 if (!hasTrust && !getIsNonInteractiveSession()) {
962 const error = new Error(
963 `Security: gcpAuthRefresh executed before workspace trust is confirmed. If you see this message, post in ${MACRO.FEEDBACK_CHANNEL}.`,
964 )
965 logAntError('gcpAuthRefresh invoked before trust check', error)
966 logEvent('ncode_gcpAuthRefresh_missing_trust', {})
967 return false
968 }
969 }
970
971 try {
972 logForDebugging('Checking GCP credentials validity for auth refresh')
973 const isValid = await checkGcpCredentialsValid()
974 if (isValid) {
975 logForDebugging(
976 'GCP credentials are valid, skipping auth refresh command',
977 )
978 return false
979 }
980 } catch {
981 // Credentials check failed, proceed with refresh
982 }
983
984 return refreshGcpAuth(gcpAuthRefresh)
985}
986
987// Timeout for GCP auth refresh command (3 minutes).
988// Long enough for browser-based auth flows, short enough to prevent indefinite hangs.

Callers 1

auth.tsFile · 0.85

Calls 9

logAntErrorFunction · 0.85
checkGcpCredentialsValidFunction · 0.85
refreshGcpAuthFunction · 0.85
logForDebuggingFunction · 0.70
logEventFunction · 0.50

Tested by

no test coverage detected