/
gkat
/
gitverse-codex-plugin
Обзор
Документация
Войти
/
gkat
/
gitverse-codex-plugin
Код
Запросы
0
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/auth.mjs
90 строк
3 KB
gkat
Add cross-platform authentication and usage guide
29 июл 2026, 15:18
29 июл 2026, 15:18
a87de51
Код
Авторство
О чём код?
import { execFileSync as defaultExecFileSync } from "node:child_process"; function clean(value) { const token = String(value || "").trim(); return token || undefined; } function run(execFileSync, command, args) { try { return clean( execFileSync(command, args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], }), ); } catch { return undefined; } } function quotePowerShell(value) { return String(value).replaceAll("'", "''"); } export function resolveToken({ env = process.env, platform = process.platform, execFileSync = defaultExecFileSync, } = {}) { const environmentToken = clean(env.GITVERSE_TOKEN); if (environmentToken) { return { token: environmentToken, source: "GITVERSE_TOKEN" }; } const account = env.GITVERSE_SECRET_ACCOUNT || env.GITVERSE_KEYCHAIN_ACCOUNT; const configuredName = env.GITVERSE_SECRET_NAME || env.GITVERSE_KEYCHAIN_SERVICE; if (platform === "darwin") { const services = configuredName ? [configuredName] : ["codex-gitverse-mcp", "GitVerse", "gitverse", "gitverse.ru"]; for (const service of services) { const args = ["find-generic-password", "-w", "-s", service]; if (account) args.push("-a", account); const token = run(execFileSync, "security", args); if (token) return { token, source: `macOS Keychain (${service})` }; } const args = ["find-internet-password", "-w", "-s", "gitverse.ru"]; if (account) args.push("-a", account); const token = run(execFileSync, "security", args); if (token) return { token, source: "macOS Keychain (gitverse.ru)" }; } if (platform === "linux") { const secretName = configuredName || "codex-gitverse-mcp"; const args = ["lookup", "service", secretName]; if (account) args.push("account", account); const token = run(execFileSync, "secret-tool", args); if (token) return { token, source: `Linux Secret Service (${secretName})` }; } if (platform === "win32") { const secretName = quotePowerShell( configuredName || "codex-gitverse-mcp", ); const script = `$value = Get-Secret -Name '${secretName}' -AsPlainText -ErrorAction Stop; [Console]::Out.Write($value)`; for (const executable of ["powershell.exe", "pwsh"]) { const token = run(execFileSync, executable, [ "-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script, ]); if (token) { return { token, source: `PowerShell SecretManagement (${secretName})`, }; } } } throw new Error( `GitVerse token not found for ${platform}. Configure the platform secret store or GITVERSE_TOKEN; see README.md#authentication.`, ); }