UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.01 kB
import{_ as resolveSecretInputRef}from"./types.secrets-UWdyCdE6.mjs";import{a as copyConfigResolutionFactsExcept}from"./resolution-facts-DYKtoyes.mjs";import{a as getRuntimeConfigSnapshot}from"./runtime-snapshot-Bg5K4JNu.mjs";import{a as resolveGatewayCredentialsFromValues,s as createGatewayCredentialPlan}from"./credentials-BL-kavyD.mjs"; //!src/gateway/auth-resolve.ts function mergeGatewayAuthConfig(e,t){const n={...e};if(!t)return n;for(const e of[`mode`,`token`,`password`,`allowTailscale`,`rateLimit`,`trustedProxy`])if(t[e]!==void 0)Object.assign(n,{[e]:t[e]});return n}function resolveGatewayAuthFromCredentials(e){const{authConfig:t,authOverride:n,token:r,password:i}=e;const a=n?.mode??t.mode??(i?`password`:`token`);return{mode:a,modeSource:n?.mode!==void 0?`override`:t.mode?`config`:i?`password`:r?`token`:`default`,token:r,password:i,allowTailscale:t.allowTailscale??(e.tailscaleMode===`serve`&&a!==`password`&&a!==`trusted-proxy`),trustedProxy:t.trustedProxy}}function resolveGatewayAuth(e){const t=getRuntimeConfigSnapshot();if(t&&t.gateway?.auth===e.authConfig)return resolveGatewayAuthForConfig({config:t,authOverride:e.authOverride,env:e.env,tailscaleMode:e.tailscaleMode});const n=e.authOverride??void 0;const r=mergeGatewayAuthConfig(e.authConfig,n);const i=e.env??process.env;const a=resolveSecretInputRef({value:r.token}).ref;const o=resolveSecretInputRef({value:r.password}).ref;const s=resolveGatewayCredentialsFromValues({configToken:a?void 0:r.token,configPassword:o?void 0:r.password,env:i,tokenPrecedence:`config-first`,passwordPrecedence:`config-first`});return resolveGatewayAuthFromCredentials({authConfig:r,authOverride:n,token:s.token,password:s.password,tailscaleMode:e.tailscaleMode})}function canHotReloadGatewayAuthCredentials(e,t){if(!e||!t)return false;const n=[e,t].map(e=>{const t=e.gateway?.auth;if(!t?.mode&&(resolveSecretInputRef({value:t?.token}).ref||resolveSecretInputRef({value:t?.password}).ref))return;return resolveGatewayAuth({authConfig:t,tailscaleMode:e.gateway?.tailscale?.mode}).mode});return(n[0]===`token`||n[0]===`password`)&&n[0]===n[1]}function resolveGatewayAuthForConfig(e){const t=e.authOverride??void 0;const n=mergeGatewayAuthConfig(e.config.gateway?.auth,t);const r={...e.config,gateway:{...e.config.gateway,auth:n}};const i=[...t?.token!==void 0?[`gateway.auth.token`]:[],...t?.password!==void 0?[`gateway.auth.password`]:[]];copyConfigResolutionFactsExcept(e.config,r,i);const a=createGatewayCredentialPlan({config:r,env:e.env});return resolveGatewayAuthFromCredentials({authConfig:n,authOverride:t,token:a.localToken.hasSecretRef?void 0:a.localToken.value??a.envToken??a.remoteToken.value,password:a.localPassword.hasSecretRef?void 0:a.localPassword.value??a.envPassword??(a.authMode===`trusted-proxy`?void 0:a.remotePassword.value),tailscaleMode:e.tailscaleMode})}export{resolveGatewayAuthFromCredentials as a,resolveGatewayAuthForConfig as i,mergeGatewayAuthConfig as n,resolveGatewayAuth as r,canHotReloadGatewayAuthCredentials as t};