A convenient CLI tool to quickly spin up DragonflyBSD virtual machines using QEMU with sensible defaults.
1import machines from "./machines.ts";
2import images from "./images.ts";
3import volumes from "./volumes.ts";
4import { Hono } from "hono";
5import { logger } from "hono/logger";
6import { cors } from "hono/cors";
7import { bearerAuth } from "hono/bearer-auth";
8import { parseFlags } from "@cliffy/flags";
9
10export { images, machines, volumes };
11
12export default function () {
13 const token = Deno.env.get("DFLYBSD_UP_API_TOKEN") ||
14 crypto.randomUUID();
15 const { flags } = parseFlags(Deno.args);
16
17 if (!Deno.env.get("DFLYBSD_UP_API_TOKEN")) {
18 console.log(`Using API token: ${token}`);
19 } else {
20 console.log(
21 `Using provided API token from environment variable DFLYBSD_UP_API_TOKEN`,
22 );
23 }
24
25 const app = new Hono();
26
27 app.use(logger());
28 app.use(cors());
29
30 app.use("/images/*", bearerAuth({ token }));
31 app.use("/machines/*", bearerAuth({ token }));
32 app.use("/volumes/*", bearerAuth({ token }));
33
34 app.route("/images", images);
35 app.route("/machines", machines);
36 app.route("/volumes", volumes);
37
38 const port = Number(
39 flags.port || flags.p ||
40 (Deno.env.get("DFLYBSD_UP_PORT")
41 ? Number(Deno.env.get("DFLYBSD_UP_PORT"))
42 : 8893),
43 );
44
45 Deno.serve({ port }, app.fetch);
46}