openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.61 kB
JavaScript
import{_ as resolveSecretInputRef,o as hasConfiguredSecretInput}from"./types.secrets-UWdyCdE6.mjs";import{r as resolveCanonicalRequiredConfiguredSecretRefInputString}from"./resolve-configured-secret-input-string-BVebKi8N.mjs";import{o as readGatewaySecretInputValue,r as assignResolvedGatewaySecretInput}from"./secret-input-paths-DKW4Nh7w.mjs";
//!src/gateway/auth-config-utils.ts
function hasConfiguredGatewayAuthSecretInput(e,t){return hasConfiguredSecretInput(readGatewaySecretInputValue(e,t),e.secrets?.defaults)}function shouldResolveGatewayAuthSecretRef(e,t){const n=t===`gateway.auth.token`;if(n?e.hasTokenOverride:e.hasPasswordOverride)return false;if(e.mode===(n?`token`:`password`))return true;if(e.mode===`trusted-proxy`)return!n;if(e.mode===`token`||e.mode===`password`||e.mode===`none`)return false;return n?!(e.hasPasswordOverride||e.hasPasswordFallback):!(e.hasTokenOverride||e.hasTokenFallback)}function hasActiveExecGatewayAuthSecretRef(e,t){if(!shouldResolveGatewayAuthSecretRef(e,t))return false;const{ref:n}=resolveSecretInputRef({value:readGatewaySecretInputValue(e.cfg,t),defaults:e.cfg.secrets?.defaults});return n?.source===`exec`}function canMaterializeGatewayAuthSecretRefsWithoutExec(e){return!(hasActiveExecGatewayAuthSecretRef(e,`gateway.auth.token`)||hasActiveExecGatewayAuthSecretRef(e,`gateway.auth.password`))}async function resolveGatewayAuthSecretRefValue(e,t){if(!shouldResolveGatewayAuthSecretRef(e,t))return;return await resolveCanonicalRequiredConfiguredSecretRefInputString({config:e.cfg,env:e.env,value:readGatewaySecretInputValue(e.cfg,t),path:t})||void 0}async function resolveGatewayTokenSecretRefValue(e){return resolveGatewayAuthSecretRefValue(e,`gateway.auth.token`)}async function resolveGatewayPasswordSecretRefValue(e){return resolveGatewayAuthSecretRefValue(e,`gateway.auth.password`)}async function resolveGatewayAuthSecretRef(e,t){const n=e.cfg;const r=await resolveGatewayAuthSecretRefValue(e,t);if(!r)return n;const i=structuredClone(n);i.gateway??={};i.gateway.auth??={};assignResolvedGatewaySecretInput({config:i,path:t,value:r});return i}async function materializeGatewayAuthSecretRefs(e){const t=await resolveGatewayAuthSecretRef(e,`gateway.auth.token`);return await resolveGatewayAuthSecretRef({...e,cfg:t,hasTokenFallback:e.hasTokenFallback||hasConfiguredGatewayAuthSecretInput(t,`gateway.auth.token`)},`gateway.auth.password`)}export{resolveGatewayTokenSecretRefValue as a,resolveGatewayPasswordSecretRefValue as i,hasConfiguredGatewayAuthSecretInput as n,materializeGatewayAuthSecretRefs as r,canMaterializeGatewayAuthSecretRefsWithoutExec as t};