UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 2.66 kB
import{l as isRecord}from"../record-coerce-BTbqdJ3-.mjs";import{g as readSecureFile}from"../fs-safe-Bxzu1j4h.mjs";import{a as resolveConfiguredGitHubHost}from"../github-host-BIyVIYLv.mjs";import path from"node:path";import fs from"node:fs/promises";import{inspectPathPermissions}from"@openclaw/fs-safe/permissions";import{parseDocument}from"yaml"; //!src/agents/github-exec-credential.ts const GITHUB_EXEC_CREDENTIAL_UNAVAILABLE=`GitHub Identity credential is unavailable or insecure. Reconnect or change GitHub Identity, then retry.`;async function privateProfileStat(e){const t=await fs.lstat(e);if(!t.isDirectory()||t.isSymbolicLink())throw new Error(GITHUB_EXEC_CREDENTIAL_UNAVAILABLE);if(process.platform===`win32`){const t=await inspectPathPermissions(e);if(!t.ok||t.source!==`windows-acl`||t.ownerTrusted!==true||t.groupReadable||t.worldReadable||t.groupWritable||t.worldWritable)throw new Error(GITHUB_EXEC_CREDENTIAL_UNAVAILABLE)}else if((t.mode&63)!==0||t.uid!==process.getuid?.())throw new Error(GITHUB_EXEC_CREDENTIAL_UNAVAILABLE);return t}async function readGitHubExecToken(e,t){try{const n=resolveConfiguredGitHubHost({gateway:{github:{host:t}}});const r=await privateProfileStat(e);const i=await fs.realpath(e);const a=path.join(e,`hosts.yml`);const o=await fs.lstat(a);if(!o.isFile()||o.isSymbolicLink()||o.nlink!==1)throw new Error(GITHUB_EXEC_CREDENTIAL_UNAVAILABLE);const s=await readSecureFile({filePath:a,trust:{trustedDirs:[i]},io:{maxBytes:65536,timeoutMs:5e3}});try{const t=await privateProfileStat(e);if(t.dev!==r.dev||t.ino!==r.ino||path.dirname(s.realPath)!==i||s.stat.nlink!==1)throw new Error(GITHUB_EXEC_CREDENTIAL_UNAVAILABLE);const a=parseDocument(s.buffer.toString(`utf8`),{prettyErrors:false});if(a.errors.length||a.warnings.length)throw new Error(GITHUB_EXEC_CREDENTIAL_UNAVAILABLE);const o=a.toJS({maxAliasCount:0});const c=isRecord(o)?o[n]:void 0;const l=isRecord(c)&&typeof c.oauth_token===`string`?c.oauth_token.trim():``;if(!l||/[\r\n\0]/u.test(l))throw new Error(GITHUB_EXEC_CREDENTIAL_UNAVAILABLE);return l}finally{s.buffer.fill(0)}}catch{throw new Error(GITHUB_EXEC_CREDENTIAL_UNAVAILABLE)}} //!src/agents/github-exec-launcher.ts async function resolveCredential(){const e=await readGitHubExecToken(process.argv[2]??``,process.argv[3]);process.stdout.write(e)}function credentialUnavailable(e){process.exitCode=1;process.stderr.write(`${GITHUB_EXEC_CREDENTIAL_UNAVAILABLE}\nGitHub Identity stage: ${e}\n`)}process.stdout.on(`error`,()=>credentialUnavailable(`credential-output`));process.stderr.on(`error`,()=>{process.exitCode=1});resolveCredential().catch(()=>credentialUnavailable(`credential-read`));export{};