Files
stack/packages/bus/tests/shared-proxy-worker.mjs

16 lines
958 B
JavaScript

import { Credentials } from '../src/credentials.mjs';
import { ModelKeys } from '../src/model-keys.mjs';
import { createProxyLock } from '../src/proxy-lock.mjs';
import { ManagementClient } from '../../model-proxy/src/client.mjs';
import { join } from 'node:path';
const [root, configDir, baseUrl, org] = process.argv.slice(2);
const credentials = new Credentials({ storeRoot: join(root, org, 'secrets'), dataRoot: join(root, org), modelAgents: [`${org}/worker`] });
const client = new ManagementClient({ baseUrl, key: 'fixture-management', timeout: 5000 });
const lock = createProxyLock({ stateDir: join(root, 'proxy'), identity: `${configDir}:${new URL(baseUrl).port}` });
try {
const manager = new ModelKeys({ credentials, client, configDir, baseUrl, org, lock });
await manager.reconcile();
const answer = await manager.ensure(`${org}/worker`);
process.stdout.write(JSON.stringify({ key: answer.key }) + '\n');
} finally { credentials.close(); }