import Fastify from 'fastify'; import cors from '@fastify/cors'; import { loadWhitelist } from './whitelist.js'; import { loadSecret, authHook } from './auth.js'; import { healthRoutes } from './routes/health.js'; import { execRoutes } from './routes/exec.js'; import { makeFlowRoutes } from './routes/flow.js'; const WHITELIST_PATH = process.env.OPS_AGENT_WHITELIST_PATH ?? '/etc/ops-agent/commands.yml'; const FLOWS_PATH = process.env.OPS_AGENT_FLOWS_PATH ?? '/etc/ops-agent/flows'; const PORT = parseInt(process.env.OPS_AGENT_PORT ?? '3099', 10); const HOST = process.env.OPS_AGENT_HOST ?? '127.0.0.1'; async function main() { loadWhitelist(WHITELIST_PATH); loadSecret(); const app = Fastify({ logger: true }); await app.register(cors, { origin: false }); app.addHook('onRequest', authHook); await app.register(healthRoutes); await app.register(execRoutes); await app.register(makeFlowRoutes(FLOWS_PATH)); await app.listen({ port: PORT, host: HOST }); console.log(`ops-agent listening on ${HOST}:${PORT}`); } main().catch((err) => { console.error(err); process.exit(1); });