Servers and the agent, backend (2.1.0): join, jobs, schedules, port list, stats, alerts
- Agent API /api/agent/v1: join with a one-time token, then poll, stats, report and export upload, all signed with the server's Ed25519 key. - Jobs signed with a separate job key (HUB_JOB_SIGNING_KEY_FILE) when delivered, config sealed to the server; one at a time per server; missed when not picked up in their window. - New install (licence, ports, preflight against the release's env template), Proxy done with public URL checks, scheduled / emergency (2FA, reason) / batch updates with email and banner, uninstall with an encrypted export first (the key is never stored), adopt and linking existing installs, purge after 30 days. - Port list, install defaults, server configuration (encrypted), stats per minute / hour with roll-up, server alerts. contracts 1.3.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* The env template of the release being installed (crosscode.env-template/1,
|
||||
* apps/<product>/env.template.json at its tag), read from git like the release notes. The Hub
|
||||
* refuses to make a job when a required server or defaults value is missing (AGENT-1.0-PLAN §5).
|
||||
* Releases from before templates (events@2.2.0) use the copy kept here, the same one the
|
||||
* crosscode script falls back to.
|
||||
*/
|
||||
|
||||
const { agent } = require('@crosscode/contracts');
|
||||
const { getSettings, releaseRepoToken } = require('./settings');
|
||||
const { PLATFORM_REPO, parseRepoUrl, gitGet } = require('./releaseSync');
|
||||
|
||||
const FALLBACK = { events: require('./envTemplates/events.json') };
|
||||
const cache = new Map();
|
||||
|
||||
async function envTemplate(product, version) {
|
||||
const key = `${product}@${version}`;
|
||||
if (cache.has(key)) return cache.get(key);
|
||||
let template = null;
|
||||
try {
|
||||
const repo = parseRepoUrl(PLATFORM_REPO);
|
||||
const token = await releaseRepoToken().catch(() => '');
|
||||
const text = await gitGet(`${repo.api}/raw/${encodeURIComponent(`apps/${product}`)}/env.template.json?ref=${encodeURIComponent(key)}`, token, { raw: true });
|
||||
if (text) {
|
||||
const parsed = agent.envTemplateSchema.safeParse(JSON.parse(text));
|
||||
if (parsed.success) template = parsed.data;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(`[env template] ${key}: ${e?.message || e}`);
|
||||
}
|
||||
template = template || (FALLBACK[product] ? agent.envTemplateSchema.parse(FALLBACK[product]) : null);
|
||||
if (template) cache.set(key, template);
|
||||
return template;
|
||||
}
|
||||
|
||||
/** What's missing for a release on a server: { server: [...], defaults: [...] }. */
|
||||
async function missingFor(product, version, serverValues, defaults) {
|
||||
const template = await envTemplate(product, version);
|
||||
if (!template) return { server: [], defaults: [] };
|
||||
return { server: agent.missingRequired(template, 'server', serverValues), defaults: agent.missingRequired(template, 'defaults', defaults) };
|
||||
}
|
||||
|
||||
module.exports = { envTemplate, missingFor, _cache: cache, getSettings };
|
||||
Reference in New Issue
Block a user