UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.58 kB
import{o as normalizeEnvVarKey}from"./host-env-security-CA3pVx5Z.mjs";import{r as resolvePreferredOpenClawTmpDir}from"./tmp-openclaw-dir-DapBruir.mjs";import{tempWorkspace}from"@openclaw/fs-safe/temp"; //!src/infra/container-env-file.ts function getContainerEnvFileEntryIssue(e,t){if(normalizeEnvVarKey(e,{portable:true})!==e)return`invalid-name`;if(/[\r\n]/u.test(t))return`line-break`;return t.includes(`\0`)?`nul`:void 0}async function createContainerEnvFile(e){let t=``;const n=Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t));for(const[e,r]of n){const n=getContainerEnvFileEntryIssue(e,r);if(n===`invalid-name`)throw new Error(`Invalid container environment variable name ${JSON.stringify(e)}; use letters, digits, and underscores without a leading digit.`);if(n===`line-break`)throw new Error(`Container environment variable ${e} must have a single-line value because Docker and Podman --env-file entries are line-delimited.`);if(n===`nul`)throw new Error(`Container environment variable ${e} must not contain NUL bytes.`);t+=`${e}=${r}\n`}const r=await tempWorkspace({rootDir:resolvePreferredOpenClawTmpDir(),prefix:`openclaw-container-env-`,dirMode:448,mode:384});try{return{path:await r.store.write(`container.env`,t,{durable:false}),cleanup:async()=>{await r.cleanup()}}}catch(e){await r.cleanup().catch(()=>void 0);throw e}}async function withContainerEnvFile(e,t){const n=await createContainerEnvFile(e);try{return await t(n.path)}finally{await n.cleanup()}}export{getContainerEnvFileEntryIssue as n,withContainerEnvFile as r,createContainerEnvFile as t};