UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 4.26 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{_ as resolveSecretInputRef,o as hasConfiguredSecretInput}from"./types.secrets-UWdyCdE6.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{v as formatUnsafeGatewayTailscaleNoAuthMessage,y as isUnsafeGatewayTailscaleNoAuth}from"./validation-core-Dgg8JyG6.mjs";import{r as replaceConfigFile}from"./mutate-DcH8aT_4.mjs";import{r as resolveGatewayAuth}from"./auth-resolve-UwT9_UjV.mjs";import{i as assertGatewayServiceUpdateCurrent,o as isUpdateOwnedGatewayServiceCommand}from"./service-update-authority-DqjrBTQ9.mjs";import{n as collectDurableServiceEnvVars}from"./state-dir-dotenv-BtH1iiHQ.mjs";import"./auth-BwgQGI6W.mjs";import{n as hasAmbiguousGatewayAuthModeConfig}from"./auth-mode-policy-BwBhFxiZ.mjs";import{t as randomToken}from"./random-token-CWOnwMog.mjs";import{t as resolveGatewayAuthToken}from"./auth-token-resolution-BHyWE1aF.mjs"; //!src/gateway/auth-install-policy.ts function shouldRequireGatewayTokenForInstall(e,t){switch(e.gateway?.auth?.mode){case`token`:return true;case`password`:case`none`:case`trusted-proxy`:return false;case void 0:}if(hasConfiguredSecretInput(e.gateway?.auth?.password,e.secrets?.defaults))return false;const n=collectDurableServiceEnvVars({env:t,config:e});return!normalizeOptionalString(n.OPENCLAW_GATEWAY_PASSWORD)} //!src/commands/gateway-install-token.ts async function maybePersistAutoGeneratedGatewayInstallToken(e){try{const{snapshot:t,writeOptions:n}=e.generation;if(t.exists&&!t.valid){e.warnings.push(`Warning: config file exists but is invalid; skipping token persistence.`);return}const r=t.exists?t.sourceConfig??t.config:{};const i=resolveSecretInputRef({value:r.gateway?.auth?.token,defaults:r.secrets?.defaults}).ref;const a=i||typeof r.gateway?.auth?.token!==`string`?void 0:normalizeOptionalString(r.gateway.auth.token);if(!i&&!a){await replaceConfigFile({sourceConfig:{...r,gateway:{...r.gateway,auth:{...r.gateway?.auth,mode:r.gateway?.auth?.mode??`token`,token:e.token}}},snapshot:t,writeOptions:{baseSnapshot:t,...n,...isUpdateOwnedGatewayServiceCommand()?{assertCurrent:()=>{n.assertCurrent?.();assertGatewayServiceUpdateCurrent()}}:{},skipRuntimeSnapshotRefresh:true},afterWrite:{mode:`auto`}});return}if(a)return;e.warnings.push(`Warning: gateway.auth.token is SecretRef-managed; skipping plaintext token persistence.`)}catch(t){e.warnings.push(`Warning: could not persist token to config: ${String(t)}`)}}function formatAmbiguousGatewayAuthModeReason(){return[`gateway.auth.token and gateway.auth.password are both configured while gateway.auth.mode is unset.`,`Set ${formatCliCommand(`openclaw config set gateway.auth.mode token`)} or ${formatCliCommand(`openclaw config set gateway.auth.mode password`)}.`].join(` `)}async function resolveGatewayInstallToken(e){const t=e.config;const n=[];const resolution=e=>({unavailableReason:e,warnings:n});if(hasAmbiguousGatewayAuthModeConfig(t))return resolution(formatAmbiguousGatewayAuthModeReason());const r=resolveGatewayAuth({authConfig:t.gateway?.auth,env:e.env,tailscaleMode:t.gateway?.tailscale?.mode??`off`});const i=t.gateway?.tailscale?.mode??`off`;if(isUnsafeGatewayTailscaleNoAuth({authMode:r.mode,tailscaleMode:i}))return resolution(formatUnsafeGatewayTailscaleNoAuthMessage(i));if(!(shouldRequireGatewayTokenForInstall(t,e.env)&&!r.allowTailscale))return resolution();const a=await resolveGatewayAuthToken({cfg:t,env:e.env,explicitToken:e.explicitToken,envFallback:`no-secret-ref`,unresolvedReasonStyle:`detailed`});const o=a.secretRefConfigured;const s=a.source===`secretRef`?void 0:a.token;let c;if(o&&a.source===`secretRef`)n.push(`gateway.auth.token is SecretRef-managed; install will not persist a resolved token in service environment. Check that the SecretRef is resolvable in the daemon runtime context.`);else if(o&&!s)c=`gateway.auth.token SecretRef is configured but unresolved (${a.unresolvedRefReason??`unknown reason`}).`;if(!s&&!o&&e.generateIfMissing){const t=randomToken();n.push(`No gateway token found. Auto-generated one and saving to config.`);await maybePersistAutoGeneratedGatewayInstallToken({token:t,generation:e.generateIfMissing,warnings:n})}return resolution(c)}export{resolveGatewayInstallToken as t};