@kvbox/cli 0.6.10 → 0.6.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kvbox.js +446 -288
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -155,7 +155,7 @@ async function spin(message, work, opts = {}) {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// src/program.ts
|
|
158
|
-
import { Command as
|
|
158
|
+
import { Command as Command131 } from "commander";
|
|
159
159
|
|
|
160
160
|
// ../shared/src/version.ts
|
|
161
161
|
import { createRequire } from "module";
|
|
@@ -170,10 +170,10 @@ function versionOf(srcFileUrl, injected) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// src/version.ts
|
|
173
|
-
var VERSION = versionOf(import.meta.url, true ? "0.6.
|
|
173
|
+
var VERSION = versionOf(import.meta.url, true ? "0.6.12" : void 0);
|
|
174
174
|
|
|
175
175
|
// src/commands/vm/index.ts
|
|
176
|
-
import { Command as
|
|
176
|
+
import { Command as Command39 } from "commander";
|
|
177
177
|
|
|
178
178
|
// src/commands/vm/connect.ts
|
|
179
179
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
@@ -438,6 +438,12 @@ var BackupSchema = z.object({
|
|
|
438
438
|
id: z.string(),
|
|
439
439
|
owner: z.string(),
|
|
440
440
|
box: z.string(),
|
|
441
|
+
/**
|
|
442
|
+
* The box it was taken of has been removed (#141): a box called `box` now is another box, which this backup
|
|
443
|
+
* never restores into; `kvbox new <name> --from-backup <id>` makes a box from it. Absent from a control plane
|
|
444
|
+
* before #141.
|
|
445
|
+
*/
|
|
446
|
+
boxRemoved: z.boolean().optional(),
|
|
441
447
|
status: z.enum(BACKUP_STATUSES),
|
|
442
448
|
/** Why it failed; null otherwise. */
|
|
443
449
|
error: z.string().nullable(),
|
|
@@ -616,7 +622,7 @@ var MachineSchema = z.object({
|
|
|
616
622
|
image: z.string().optional(),
|
|
617
623
|
createdAt: z.string(),
|
|
618
624
|
source: z.string(),
|
|
619
|
-
// "base", "snapshot:<owner/name>"
|
|
625
|
+
// "base", "snapshot:<owner/name>", "fork:<owner/name>" (#79) or "backup:<id>" (#141)
|
|
620
626
|
status: BoxStatusSchema,
|
|
621
627
|
/**
|
|
622
628
|
* Public TCP port on the host that reaches the box's SSH while it runs (#49). Only boxes made
|
|
@@ -826,8 +832,14 @@ var CreateMachineRequest = z.object({
|
|
|
826
832
|
/** The image to boot (#87, `kvbox new --base postgres`). Absent: the base image. */
|
|
827
833
|
image: z.string().optional(),
|
|
828
834
|
/** The box's own environment variables (#87, `kvbox new -e NAME=value`), over its owner's. */
|
|
829
|
-
env: z.array(z.object({ name: z.string(), value: z.string() })).optional()
|
|
835
|
+
env: z.array(z.object({ name: z.string(), value: z.string() })).optional(),
|
|
836
|
+
/**
|
|
837
|
+
* Start the box on this backup's disk (#141, `kvbox new --from-backup <id>`), a removed box's too: its image,
|
|
838
|
+
* version and variables come from the backup, its size too unless given. Only the control plane reads it.
|
|
839
|
+
*/
|
|
840
|
+
fromBackup: z.string().optional()
|
|
830
841
|
});
|
|
842
|
+
var HostFromBackupRequest = CreateMachineRequest.omit({ from: true, fromBackup: true, image: true, env: true }).extend({ backup: HostRestoreRequest });
|
|
831
843
|
var ForkMachineRequest = z.object({
|
|
832
844
|
name: z.string().optional(),
|
|
833
845
|
/**
|
|
@@ -896,6 +908,11 @@ var CapacitySchema = z.object({
|
|
|
896
908
|
reservedMemMib: z.number().int(),
|
|
897
909
|
reservedVcpu: z.number().int(),
|
|
898
910
|
running: z.number().int(),
|
|
911
|
+
/**
|
|
912
|
+
* MiB of RAM the host keeps back from its boxes (config.json `memHeadroomMib`). Absent on a kvbox-server
|
|
913
|
+
* from before the setting, which keeps 2 GB (`OLD_HOST_MEM_HEADROOM_MIB`).
|
|
914
|
+
*/
|
|
915
|
+
memHeadroomMib: z.number().int().optional(),
|
|
899
916
|
/** Absent on a host from before volumes (#91): it cannot take one. */
|
|
900
917
|
disk: DiskCapacitySchema.optional(),
|
|
901
918
|
/**
|
|
@@ -908,7 +925,9 @@ var CapacitySchema = z.object({
|
|
|
908
925
|
/** Present on a host set up as a backup store: the disk its Garage keeps chunks on, and whether Garage runs. */
|
|
909
926
|
backupStore: z.object({ totalBytes: z.number().int(), freeBytes: z.number().int(), running: z.boolean() }).optional(),
|
|
910
927
|
/** True on a kvbox-server that reaches a backup store by its certificate's `pin`; older ones omit it and cannot back up to a store. */
|
|
911
|
-
storeClient: z.boolean().optional()
|
|
928
|
+
storeClient: z.boolean().optional(),
|
|
929
|
+
/** True on a kvbox-server with `POST /machines/from-backup` (#141, `kvbox new --from-backup`); older ones omit it. */
|
|
930
|
+
fromBackup: z.boolean().optional()
|
|
912
931
|
});
|
|
913
932
|
var ImageSchema = z.object({ name: z.string(), version: z.string().nullable() });
|
|
914
933
|
var ImageIndexSchema = z.object({
|
|
@@ -1691,6 +1710,7 @@ var FORK_TIMEOUT_MS = 66e4;
|
|
|
1691
1710
|
var listQuery = (opts) => opts.all ? "?all=1" : "";
|
|
1692
1711
|
var box = (name, rest = "") => `/machines/${encodeURIComponent(name)}${rest}`;
|
|
1693
1712
|
var sleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
1713
|
+
var FROM_BACKUP_TIMEOUT_MS = 2 * 36e5;
|
|
1694
1714
|
var passing = (err) => err instanceof KvboxConnectionError || err instanceof KvboxTimeoutError || err instanceof KvboxApiError && [502, 503, 504].includes(err.status);
|
|
1695
1715
|
var Machines = class {
|
|
1696
1716
|
constructor(transport) {
|
|
@@ -1734,9 +1754,15 @@ var Machines = class {
|
|
|
1734
1754
|
* system inside is still booting for a few seconds after (see `waitUntilReady`). A box from an
|
|
1735
1755
|
* image that serves something answers `connect` (its URL with the password) this once.
|
|
1736
1756
|
* `org` (this call's, else the client's): the new box goes to that org, else to the caller's own slug.
|
|
1757
|
+
* `fromBackup` (a backup's id, a removed box's too) starts it on that backup's disk, image and variables;
|
|
1758
|
+
* the answer then waits for the download, up to two hours.
|
|
1737
1759
|
*/
|
|
1738
|
-
create(req = {}, opts = {}) {
|
|
1739
|
-
|
|
1760
|
+
async create(req = {}, opts = {}) {
|
|
1761
|
+
const made = await this.transport.request("POST", "/machines", MachineSchema, { body: req, org: opts.org, ...req.fromBackup !== void 0 ? { timeoutMs: FROM_BACKUP_TIMEOUT_MS } : {} });
|
|
1762
|
+
if (req.fromBackup !== void 0 && !made.source.startsWith("backup:")) {
|
|
1763
|
+
throw new KvboxSdkError(`this API does not know fromBackup yet: box ${slugOf2(made.owner)}/${made.name} was made empty, not from backup ${req.fromBackup}; remove it`);
|
|
1764
|
+
}
|
|
1765
|
+
return made;
|
|
1740
1766
|
}
|
|
1741
1767
|
/** Remove the box and its disk. */
|
|
1742
1768
|
async remove(name, opts = {}) {
|
|
@@ -2364,6 +2390,8 @@ var cronTarget = (t) => t.kind === "command" ? `${t.box}$ ${t.command}` : `${t.m
|
|
|
2364
2390
|
// ../shared/src/storage.ts
|
|
2365
2391
|
import { z as z10 } from "zod";
|
|
2366
2392
|
var RegionSchema = z10.object({ name: z10.string(), country: z10.string().nullable() });
|
|
2393
|
+
var MAX_PUBLIC_BUCKETS = 10;
|
|
2394
|
+
var STORAGE_BOX_SUBDOMAINS = MAX_PUBLIC_BUCKETS + 2;
|
|
2367
2395
|
var ObjectStorageSchema = z10.object({
|
|
2368
2396
|
owner: z10.string(),
|
|
2369
2397
|
ownerKind: z10.enum(["user", "org"]),
|
|
@@ -2391,6 +2419,7 @@ var BucketSchema = z10.object({
|
|
|
2391
2419
|
owner: z10.string(),
|
|
2392
2420
|
ownerKind: z10.enum(["user", "org"]),
|
|
2393
2421
|
endpoint: z10.string().nullable(),
|
|
2422
|
+
publicUrl: z10.string().optional(),
|
|
2394
2423
|
region: z10.string(),
|
|
2395
2424
|
keys: z10.number().int(),
|
|
2396
2425
|
objects: z10.number().optional(),
|
|
@@ -2406,6 +2435,7 @@ var CreateBucketRequest = z10.object({
|
|
|
2406
2435
|
});
|
|
2407
2436
|
var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z10.boolean() });
|
|
2408
2437
|
var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
|
|
2438
|
+
var SetBucketPublicRequest = z10.object({ on: z10.boolean(), sub: z10.string().optional() });
|
|
2409
2439
|
var BucketKeySchema = z10.object({
|
|
2410
2440
|
id: z10.string(),
|
|
2411
2441
|
name: z10.string(),
|
|
@@ -2676,7 +2706,7 @@ var ServerClient = class {
|
|
|
2676
2706
|
return this.call("GET", `/machines${allQuery(opts)}`, z11.array(MachineSchema), void 0, opts.org);
|
|
2677
2707
|
}
|
|
2678
2708
|
createMachine(req) {
|
|
2679
|
-
return this.call("POST", "/machines", MachineSchema, req);
|
|
2709
|
+
return this.call("POST", "/machines", MachineSchema, req, void 0, req.fromBackup !== void 0 ? 2 * 36e5 : void 0);
|
|
2680
2710
|
}
|
|
2681
2711
|
/** `kvbox vm fork` (#79): `name` is the source; the copy goes to the `--org` slug, else the caller's own. */
|
|
2682
2712
|
forkMachine(name, req) {
|
|
@@ -2940,6 +2970,10 @@ var ServerClient = class {
|
|
|
2940
2970
|
getBucket(name) {
|
|
2941
2971
|
return this.call("GET", `/buckets/${encodeURIComponent(name)}`, BucketInfoSchema);
|
|
2942
2972
|
}
|
|
2973
|
+
/** Make every object of the bucket readable by anyone at its own address (#191), or private again. */
|
|
2974
|
+
setBucketPublic(name, req) {
|
|
2975
|
+
return this.call("PUT", `/buckets/${encodeURIComponent(name)}/public`, BucketSchema, req);
|
|
2976
|
+
}
|
|
2943
2977
|
deleteBucket(name, force = false) {
|
|
2944
2978
|
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z11.undefined());
|
|
2945
2979
|
}
|
|
@@ -3531,12 +3565,20 @@ function parseDuration(text2) {
|
|
|
3531
3565
|
}
|
|
3532
3566
|
|
|
3533
3567
|
// src/commands/vm/new.ts
|
|
3534
|
-
var newCommand = new Command("new").description("boot a new box from an image (the base one, or e.g. postgres) or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-b, --base <image>", "the image to boot: base (default) or one the host has, e.g. postgres").option("-e, --env <NAME=value>", "a variable of the box's own, over yours (repeatable; change later with kvbox env set --box)", collect, []).option("-f, --from <snapshot>", "start from a snapshot instead of an image").option("--near <box>", "put it on the same host as this box, so the two can be linked (kvbox vm link)").option("--country <country>", "put it on a host in this country, a name or a code, e.g. romania or US").addOption(new Option("--host <name>", "put it on this host and no other (admins only)").hideHelp()).option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
3568
|
+
var newCommand = new Command("new").description("boot a new box from an image (the base one, or e.g. postgres) or a snapshot").argument("[name]", "box name (box1, box2, \u2026 when omitted)").addOption(new Option("-s, --size <size>", "box size (default: server config, s)").choices(SIZE_NAMES)).option("-b, --base <image>", "the image to boot: base (default) or one the host has, e.g. postgres").option("-e, --env <NAME=value>", "a variable of the box's own, over yours (repeatable; change later with kvbox env set --box)", collect, []).option("-f, --from <snapshot>", "start from a snapshot instead of an image").option("--from-backup <id>", "start on a backup's disk, a removed box's too (kvbox vm backup ls); image, variables and size come from it").option("--near <box>", "put it on the same host as this box, so the two can be linked (kvbox vm link)").option("--country <country>", "put it on a host in this country, a name or a code, e.g. romania or US").addOption(new Option("--host <name>", "put it on this host and no other (admins only)").hideHelp()).option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never; default: server config, off)").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
3535
3569
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
3536
3570
|
const env = parseEnvFlags(opts.env);
|
|
3537
3571
|
const country = opts.country === void 0 ? void 0 : parseCountry(opts.country);
|
|
3538
3572
|
if (country !== void 0 && opts.from !== void 0) throw new KvboxError("--country cannot be given with --from: a snapshot is restored on its own host");
|
|
3573
|
+
if (opts.fromBackup !== void 0) {
|
|
3574
|
+
const clash = opts.from !== void 0 ? "--from" : opts.base !== void 0 ? "--base" : env.length > 0 ? "-e" : null;
|
|
3575
|
+
if (clash) throw new KvboxError(`a box from a backup takes its image and variables from the backup; ${clash} cannot be given with --from-backup`);
|
|
3576
|
+
}
|
|
3539
3577
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3578
|
+
if (opts.fromBackup !== void 0 && client.target.kind !== "cloud") {
|
|
3579
|
+
await client.close();
|
|
3580
|
+
throw new KvboxError("backups are kept by the control plane; this machine has none (kvbox login first)");
|
|
3581
|
+
}
|
|
3540
3582
|
if (country !== void 0 && client.target.kind !== "cloud") {
|
|
3541
3583
|
await client.close();
|
|
3542
3584
|
throw new KvboxError("--country picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
@@ -3546,11 +3588,12 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
3546
3588
|
throw new KvboxError("--host picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
3547
3589
|
}
|
|
3548
3590
|
try {
|
|
3549
|
-
const what = opts.from !== void 0 ? `restoring ${name ?? "a new box"} from snapshot ${opts.from}\u2026` : `booting ${name ?? "a new box"}${opts.base !== void 0 && opts.base !== "base" ? ` from image ${opts.base}` : ""}\u2026`;
|
|
3591
|
+
const what = opts.fromBackup !== void 0 ? `restoring ${name ?? "a new box"} from backup ${opts.fromBackup}\u2026` : opts.from !== void 0 ? `restoring ${name ?? "a new box"} from snapshot ${opts.from}\u2026` : `booting ${name ?? "a new box"}${opts.base !== void 0 && opts.base !== "base" ? ` from image ${opts.base}` : ""}\u2026`;
|
|
3550
3592
|
const box2 = await spin(what, client.createMachine({
|
|
3551
3593
|
...name !== void 0 ? { name } : {},
|
|
3552
3594
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
3553
3595
|
...opts.from !== void 0 ? { from: opts.from } : {},
|
|
3596
|
+
...opts.fromBackup !== void 0 ? { fromBackup: opts.fromBackup } : {},
|
|
3554
3597
|
...opts.base !== void 0 ? { image: opts.base } : {},
|
|
3555
3598
|
...env.length > 0 ? { env } : {},
|
|
3556
3599
|
...opts.near !== void 0 ? { near: opts.near } : {},
|
|
@@ -3559,6 +3602,9 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
3559
3602
|
...autoHibernateSec !== void 0 ? { autoHibernateSec } : {},
|
|
3560
3603
|
...opts.force ? { force: true } : {}
|
|
3561
3604
|
}));
|
|
3605
|
+
if (opts.fromBackup !== void 0 && !box2.source.startsWith("backup:")) {
|
|
3606
|
+
throw new KvboxError(`this control plane does not know --from-backup yet: box ${box2.name} was made empty, not from backup ${opts.fromBackup}; remove it with: kvbox rm ${displayName(box2, me(client))}`);
|
|
3607
|
+
}
|
|
3562
3608
|
if (autoHibernateSec && !box2.autoHibernateSec) warn(`box ${name ?? box2.name}: its host runs a kvbox-server too old for auto-hibernate; it will not hibernate on its own`);
|
|
3563
3609
|
if (opts.base !== void 0 && opts.base !== "base" && box2.image === void 0) {
|
|
3564
3610
|
warn(`box ${box2.name}: its host runs a kvbox-server too old for images; it booted the base image, not ${opts.base}`);
|
|
@@ -3577,6 +3623,7 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
3577
3623
|
`);
|
|
3578
3624
|
info(`${color.green("\u2713")} ${describe(box2, user)}`);
|
|
3579
3625
|
if (opts.from !== void 0) info(` connect with: kvbox connect ${displayName(box2, user)} (already up: everything that ran in the snapshot is running)`);
|
|
3626
|
+
else if (opts.fromBackup !== void 0) info(` connect with: kvbox connect ${displayName(box2, user)} (booting on the backup's disk: SSH is up a couple of seconds after)`);
|
|
3580
3627
|
else info(` connect with: kvbox connect ${displayName(box2, user)} (SSH is up a couple of seconds after boot)`);
|
|
3581
3628
|
if (box2.autoHibernateSec) info(` it ${autoHibernateText(box2.autoHibernateSec, box2.idleCheck)}`);
|
|
3582
3629
|
if (box2.connect !== void 0) {
|
|
@@ -3724,25 +3771,25 @@ async function runSsh(ssh, opts) {
|
|
|
3724
3771
|
}).finally(() => clearTimeout(timer));
|
|
3725
3772
|
return { status: status2, chunks, timedOut };
|
|
3726
3773
|
}
|
|
3727
|
-
|
|
3728
|
-
const client = await clientFor(
|
|
3729
|
-
let ep;
|
|
3730
|
-
let cert;
|
|
3731
|
-
let owner;
|
|
3774
|
+
async function reachBox(globals, name, direct) {
|
|
3775
|
+
const client = await clientFor(globals);
|
|
3732
3776
|
try {
|
|
3733
3777
|
let box2 = pickRef(await boxesFor(client, name), name, me(client));
|
|
3734
3778
|
if (!box2) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
3735
3779
|
if (box2.status === "stopped") throw new KvboxError(`box ${name} is stopped (kvbox start ${name})`);
|
|
3736
|
-
cert = await ensureCert(client, void 0, void 0, { owner: box2.owner });
|
|
3737
|
-
owner = box2.owner;
|
|
3780
|
+
const cert = await ensureCert(client, void 0, void 0, { owner: box2.owner });
|
|
3738
3781
|
const wasRunning = box2.status === "running";
|
|
3739
3782
|
if (!wasRunning) box2 = await wakeUp(client, box2, displayName(box2, me(client)));
|
|
3740
|
-
ep = sshEndpoint(box2, client.target,
|
|
3783
|
+
const ep = sshEndpoint(box2, client.target, direct);
|
|
3741
3784
|
if (!wasRunning) await spin(`waiting for ${name} to accept SSH\u2026`, waitForSsh(ep));
|
|
3742
|
-
else if (
|
|
3785
|
+
else if (direct) await checkDirect(ep);
|
|
3786
|
+
return { ep, cert, owner: box2.owner };
|
|
3743
3787
|
} finally {
|
|
3744
3788
|
await client.close();
|
|
3745
3789
|
}
|
|
3790
|
+
}
|
|
3791
|
+
var execCommand = new Command3("exec").description("run a command in a box and exit with its status (kvbox exec <name> -- <cmd>)").argument("<name>", "box name").argument("<cmd...>", "command, passed to the box's shell as one string (pipes, &&, cd work)").option("-e, --env <KEY=VALUE>", "set an environment variable for the command (repeatable)", collect2).option("--timeout <seconds>", "kill the command after N seconds and exit 124", positiveSeconds).option("--tty", "allocate a pseudo-terminal (for interactive tools like htop)").option("--json", 'capture output and print {"output": "...", "exit_code": N}').option("--direct", "on the box's host: ssh to the box's private ip, not through the public address or relay").action(async (name, cmdArgs, opts, cmd) => {
|
|
3792
|
+
const { ep, cert, owner } = await reachBox(cmd.optsWithGlobals(), name, opts.direct);
|
|
3746
3793
|
const remote = remoteCommand(cmdArgs, opts.env ?? []);
|
|
3747
3794
|
const stdinIsTty = process.stdin.isTTY === true;
|
|
3748
3795
|
const ssh = [
|
|
@@ -3773,9 +3820,66 @@ var execCommand = new Command3("exec").description("run a command in a box and e
|
|
|
3773
3820
|
process.exit(status2);
|
|
3774
3821
|
});
|
|
3775
3822
|
|
|
3823
|
+
// src/commands/vm/cp.ts
|
|
3824
|
+
import { spawn as spawn3 } from "child_process";
|
|
3825
|
+
import { Command as Command4 } from "commander";
|
|
3826
|
+
function parseSide(arg, platform = process.platform) {
|
|
3827
|
+
if (platform === "win32" && /^[A-Za-z]:[\\/]/.test(arg)) return { box: void 0, path: arg };
|
|
3828
|
+
const m = /^([^/:\\]+(?:\/[^/:\\]+)?):(.*)$/s.exec(arg);
|
|
3829
|
+
if (!m || arg.startsWith("./") || arg.startsWith("../")) return { box: void 0, path: arg };
|
|
3830
|
+
return { box: m[1], path: m[2] };
|
|
3831
|
+
}
|
|
3832
|
+
function parseCopy(src, dest, platform = process.platform) {
|
|
3833
|
+
const from = parseSide(src, platform);
|
|
3834
|
+
const to = parseSide(dest, platform);
|
|
3835
|
+
if (from.box !== void 0 && to.box !== void 0) {
|
|
3836
|
+
throw new KvboxError("both sides are in a box: copy between this machine and one box (kvbox cp <file> <box>:<path>)");
|
|
3837
|
+
}
|
|
3838
|
+
const box2 = from.box ?? to.box;
|
|
3839
|
+
if (box2 === void 0) {
|
|
3840
|
+
throw new KvboxError("neither side is in a box: write the box side as <box>:<path> (kvbox cp ./app.apk dev:app.apk)");
|
|
3841
|
+
}
|
|
3842
|
+
return { box: box2, from, to };
|
|
3843
|
+
}
|
|
3844
|
+
function scpArgs(ep, from, to, recursive) {
|
|
3845
|
+
const ssh = sshArgs(ep);
|
|
3846
|
+
const options = ssh.slice(0, -1).map((a) => a === "-p" ? "-P" : a);
|
|
3847
|
+
const host = ep.host.includes(":") ? `[${ep.host}]` : ep.host;
|
|
3848
|
+
const side = (s) => s.box === void 0 ? s.path : `${ep.user}@${host}:${s.path === "" ? "." : s.path}`;
|
|
3849
|
+
return [...recursive ? ["-r"] : [], ...options, side(from), side(to)];
|
|
3850
|
+
}
|
|
3851
|
+
async function runScp(args) {
|
|
3852
|
+
const child = spawn3("scp", args, { stdio: ["inherit", "inherit", "pipe"] });
|
|
3853
|
+
let refused = false;
|
|
3854
|
+
child.stderr?.on("data", (c2) => {
|
|
3855
|
+
process.stderr.write(c2);
|
|
3856
|
+
if (c2.toString("utf8").includes("Permission denied")) refused = true;
|
|
3857
|
+
});
|
|
3858
|
+
const status2 = await new Promise((resolve4, reject) => {
|
|
3859
|
+
child.once("error", (err) => reject(new KvboxError(`could not run scp: ${err.message}`)));
|
|
3860
|
+
child.once("close", (code, signal) => resolve4(code ?? (signal === "SIGINT" ? 130 : 1)));
|
|
3861
|
+
});
|
|
3862
|
+
return { status: status2, refused };
|
|
3863
|
+
}
|
|
3864
|
+
var cpCommand = new Command4("cp").description("copy files between this machine and a box (kvbox cp ./f <box>:f, kvbox cp <box>:f .)").argument("<src>", "a local path, or <box>:<path>").argument("<dest>", "a local path, or <box>:<path>").option("-r, --recursive", "copy directories").option("--direct", "on the box's host: ssh to the box's private ip, not through the public address or relay").action(async (src, dest, opts, cmd) => {
|
|
3865
|
+
const { box: box2, from, to } = parseCopy(src, dest);
|
|
3866
|
+
const { ep, cert, owner } = await reachBox(cmd.optsWithGlobals(), box2, opts.direct);
|
|
3867
|
+
const args = scpArgs(ep, from, to, opts.recursive === true);
|
|
3868
|
+
const first = await runScp(args);
|
|
3869
|
+
let status2 = first.status;
|
|
3870
|
+
if (status2 !== 0 && first.refused) {
|
|
3871
|
+
const again = await clientFor(cmd.optsWithGlobals());
|
|
3872
|
+
if (await renewAfterRefusal(again, cert, owner).finally(() => again.close())) {
|
|
3873
|
+
info("renewed your SSH certificate, trying again\u2026");
|
|
3874
|
+
({ status: status2 } = await runScp(args));
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
if (status2 !== 0) process.exit(status2);
|
|
3878
|
+
});
|
|
3879
|
+
|
|
3776
3880
|
// src/commands/vm/fork.ts
|
|
3777
|
-
import { Command as
|
|
3778
|
-
var forkCommand = new
|
|
3881
|
+
import { Command as Command5, Option as Option2 } from "commander";
|
|
3882
|
+
var forkCommand = new Command5("fork").description("copy a box, running or stopped, into a new one on the same host (--org: into an org)").argument("<box>", "the box to copy").argument("[name]", "the copy's name (box1, box2, \u2026 when omitted)").addOption(new Option2("-s, --size <size>", "the copy's size, for a stopped box only (default: the box's)").choices(SIZE_NAMES)).option("--auto-hibernate <duration>", "hibernate the copy after this long without network traffic (30m, 4h, 1d; off: never; default: the box's)").option("--force", "skip the capacity guard").option("--json", "print the new box as JSON").action(async (source, name, opts, cmd) => {
|
|
3779
3883
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
3780
3884
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3781
3885
|
try {
|
|
@@ -3801,10 +3905,10 @@ var forkCommand = new Command4("fork").description("copy a box, running or stopp
|
|
|
3801
3905
|
});
|
|
3802
3906
|
|
|
3803
3907
|
// src/commands/vm/get.ts
|
|
3804
|
-
import { Command as
|
|
3908
|
+
import { Command as Command7 } from "commander";
|
|
3805
3909
|
|
|
3806
3910
|
// src/commands/vm/ls.ts
|
|
3807
|
-
import { Command as
|
|
3911
|
+
import { Command as Command6 } from "commander";
|
|
3808
3912
|
function ownerCell(b, me2) {
|
|
3809
3913
|
const slug = slugOf(b.owner);
|
|
3810
3914
|
if (slug === me2) return "private";
|
|
@@ -3814,7 +3918,7 @@ function addressOf(b) {
|
|
|
3814
3918
|
if (b.ssh !== void 0) return b.ssh.host;
|
|
3815
3919
|
return b.ip === "" ? "-" : b.ip;
|
|
3816
3920
|
}
|
|
3817
|
-
var lsCommand = new
|
|
3921
|
+
var lsCommand = new Command6("ls").description("list boxes with status and address (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
3818
3922
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3819
3923
|
try {
|
|
3820
3924
|
const cloud = client.target.kind === "cloud";
|
|
@@ -3886,7 +3990,7 @@ async function findBox(client, text2) {
|
|
|
3886
3990
|
}
|
|
3887
3991
|
|
|
3888
3992
|
// src/commands/vm/get.ts
|
|
3889
|
-
var getCommand = new
|
|
3993
|
+
var getCommand = new Command7("get").description("show one box in full: status, size, address, HTTPS name, ports, auto-hibernate").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
3890
3994
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3891
3995
|
try {
|
|
3892
3996
|
const user = me(client);
|
|
@@ -3939,8 +4043,8 @@ function getRows(box2, subs, user) {
|
|
|
3939
4043
|
}
|
|
3940
4044
|
|
|
3941
4045
|
// src/commands/vm/hibernate.ts
|
|
3942
|
-
import { Command as
|
|
3943
|
-
var hibernateCommand = new
|
|
4046
|
+
import { Command as Command8 } from "commander";
|
|
4047
|
+
var hibernateCommand = new Command8("hibernate").description("save a box's memory to disk and free its RAM (kvbox wake continues it where it left off)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
3944
4048
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3945
4049
|
try {
|
|
3946
4050
|
const box2 = await spin(`hibernating ${name} (saving its memory to disk)\u2026`, client.hibernateMachine(name));
|
|
@@ -3952,13 +4056,13 @@ var hibernateCommand = new Command7("hibernate").description("save a box's memor
|
|
|
3952
4056
|
});
|
|
3953
4057
|
|
|
3954
4058
|
// src/commands/vm/link.ts
|
|
3955
|
-
import { Command as
|
|
4059
|
+
import { Command as Command9 } from "commander";
|
|
3956
4060
|
function parseLinkPort(text2) {
|
|
3957
4061
|
const port = Number(text2);
|
|
3958
4062
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new KvboxError(`--port: expected a port from 1 to 65535, got "${text2}"`);
|
|
3959
4063
|
return port;
|
|
3960
4064
|
}
|
|
3961
|
-
var linkCommand = new
|
|
4065
|
+
var linkCommand = new Command9("link").description("let one box reach a port of another (private, same host; never public)").argument("<from>", "the box that connects").argument("<box>", "the box it may reach").requiredOption("-p, --port <port>", "the port in <box>").option("--json", "print the link as JSON").action(async (from, name, opts, cmd) => {
|
|
3962
4066
|
const port = parseLinkPort(opts.port);
|
|
3963
4067
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3964
4068
|
try {
|
|
@@ -3981,8 +4085,8 @@ var linkCommand = new Command8("link").description("let one box reach a port of
|
|
|
3981
4085
|
});
|
|
3982
4086
|
|
|
3983
4087
|
// src/commands/vm/links.ts
|
|
3984
|
-
import { Command as
|
|
3985
|
-
var linksCommand = new
|
|
4088
|
+
import { Command as Command10 } from "commander";
|
|
4089
|
+
var linksCommand = new Command10("links").description("list the links between boxes (kvbox vm link)").argument("[box]", "only links into or out of this box").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
3986
4090
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
3987
4091
|
try {
|
|
3988
4092
|
const user = me(client);
|
|
@@ -4015,8 +4119,8 @@ var linksCommand = new Command9("links").description("list the links between box
|
|
|
4015
4119
|
});
|
|
4016
4120
|
|
|
4017
4121
|
// src/commands/vm/pause.ts
|
|
4018
|
-
import { Command as
|
|
4019
|
-
var pauseCommand = new
|
|
4122
|
+
import { Command as Command11 } from "commander";
|
|
4123
|
+
var pauseCommand = new Command11("pause").description("freeze a box in place (memory and processes kept, no CPU used; kvbox resume continues it instantly)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4020
4124
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4021
4125
|
try {
|
|
4022
4126
|
const box2 = await spin(`pausing ${name}\u2026`, client.pauseMachine(name));
|
|
@@ -4028,7 +4132,7 @@ var pauseCommand = new Command10("pause").description("freeze a box in place (me
|
|
|
4028
4132
|
});
|
|
4029
4133
|
|
|
4030
4134
|
// src/commands/vm/proxy/claim.ts
|
|
4031
|
-
import { Command as
|
|
4135
|
+
import { Command as Command12 } from "commander";
|
|
4032
4136
|
|
|
4033
4137
|
// ../shared/src/names.ts
|
|
4034
4138
|
import { createHmac } from "crypto";
|
|
@@ -4099,7 +4203,7 @@ function assertDomain(text2, proxyDomain) {
|
|
|
4099
4203
|
}
|
|
4100
4204
|
|
|
4101
4205
|
// src/commands/vm/proxy/claim.ts
|
|
4102
|
-
var claimCommand = new
|
|
4206
|
+
var claimCommand = new Command12("claim").description(`give a box an HTTPS address, https://<subdomain>.kvbox.app, serving one of its ports (up to ${MAX_BOX_SUBDOMAINS} per box)`).argument("[box]", "box name (picked from a list when left out)").argument("[subdomain]", "3-63 lowercase letters, digits and '-'; must be free (asked for when left out)").option("--port <port>", "the box port the address serves (asked for when left out)").option("--json", "print the subdomain as JSON").action(async (nameArg, subArg, opts, cmd) => {
|
|
4103
4207
|
if (nameArg === void 0 || subArg === void 0 || opts.port === void 0) askOrUsage("give the box, the subdomain and the port: kvbox vm proxy claim <box> <subdomain> --port <port>");
|
|
4104
4208
|
if (subArg !== void 0) assertSubdomain(subArg);
|
|
4105
4209
|
if (opts.port !== void 0) parsePorts([opts.port]);
|
|
@@ -4128,11 +4232,11 @@ var claimCommand = new Command11("claim").description(`give a box an HTTPS addre
|
|
|
4128
4232
|
});
|
|
4129
4233
|
|
|
4130
4234
|
// src/commands/vm/proxy/index.ts
|
|
4131
|
-
import { Command as
|
|
4235
|
+
import { Command as Command18 } from "commander";
|
|
4132
4236
|
|
|
4133
4237
|
// src/commands/vm/proxy/add.ts
|
|
4134
|
-
import { Command as
|
|
4135
|
-
var addCommand = new
|
|
4238
|
+
import { Command as Command13 } from "commander";
|
|
4239
|
+
var addCommand = new Command13("add").description("publish box ports on the internet; each gets a random public port, or an HTTPS name with --name").argument("<box>", "box name").argument("<port...>", "ports inside the box, e.g. 3000 8080").option("--udp", "UDP instead of TCP").option("--name <name>", "serve the port at https://<name>.<subdomain>.kvbox.app (one port; needs kvbox vm proxy claim first)").option("--sub <subdomain>", "with --name: which of the box's subdomains it goes under (needed when it has more than one)").option("--json", "print the new forwards as JSON").action(async (name, portTexts, opts, cmd) => {
|
|
4136
4240
|
const guestPorts = parsePorts(portTexts);
|
|
4137
4241
|
if (opts.name !== void 0) {
|
|
4138
4242
|
assertRouteName(opts.name);
|
|
@@ -4175,7 +4279,7 @@ var addCommand = new Command12("add").description("publish box ports on the inte
|
|
|
4175
4279
|
});
|
|
4176
4280
|
|
|
4177
4281
|
// src/commands/vm/proxy/ls.ts
|
|
4178
|
-
import { Command as
|
|
4282
|
+
import { Command as Command14 } from "commander";
|
|
4179
4283
|
async function subdomainsOf2(client) {
|
|
4180
4284
|
try {
|
|
4181
4285
|
return await client.listSubdomains();
|
|
@@ -4184,7 +4288,7 @@ async function subdomainsOf2(client) {
|
|
|
4184
4288
|
return [];
|
|
4185
4289
|
}
|
|
4186
4290
|
}
|
|
4187
|
-
var lsCommand2 = new
|
|
4291
|
+
var lsCommand2 = new Command14("ls").description("list the box ports published on the internet").argument("[box]", "only this box").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4188
4292
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4189
4293
|
try {
|
|
4190
4294
|
const user = me(client);
|
|
@@ -4210,8 +4314,8 @@ var lsCommand2 = new Command13("ls").description("list the box ports published o
|
|
|
4210
4314
|
});
|
|
4211
4315
|
|
|
4212
4316
|
// src/commands/vm/proxy/release.ts
|
|
4213
|
-
import { Command as
|
|
4214
|
-
var releaseCommand = new
|
|
4317
|
+
import { Command as Command15 } from "commander";
|
|
4318
|
+
var releaseCommand = new Command15("release").description("give up one of a box's HTTPS addresses and every name under it").argument("<box>", "box name").option("--sub <subdomain>", "which of the box's subdomains (needed when it has more than one)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
4215
4319
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4216
4320
|
try {
|
|
4217
4321
|
requireCloud(client);
|
|
@@ -4230,8 +4334,8 @@ var releaseCommand = new Command14("release").description("give up one of a box'
|
|
|
4230
4334
|
});
|
|
4231
4335
|
|
|
4232
4336
|
// src/commands/vm/proxy/rm.ts
|
|
4233
|
-
import { Command as
|
|
4234
|
-
var rmCommand = new
|
|
4337
|
+
import { Command as Command16 } from "commander";
|
|
4338
|
+
var rmCommand = new Command16("rm").description("stop publishing box ports, or an HTTPS name with --name").argument("<box>", "box name").argument("[port...]", "ports inside the box, as given to add").option("--udp", "the UDP forwards of those ports").option("--name <name>", "the HTTPS name to free (kvbox vm proxy release frees the whole subdomain)").option("--sub <subdomain>", "with --name: which of the box's subdomains the name is under (needed when it has more than one)").option("-y, --yes", "do not ask for confirmation").action(async (name, portTexts, opts, cmd) => {
|
|
4235
4339
|
if (opts.name !== void 0) {
|
|
4236
4340
|
assertRouteName(opts.name);
|
|
4237
4341
|
if (portTexts.length > 0) throw new KvboxError("--name frees a name, not ports: kvbox vm proxy rm <box> --name <name>");
|
|
@@ -4265,8 +4369,8 @@ var rmCommand = new Command15("rm").description("stop publishing box ports, or a
|
|
|
4265
4369
|
});
|
|
4266
4370
|
|
|
4267
4371
|
// src/commands/vm/proxy/set-port.ts
|
|
4268
|
-
import { Command as
|
|
4269
|
-
var setPortCommand = new
|
|
4372
|
+
import { Command as Command17 } from "commander";
|
|
4373
|
+
var setPortCommand = new Command17("set-port").description("point a box's HTTPS address at another of its ports").argument("<box>", "box name").argument("<port>", "the box port https://<subdomain>.kvbox.app serves from now on").option("--sub <subdomain>", "which of the box's subdomains (needed when it has more than one)").option("--json", "print the subdomain as JSON").action(async (name, portText, opts, cmd) => {
|
|
4270
4374
|
const [port] = parsePorts([portText]);
|
|
4271
4375
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4272
4376
|
try {
|
|
@@ -4284,14 +4388,14 @@ var setPortCommand = new Command16("set-port").description("point a box's HTTPS
|
|
|
4284
4388
|
});
|
|
4285
4389
|
|
|
4286
4390
|
// src/commands/vm/proxy/index.ts
|
|
4287
|
-
var proxyCommand = new
|
|
4391
|
+
var proxyCommand = new Command18("proxy").description("publish box ports on the internet").addCommand(addCommand).addCommand(lsCommand2).addCommand(rmCommand).addCommand(claimCommand).addCommand(setPortCommand).addCommand(releaseCommand);
|
|
4288
4392
|
for (const cmd of proxyCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4289
4393
|
|
|
4290
4394
|
// src/commands/vm/hook/index.ts
|
|
4291
|
-
import { Command as
|
|
4395
|
+
import { Command as Command22 } from "commander";
|
|
4292
4396
|
|
|
4293
4397
|
// src/commands/vm/hook/create.ts
|
|
4294
|
-
import { Command as
|
|
4398
|
+
import { Command as Command19 } from "commander";
|
|
4295
4399
|
|
|
4296
4400
|
// src/commands/vm/hook/shared.ts
|
|
4297
4401
|
function requireCloud2(client) {
|
|
@@ -4299,7 +4403,7 @@ function requireCloud2(client) {
|
|
|
4299
4403
|
}
|
|
4300
4404
|
|
|
4301
4405
|
// src/commands/vm/hook/create.ts
|
|
4302
|
-
var createCommand = new
|
|
4406
|
+
var createCommand = new Command19("create").description("make a URL that wakes the box when called (a GitHub webhook, cron, any automation)").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4303
4407
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4304
4408
|
try {
|
|
4305
4409
|
requireCloud2(client);
|
|
@@ -4323,8 +4427,8 @@ var createCommand = new Command18("create").description("make a URL that wakes t
|
|
|
4323
4427
|
});
|
|
4324
4428
|
|
|
4325
4429
|
// src/commands/vm/hook/ls.ts
|
|
4326
|
-
import { Command as
|
|
4327
|
-
var lsCommand3 = new
|
|
4430
|
+
import { Command as Command20 } from "commander";
|
|
4431
|
+
var lsCommand3 = new Command20("ls").alias("list").description("list a box's wake hooks").argument("<box>", "box name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4328
4432
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4329
4433
|
try {
|
|
4330
4434
|
requireCloud2(client);
|
|
@@ -4345,8 +4449,8 @@ var lsCommand3 = new Command19("ls").alias("list").description("list a box's wak
|
|
|
4345
4449
|
});
|
|
4346
4450
|
|
|
4347
4451
|
// src/commands/vm/hook/rm.ts
|
|
4348
|
-
import { Command as
|
|
4349
|
-
var rmCommand2 = new
|
|
4452
|
+
import { Command as Command21 } from "commander";
|
|
4453
|
+
var rmCommand2 = new Command21("rm").alias("remove").description("remove a wake hook: its URL stops working").argument("<box>", "box name").argument("<id>", "the hook's id (kvbox vm hook ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed hook as JSON").action(async (name, id, opts, cmd) => {
|
|
4350
4454
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4351
4455
|
try {
|
|
4352
4456
|
requireCloud2(client);
|
|
@@ -4368,21 +4472,21 @@ var rmCommand2 = new Command20("rm").alias("remove").description("remove a wake
|
|
|
4368
4472
|
});
|
|
4369
4473
|
|
|
4370
4474
|
// src/commands/vm/hook/index.ts
|
|
4371
|
-
var hookCommand = new
|
|
4475
|
+
var hookCommand = new Command22("hook").description("URLs that wake a box when called (GitHub webhooks, cron, any automation)").addCommand(createCommand).addCommand(lsCommand3).addCommand(rmCommand2);
|
|
4372
4476
|
for (const cmd of hookCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4373
4477
|
|
|
4374
4478
|
// src/commands/vm/backup/index.ts
|
|
4375
|
-
import { Command as
|
|
4479
|
+
import { Command as Command28 } from "commander";
|
|
4376
4480
|
|
|
4377
4481
|
// src/commands/vm/backup/create.ts
|
|
4378
|
-
import { Command as
|
|
4482
|
+
import { Command as Command24 } from "commander";
|
|
4379
4483
|
|
|
4380
4484
|
// src/commands/vm/backup/shared.ts
|
|
4381
4485
|
import { setTimeout as sleep3 } from "timers/promises";
|
|
4382
4486
|
|
|
4383
4487
|
// src/commands/vm/usage.ts
|
|
4384
|
-
import { Command as
|
|
4385
|
-
var usageCommand = new
|
|
4488
|
+
import { Command as Command23 } from "commander";
|
|
4489
|
+
var usageCommand = new Command23("usage").description("how long a box ran, slept and sat stopped, as vCPU-hours, RAM and disk GiB-hours (and cost, when the host prices them)").argument("<name>", "box name").option("--since <date>", "count from this date instead of the box's creation, e.g. 2026-10-01").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4386
4490
|
let since;
|
|
4387
4491
|
if (opts.since !== void 0) {
|
|
4388
4492
|
const t = Date.parse(opts.since);
|
|
@@ -4482,7 +4586,7 @@ async function removeListed(client, listed, nameOf, name, id, what, yes) {
|
|
|
4482
4586
|
}
|
|
4483
4587
|
|
|
4484
4588
|
// src/commands/vm/backup/create.ts
|
|
4485
|
-
var createCommand2 = new
|
|
4589
|
+
var createCommand2 = new Command24("create").description("back up a box's disk to the kvbox cloud (encrypted; memory and volumes not included)").argument("<box>", "box name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
|
|
4486
4590
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4487
4591
|
try {
|
|
4488
4592
|
requireCloud3(client);
|
|
@@ -4512,13 +4616,12 @@ var createCommand2 = new Command23("create").description("back up a box's disk t
|
|
|
4512
4616
|
});
|
|
4513
4617
|
|
|
4514
4618
|
// src/commands/vm/backup/ls.ts
|
|
4515
|
-
import { Command as
|
|
4516
|
-
var lsCommand4 = new
|
|
4619
|
+
import { Command as Command25 } from "commander";
|
|
4620
|
+
var lsCommand4 = new Command25("ls").alias("list").description("list backups: every box's, or one box's").argument("[box]", "box name (default: every box)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4517
4621
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4518
4622
|
try {
|
|
4519
4623
|
requireCloud3(client);
|
|
4520
|
-
const
|
|
4521
|
-
const list = box2 === void 0 ? await client.listBackups() : await client.boxBackups(box2);
|
|
4624
|
+
const { box: box2, list } = await backupsOf(client, name);
|
|
4522
4625
|
if (opts.json) {
|
|
4523
4626
|
json(list);
|
|
4524
4627
|
return;
|
|
@@ -4528,10 +4631,12 @@ var lsCommand4 = new Command24("ls").alias("list").description("list backups: ev
|
|
|
4528
4631
|
return;
|
|
4529
4632
|
}
|
|
4530
4633
|
const anyError = list.some((b) => b.error !== null);
|
|
4634
|
+
const anyRemoved = list.some((b) => b.boxRemoved === true);
|
|
4635
|
+
const removed = (b) => b.boxRemoved === true ? color.dim(" (removed)") : "";
|
|
4531
4636
|
table(
|
|
4532
4637
|
list.map((b) => ({
|
|
4533
4638
|
id: b.id,
|
|
4534
|
-
...box2 === void 0 ? { box: b.owner === me(client) ? b.box : `${b.owner}/${b.box}` } : {},
|
|
4639
|
+
...box2 === void 0 ? { box: (b.owner === me(client) ? b.box : `${b.owner}/${b.box}`) + removed(b) } : anyRemoved ? { of: b.boxRemoved === true ? color.dim("removed box") : "this box" } : {},
|
|
4535
4640
|
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
4536
4641
|
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
4537
4642
|
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
@@ -4541,14 +4646,35 @@ var lsCommand4 = new Command24("ls").alias("list").description("list backups: ev
|
|
|
4541
4646
|
...anyError ? { error: b.error ?? "" } : {}
|
|
4542
4647
|
}))
|
|
4543
4648
|
);
|
|
4649
|
+
if (anyRemoved) {
|
|
4650
|
+
const orgs = [...new Set(list.filter((b) => b.boxRemoved === true && slugOf(b.owner) !== me(client)).map((b) => slugOf(b.owner)))];
|
|
4651
|
+
info(`a removed box's backup makes a new box: kvbox new <name>${orgs.length === 1 ? ` --org ${orgs[0]}` : orgs.length > 1 ? " --org <org>" : ""} --from-backup <id>`);
|
|
4652
|
+
}
|
|
4544
4653
|
} finally {
|
|
4545
4654
|
await client.close();
|
|
4546
4655
|
}
|
|
4547
4656
|
});
|
|
4657
|
+
async function backupsOf(client, name) {
|
|
4658
|
+
if (name === void 0) return { box: void 0, list: await client.listBackups() };
|
|
4659
|
+
const live = pickRef(await boxesFor(client, name), name, me(client));
|
|
4660
|
+
if (live) {
|
|
4661
|
+
const box2 = displayName(live, me(client));
|
|
4662
|
+
return { box: box2, list: await client.boxBackups(box2) };
|
|
4663
|
+
}
|
|
4664
|
+
const [owner, bare] = name.includes("/") ? name.split("/", 2) : [void 0, name];
|
|
4665
|
+
const named = (await client.listBackups()).filter((b) => b.box === bare && (owner === void 0 || slugOf(b.owner) === owner));
|
|
4666
|
+
if (named.length === 0) throw new KvboxError(`box ${name}: not found (kvbox ls)`);
|
|
4667
|
+
if (owner !== void 0) return { box: name, list: named };
|
|
4668
|
+
const mine = named.filter((b) => slugOf(b.owner) === me(client));
|
|
4669
|
+
if (mine.length > 0) return { box: name, list: mine };
|
|
4670
|
+
const owners = [...new Set(named.map((b) => slugOf(b.owner)))];
|
|
4671
|
+
if (owners.length > 1) throw new AmbiguousRefError("box", bare, owners);
|
|
4672
|
+
return { box: `${owners[0]}/${bare}`, list: named };
|
|
4673
|
+
}
|
|
4548
4674
|
|
|
4549
4675
|
// src/commands/vm/backup/restore.ts
|
|
4550
|
-
import { Command as
|
|
4551
|
-
var restoreCommand = new
|
|
4676
|
+
import { Command as Command26 } from "commander";
|
|
4677
|
+
var restoreCommand = new Command26("restore").description("put a backup back: the box's disk becomes the backup's (a running box restarts)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the box as JSON").action(async (name, id, opts, cmd) => {
|
|
4552
4678
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4553
4679
|
try {
|
|
4554
4680
|
requireCloud3(client);
|
|
@@ -4572,8 +4698,8 @@ var restoreCommand = new Command25("restore").description("put a backup back: th
|
|
|
4572
4698
|
});
|
|
4573
4699
|
|
|
4574
4700
|
// src/commands/vm/backup/rm.ts
|
|
4575
|
-
import { Command as
|
|
4576
|
-
var rmCommand3 = new
|
|
4701
|
+
import { Command as Command27 } from "commander";
|
|
4702
|
+
var rmCommand3 = new Command27("rm").alias("remove").description("remove a backup for good (a box's that is gone too)").argument("<box>", "box name").argument("<id>", "the backup's id (kvbox vm backup ls <box>)").option("-y, --yes", "do not ask for confirmation").action(async (box2, id, opts, cmd) => {
|
|
4577
4703
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4578
4704
|
try {
|
|
4579
4705
|
requireCloud3(client);
|
|
@@ -4584,12 +4710,12 @@ var rmCommand3 = new Command26("rm").alias("remove").description("remove a backu
|
|
|
4584
4710
|
});
|
|
4585
4711
|
|
|
4586
4712
|
// src/commands/vm/backup/index.ts
|
|
4587
|
-
var backupCommand = new
|
|
4713
|
+
var backupCommand = new Command28("backup").description("back up a box's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand2).addCommand(lsCommand4).addCommand(restoreCommand).addCommand(rmCommand3);
|
|
4588
4714
|
for (const cmd of backupCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4589
4715
|
|
|
4590
4716
|
// src/commands/vm/rescale.ts
|
|
4591
|
-
import { Command as
|
|
4592
|
-
var rescaleCommand = new
|
|
4717
|
+
import { Command as Command29, Option as Option3 } from "commander";
|
|
4718
|
+
var rescaleCommand = new Command29("rescale").description("change a box's vCPUs, memory or disk (e.g. --vcpu 4 --mem 16GB); a running box restarts").argument("<name>", "box name").addOption(new Option3("-s, --size <size>", "a preset to start from").choices(SIZE_NAMES)).option("--vcpu <n>", "number of vCPUs").option("--mem <size>", "memory, e.g. 16GB or 4096MB").option("--disk <size>", "disk size, e.g. 32GB (grow only)").option("--force", "skip the capacity guard when a running box grows").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4593
4719
|
const req = {
|
|
4594
4720
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
4595
4721
|
...opts.vcpu !== void 0 ? { vcpu: parseCount(opts.vcpu) } : {},
|
|
@@ -4635,8 +4761,8 @@ function parseGib(flag, text2) {
|
|
|
4635
4761
|
}
|
|
4636
4762
|
|
|
4637
4763
|
// src/commands/vm/resume.ts
|
|
4638
|
-
import { Command as
|
|
4639
|
-
var resumeCommand = new
|
|
4764
|
+
import { Command as Command30 } from "commander";
|
|
4765
|
+
var resumeCommand = new Command30("resume").description("continue a box that is in standby (kvbox pause)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4640
4766
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4641
4767
|
try {
|
|
4642
4768
|
const box2 = await spin(`resuming ${name}\u2026`, client.resumeMachine(name));
|
|
@@ -4648,8 +4774,8 @@ var resumeCommand = new Command29("resume").description("continue a box that is
|
|
|
4648
4774
|
});
|
|
4649
4775
|
|
|
4650
4776
|
// src/commands/vm/rm.ts
|
|
4651
|
-
import { Command as
|
|
4652
|
-
var rmCommand4 = new
|
|
4777
|
+
import { Command as Command31 } from "commander";
|
|
4778
|
+
var rmCommand4 = new Command31("rm").description("destroy a box (its disk is deleted; snapshots are kept)").argument("<name>", "box name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
4653
4779
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4654
4780
|
try {
|
|
4655
4781
|
const box2 = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -4669,10 +4795,10 @@ var rmCommand4 = new Command30("rm").description("destroy a box (its disk is del
|
|
|
4669
4795
|
});
|
|
4670
4796
|
|
|
4671
4797
|
// src/commands/vm/set.ts
|
|
4672
|
-
import { Command as
|
|
4798
|
+
import { Command as Command32 } from "commander";
|
|
4673
4799
|
|
|
4674
4800
|
// src/swap.ts
|
|
4675
|
-
import { spawn as
|
|
4801
|
+
import { spawn as spawn4 } from "child_process";
|
|
4676
4802
|
var SWAP_FILE = "/rom/overlay/swapfile";
|
|
4677
4803
|
var SWAP_KEEP_FREE_MIB = 1024;
|
|
4678
4804
|
var SWAP_MIN_MIB = 256;
|
|
@@ -4734,7 +4860,7 @@ function parseSwapReport(output) {
|
|
|
4734
4860
|
return { sizeMib: Math.round(Number(m[1]) / 1024), usedMib: Math.round(Number(m[2]) / 1024), zswap: m[3] === "Y" || m[3] === "1" };
|
|
4735
4861
|
}
|
|
4736
4862
|
function runSwap(ep, mib) {
|
|
4737
|
-
const child =
|
|
4863
|
+
const child = spawn4("ssh", ["-n", ...sshArgs(ep), swapCommand(mib)], { stdio: ["ignore", "pipe", "pipe"] });
|
|
4738
4864
|
const chunks = [];
|
|
4739
4865
|
child.stdout.on("data", (c2) => chunks.push(c2));
|
|
4740
4866
|
child.stderr.on("data", (c2) => chunks.push(c2));
|
|
@@ -4745,7 +4871,7 @@ function runSwap(ep, mib) {
|
|
|
4745
4871
|
}
|
|
4746
4872
|
|
|
4747
4873
|
// src/commands/vm/set.ts
|
|
4748
|
-
var setCommand = new
|
|
4874
|
+
var setCommand = new Command32("set").description("change a box's settings, e.g. --auto-hibernate 30m (off: never), --idle-check /home/kvbox/idle.sh, --swap 2G").argument("<name>", "box name").option("--auto-hibernate <duration>", "hibernate the box after this long without network traffic (30m, 4h, 1d; off: never)").option("--idle-check <script>", "a script in the box that exits 0 when it is idle, asked instead of network traffic (off: none)").option("--swap <size>", "a swap file on the box's disk for memory spikes such as a build (2G, 512M; off: none)").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4749
4875
|
if (opts.autoHibernate === void 0 && opts.idleCheck === void 0 && opts.swap === void 0) {
|
|
4750
4876
|
throw new KvboxError("nothing to change: give --auto-hibernate, --idle-check or --swap");
|
|
4751
4877
|
}
|
|
@@ -4814,8 +4940,8 @@ function parseIdleCheck(text2) {
|
|
|
4814
4940
|
}
|
|
4815
4941
|
|
|
4816
4942
|
// src/commands/vm/start.ts
|
|
4817
|
-
import { Command as
|
|
4818
|
-
var startCommand = new
|
|
4943
|
+
import { Command as Command33 } from "commander";
|
|
4944
|
+
var startCommand = new Command33("start").description("boot a stopped box again (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4819
4945
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4820
4946
|
try {
|
|
4821
4947
|
const box2 = await spin(`booting ${name}\u2026`, client.startMachine(name, opts.force ?? false));
|
|
@@ -4827,8 +4953,8 @@ var startCommand = new Command32("start").description("boot a stopped box again
|
|
|
4827
4953
|
});
|
|
4828
4954
|
|
|
4829
4955
|
// src/commands/vm/stop.ts
|
|
4830
|
-
import { Command as
|
|
4831
|
-
var stopCommand = new
|
|
4956
|
+
import { Command as Command34 } from "commander";
|
|
4957
|
+
var stopCommand = new Command34("stop").description("shut a box down (its disk is kept; start it again with kvbox start)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4832
4958
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4833
4959
|
try {
|
|
4834
4960
|
const box2 = await spin(`shutting ${name} down\u2026`, client.stopMachine(name));
|
|
@@ -4840,8 +4966,8 @@ var stopCommand = new Command33("stop").description("shut a box down (its disk i
|
|
|
4840
4966
|
});
|
|
4841
4967
|
|
|
4842
4968
|
// src/commands/vm/top.ts
|
|
4843
|
-
import { Command as
|
|
4844
|
-
var topCommand = new
|
|
4969
|
+
import { Command as Command35 } from "commander";
|
|
4970
|
+
var topCommand = new Command35("top").description("load, memory and disk of each running box, as the box itself sees them").option("-a, --all", "every running box on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4845
4971
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4846
4972
|
try {
|
|
4847
4973
|
const running = (await client.listMachines({ all: opts.all })).filter((b) => b.status === "running");
|
|
@@ -4901,8 +5027,8 @@ function topRows(entries, cloud) {
|
|
|
4901
5027
|
}
|
|
4902
5028
|
|
|
4903
5029
|
// src/commands/vm/unlink.ts
|
|
4904
|
-
import { Command as
|
|
4905
|
-
var unlinkCommand = new
|
|
5030
|
+
import { Command as Command36 } from "commander";
|
|
5031
|
+
var unlinkCommand = new Command36("unlink").description("take a link away (kvbox vm link)").argument("<from>", "the box that connects").argument("<box>", "the box it reaches").requiredOption("-p, --port <port>", "the port in <box>").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed link as JSON").action(async (from, name, opts, cmd) => {
|
|
4906
5032
|
const port = parseLinkPort(opts.port);
|
|
4907
5033
|
if (!await confirm(`Cut box ${from} off from box ${name} port ${port}? Its open connections close too.`, opts.yes ?? false)) {
|
|
4908
5034
|
info("cancelled");
|
|
@@ -4923,8 +5049,8 @@ var unlinkCommand = new Command35("unlink").description("take a link away (kvbox
|
|
|
4923
5049
|
});
|
|
4924
5050
|
|
|
4925
5051
|
// src/commands/vm/update.ts
|
|
4926
|
-
import { Command as
|
|
4927
|
-
var updateCommand = new
|
|
5052
|
+
import { Command as Command37 } from "commander";
|
|
5053
|
+
var updateCommand = new Command37("update").description("move a box onto the current base image (its files stay; a running box restarts)").argument("<name>", "box name").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4928
5054
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4929
5055
|
try {
|
|
4930
5056
|
const before = pickRef(await boxesFor(client, name), name, me(client));
|
|
@@ -4946,8 +5072,8 @@ var updateCommand = new Command36("update").description("move a box onto the cur
|
|
|
4946
5072
|
});
|
|
4947
5073
|
|
|
4948
5074
|
// src/commands/vm/wake.ts
|
|
4949
|
-
import { Command as
|
|
4950
|
-
var wakeCommand = new
|
|
5075
|
+
import { Command as Command38 } from "commander";
|
|
5076
|
+
var wakeCommand = new Command38("wake").description("continue a hibernated box where it left off (same name, IP and disk)").argument("<name>", "box name").option("--force", "skip the capacity guard").option("--json", "print the box as JSON").action(async (name, opts, cmd) => {
|
|
4951
5077
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4952
5078
|
try {
|
|
4953
5079
|
const box2 = await spin(`waking ${name} (loading its memory from disk)\u2026`, client.wakeMachine(name, opts.force ?? false));
|
|
@@ -4959,19 +5085,19 @@ var wakeCommand = new Command37("wake").description("continue a hibernated box w
|
|
|
4959
5085
|
});
|
|
4960
5086
|
|
|
4961
5087
|
// src/commands/vm/index.ts
|
|
4962
|
-
var vmCommand = new
|
|
5088
|
+
var vmCommand = new Command39("vm").enablePositionalOptions().description("manage boxes (each one is a Firecracker microVM)").addCommand(newCommand).addCommand(forkCommand).addCommand(lsCommand).addCommand(getCommand).addCommand(connectCommand).addCommand(execCommand).addCommand(cpCommand).addCommand(stopCommand).addCommand(startCommand).addCommand(pauseCommand).addCommand(resumeCommand).addCommand(hibernateCommand).addCommand(wakeCommand).addCommand(updateCommand).addCommand(rescaleCommand).addCommand(setCommand).addCommand(usageCommand).addCommand(topCommand).addCommand(proxyCommand).addCommand(hookCommand).addCommand(backupCommand).addCommand(linkCommand).addCommand(unlinkCommand).addCommand(linksCommand).addCommand(rmCommand4);
|
|
4963
5089
|
for (const cmd of vmCommand.commands) if (cmd !== proxyCommand && cmd !== hookCommand && cmd !== backupCommand) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4964
|
-
var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand4, claimCommand];
|
|
5090
|
+
var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, cpCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand4, claimCommand];
|
|
4965
5091
|
|
|
4966
5092
|
// src/commands/login.ts
|
|
4967
5093
|
import { hostname as osHostname2 } from "os";
|
|
4968
5094
|
import { createInterface as createInterface2 } from "readline/promises";
|
|
4969
5095
|
import { setTimeout as sleep4 } from "timers/promises";
|
|
4970
5096
|
import { Writable } from "stream";
|
|
4971
|
-
import { Command as
|
|
5097
|
+
import { Command as Command40 } from "commander";
|
|
4972
5098
|
|
|
4973
5099
|
// src/browser.ts
|
|
4974
|
-
import { spawn as
|
|
5100
|
+
import { spawn as spawn5 } from "child_process";
|
|
4975
5101
|
function isWebLink(url) {
|
|
4976
5102
|
if (/[^\x21-\x7e]/.test(url)) return false;
|
|
4977
5103
|
let parsed;
|
|
@@ -4996,7 +5122,7 @@ function openBrowser(url) {
|
|
|
4996
5122
|
const argv = browserCommand(url);
|
|
4997
5123
|
if (argv === null) return;
|
|
4998
5124
|
try {
|
|
4999
|
-
const child =
|
|
5125
|
+
const child = spawn5(argv[0], argv.slice(1), { stdio: "ignore", detached: true });
|
|
5000
5126
|
child.on("error", () => {
|
|
5001
5127
|
});
|
|
5002
5128
|
child.unref();
|
|
@@ -5005,7 +5131,7 @@ function openBrowser(url) {
|
|
|
5005
5131
|
}
|
|
5006
5132
|
|
|
5007
5133
|
// src/commands/login.ts
|
|
5008
|
-
var loginCommand = new
|
|
5134
|
+
var loginCommand = new Command40("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("--password", "log in with email and password instead of approving a code in the web app").option("-e, --email <email>", "account email, for a password login (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
|
|
5009
5135
|
const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
|
|
5010
5136
|
const byPassword = opts.password === true || opts.passwordStdin === true || opts.email !== void 0;
|
|
5011
5137
|
const session = byPassword ? await runLogin(url, await readCredentials(opts), paths()) : await runDeviceLogin(url, paths());
|
|
@@ -5115,8 +5241,8 @@ async function firstLine(stream) {
|
|
|
5115
5241
|
}
|
|
5116
5242
|
|
|
5117
5243
|
// src/commands/logout.ts
|
|
5118
|
-
import { Command as
|
|
5119
|
-
var logoutCommand = new
|
|
5244
|
+
import { Command as Command41 } from "commander";
|
|
5245
|
+
var logoutCommand = new Command41("logout").description("log out of the control plane; commands target this machine's kvbox-server again").action(async () => {
|
|
5120
5246
|
const p = paths();
|
|
5121
5247
|
const session = await readSession(p).catch(() => null);
|
|
5122
5248
|
switch (await runLogout(p)) {
|
|
@@ -5154,8 +5280,8 @@ async function runLogout(p = paths()) {
|
|
|
5154
5280
|
}
|
|
5155
5281
|
|
|
5156
5282
|
// src/commands/whoami.ts
|
|
5157
|
-
import { Command as
|
|
5158
|
-
var whoamiCommand = new
|
|
5283
|
+
import { Command as Command42 } from "commander";
|
|
5284
|
+
var whoamiCommand = new Command42("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5159
5285
|
if (!cmd.optsWithGlobals().local && envLogin()) {
|
|
5160
5286
|
const target = await resolveTarget({});
|
|
5161
5287
|
if (target.kind !== "cloud") return;
|
|
@@ -5180,10 +5306,10 @@ function describeSession(session) {
|
|
|
5180
5306
|
}
|
|
5181
5307
|
|
|
5182
5308
|
// src/commands/key/index.ts
|
|
5183
|
-
import { Command as
|
|
5309
|
+
import { Command as Command46 } from "commander";
|
|
5184
5310
|
|
|
5185
5311
|
// src/commands/key/create.ts
|
|
5186
|
-
import { Command as
|
|
5312
|
+
import { Command as Command43 } from "commander";
|
|
5187
5313
|
|
|
5188
5314
|
// src/commands/key/shared.ts
|
|
5189
5315
|
async function keyClient(cmd) {
|
|
@@ -5220,7 +5346,7 @@ function expiryText(expiresAt, now = Date.now()) {
|
|
|
5220
5346
|
}
|
|
5221
5347
|
|
|
5222
5348
|
// src/commands/key/create.ts
|
|
5223
|
-
var createCommand3 = new
|
|
5349
|
+
var createCommand3 = new Command43("create").description("make an API key for a program: CI, an agent, the SDK (the key is shown once)").argument("<name>", "what to call the key: lowercase letters, digits, '.', '_' or '-'").option("--expires <when>", `when it stops working: a duration (30d, 12h; m is minutes), a day (2027-01-31), or never; ${DEFAULT_API_KEY_DAYS}d by default`).option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
5224
5350
|
const expiresAt = opts.expires === void 0 ? void 0 : parseExpires(opts.expires);
|
|
5225
5351
|
const client = await keyClient(cmd);
|
|
5226
5352
|
try {
|
|
@@ -5238,8 +5364,8 @@ var createCommand3 = new Command42("create").description("make an API key for a
|
|
|
5238
5364
|
});
|
|
5239
5365
|
|
|
5240
5366
|
// src/commands/key/ls.ts
|
|
5241
|
-
import { Command as
|
|
5242
|
-
var lsCommand5 = new
|
|
5367
|
+
import { Command as Command44 } from "commander";
|
|
5368
|
+
var lsCommand5 = new Command44("ls").alias("list").description("list your API keys (never the keys themselves)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5243
5369
|
const client = await keyClient(cmd);
|
|
5244
5370
|
try {
|
|
5245
5371
|
const keys = await client.listApiKeys();
|
|
@@ -5258,8 +5384,8 @@ var lsCommand5 = new Command43("ls").alias("list").description("list your API ke
|
|
|
5258
5384
|
});
|
|
5259
5385
|
|
|
5260
5386
|
// src/commands/key/rm.ts
|
|
5261
|
-
import { Command as
|
|
5262
|
-
var rmCommand5 = new
|
|
5387
|
+
import { Command as Command45 } from "commander";
|
|
5388
|
+
var rmCommand5 = new Command45("rm").alias("remove").description("remove an API key: whatever uses it stops working").argument("<name>", "the key's name (kvbox key ls)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
5263
5389
|
const client = await keyClient(cmd);
|
|
5264
5390
|
try {
|
|
5265
5391
|
if (!await confirm(`Remove API key ${name}? Whatever uses it stops working.`, opts.yes ?? false)) {
|
|
@@ -5275,14 +5401,14 @@ var rmCommand5 = new Command44("rm").alias("remove").description("remove an API
|
|
|
5275
5401
|
});
|
|
5276
5402
|
|
|
5277
5403
|
// src/commands/key/index.ts
|
|
5278
|
-
var keyCommand = new
|
|
5404
|
+
var keyCommand = new Command46("key").aliases(["keys"]).description("API keys: named tokens a program (CI, an agent, the SDK) uses as KVBOX_TOKEN in place of a login").addCommand(createCommand3).addCommand(lsCommand5).addCommand(rmCommand5);
|
|
5279
5405
|
|
|
5280
5406
|
// src/commands/snapshots/index.ts
|
|
5281
|
-
import { Command as
|
|
5407
|
+
import { Command as Command50 } from "commander";
|
|
5282
5408
|
|
|
5283
5409
|
// src/commands/snapshots/ls.ts
|
|
5284
|
-
import { Command as
|
|
5285
|
-
var lsCommand6 = new
|
|
5410
|
+
import { Command as Command47 } from "commander";
|
|
5411
|
+
var lsCommand6 = new Command47("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5286
5412
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
5287
5413
|
try {
|
|
5288
5414
|
const cloud = client.target.kind === "cloud";
|
|
@@ -5313,8 +5439,8 @@ var lsCommand6 = new Command46("ls").description("list snapshots (yours and your
|
|
|
5313
5439
|
});
|
|
5314
5440
|
|
|
5315
5441
|
// src/commands/snapshots/new.ts
|
|
5316
|
-
import { Command as
|
|
5317
|
-
var newCommand2 = new
|
|
5442
|
+
import { Command as Command48 } from "commander";
|
|
5443
|
+
var newCommand2 = new Command48("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box2, name, opts, cmd) => {
|
|
5318
5444
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
5319
5445
|
try {
|
|
5320
5446
|
const req = { box: box2, name, ...opts.replace ? { replace: true } : {} };
|
|
@@ -5327,8 +5453,8 @@ var newCommand2 = new Command47("new").description("freeze a running box (memory
|
|
|
5327
5453
|
});
|
|
5328
5454
|
|
|
5329
5455
|
// src/commands/snapshots/rm.ts
|
|
5330
|
-
import { Command as
|
|
5331
|
-
var rmCommand6 = new
|
|
5456
|
+
import { Command as Command49 } from "commander";
|
|
5457
|
+
var rmCommand6 = new Command49("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
5332
5458
|
if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
|
|
5333
5459
|
info("cancelled");
|
|
5334
5460
|
process.exitCode = 1;
|
|
@@ -5344,14 +5470,14 @@ var rmCommand6 = new Command48("rm").description("delete a snapshot (boxes made
|
|
|
5344
5470
|
});
|
|
5345
5471
|
|
|
5346
5472
|
// src/commands/snapshots/index.ts
|
|
5347
|
-
var snapshotsCommand = new
|
|
5473
|
+
var snapshotsCommand = new Command50("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand6).addCommand(rmCommand6);
|
|
5348
5474
|
for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
5349
5475
|
|
|
5350
5476
|
// src/commands/org/index.ts
|
|
5351
|
-
import { Command as
|
|
5477
|
+
import { Command as Command56 } from "commander";
|
|
5352
5478
|
|
|
5353
5479
|
// src/commands/org/ls.ts
|
|
5354
|
-
import { Command as
|
|
5480
|
+
import { Command as Command51 } from "commander";
|
|
5355
5481
|
|
|
5356
5482
|
// src/commands/org/context.ts
|
|
5357
5483
|
var NOT_LOGGED_IN2 = "orgs live on the control plane: kvbox login first";
|
|
@@ -5371,7 +5497,7 @@ function orgFor(opts, target) {
|
|
|
5371
5497
|
}
|
|
5372
5498
|
|
|
5373
5499
|
// src/commands/org/ls.ts
|
|
5374
|
-
var lsCommand7 = new
|
|
5500
|
+
var lsCommand7 = new Command51("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5375
5501
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5376
5502
|
try {
|
|
5377
5503
|
const orgs = await client.listOrgs();
|
|
@@ -5393,8 +5519,8 @@ function orgRows(orgs) {
|
|
|
5393
5519
|
}
|
|
5394
5520
|
|
|
5395
5521
|
// src/commands/org/members.ts
|
|
5396
|
-
import { Command as
|
|
5397
|
-
var lsCommand8 = new
|
|
5522
|
+
import { Command as Command52, Option as Option4 } from "commander";
|
|
5523
|
+
var lsCommand8 = new Command52("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5398
5524
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5399
5525
|
try {
|
|
5400
5526
|
const org = await client.getOrg(orgFor(opts, client.target));
|
|
@@ -5408,7 +5534,7 @@ var lsCommand8 = new Command51("ls").description("list an org's members and thei
|
|
|
5408
5534
|
await client.close();
|
|
5409
5535
|
}
|
|
5410
5536
|
});
|
|
5411
|
-
var addCommand2 = new
|
|
5537
|
+
var addCommand2 = new Command52("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
|
|
5412
5538
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5413
5539
|
try {
|
|
5414
5540
|
const slug = orgFor(opts, client.target);
|
|
@@ -5418,7 +5544,7 @@ var addCommand2 = new Command51("add").description("add a user to an org (admins
|
|
|
5418
5544
|
await client.close();
|
|
5419
5545
|
}
|
|
5420
5546
|
});
|
|
5421
|
-
var rmCommand7 = new
|
|
5547
|
+
var rmCommand7 = new Command52("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
|
|
5422
5548
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5423
5549
|
try {
|
|
5424
5550
|
const slug = orgFor(opts, client.target);
|
|
@@ -5434,11 +5560,11 @@ var rmCommand7 = new Command51("rm").description("remove a member (or leave: rem
|
|
|
5434
5560
|
await client.close();
|
|
5435
5561
|
}
|
|
5436
5562
|
});
|
|
5437
|
-
var membersCommand = new
|
|
5563
|
+
var membersCommand = new Command52("members").description("who is in an org and what they may do").addCommand(lsCommand8).addCommand(addCommand2).addCommand(rmCommand7);
|
|
5438
5564
|
|
|
5439
5565
|
// src/commands/org/new.ts
|
|
5440
|
-
import { Command as
|
|
5441
|
-
var newCommand3 = new
|
|
5566
|
+
import { Command as Command53 } from "commander";
|
|
5567
|
+
var newCommand3 = new Command53("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
|
|
5442
5568
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5443
5569
|
try {
|
|
5444
5570
|
const org = await client.createOrg({ slug, name: opts.name ?? slug });
|
|
@@ -5454,8 +5580,8 @@ var newCommand3 = new Command52("new").description("create an org; you become it
|
|
|
5454
5580
|
});
|
|
5455
5581
|
|
|
5456
5582
|
// src/commands/org/rm.ts
|
|
5457
|
-
import { Command as
|
|
5458
|
-
var rmCommand8 = new
|
|
5583
|
+
import { Command as Command54 } from "commander";
|
|
5584
|
+
var rmCommand8 = new Command54("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
|
|
5459
5585
|
if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
|
|
5460
5586
|
info("cancelled");
|
|
5461
5587
|
process.exitCode = 1;
|
|
@@ -5471,8 +5597,8 @@ var rmCommand8 = new Command53("rm").description("delete an org (owners only; re
|
|
|
5471
5597
|
});
|
|
5472
5598
|
|
|
5473
5599
|
// src/commands/org/role.ts
|
|
5474
|
-
import { Argument, Command as
|
|
5475
|
-
var roleCommand = new
|
|
5600
|
+
import { Argument, Command as Command55 } from "commander";
|
|
5601
|
+
var roleCommand = new Command55("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
|
|
5476
5602
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
5477
5603
|
try {
|
|
5478
5604
|
const slug = orgFor(opts, client.target);
|
|
@@ -5484,11 +5610,11 @@ var roleCommand = new Command54("role").description("change a member's role (own
|
|
|
5484
5610
|
});
|
|
5485
5611
|
|
|
5486
5612
|
// src/commands/org/index.ts
|
|
5487
|
-
var orgCommand = new
|
|
5613
|
+
var orgCommand = new Command56("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand7).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand8);
|
|
5488
5614
|
|
|
5489
5615
|
// src/commands/usage.ts
|
|
5490
|
-
import { Command as
|
|
5491
|
-
var usageCommand2 = new
|
|
5616
|
+
import { Command as Command57 } from "commander";
|
|
5617
|
+
var usageCommand2 = new Command57("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5492
5618
|
for (const [name, value] of [
|
|
5493
5619
|
["since", opts.since],
|
|
5494
5620
|
["until", opts.until]
|
|
@@ -5685,8 +5811,8 @@ function userRows(r) {
|
|
|
5685
5811
|
}
|
|
5686
5812
|
|
|
5687
5813
|
// src/commands/credit.ts
|
|
5688
|
-
import { Command as
|
|
5689
|
-
var creditCommand = new
|
|
5814
|
+
import { Command as Command58 } from "commander";
|
|
5815
|
+
var creditCommand = new Command58("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
5690
5816
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
5691
5817
|
try {
|
|
5692
5818
|
if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
|
|
@@ -5715,8 +5841,8 @@ function creditRow(b, me2) {
|
|
|
5715
5841
|
}
|
|
5716
5842
|
|
|
5717
5843
|
// src/commands/redeem.ts
|
|
5718
|
-
import { Command as
|
|
5719
|
-
var redeemCommand = new
|
|
5844
|
+
import { Command as Command59 } from "commander";
|
|
5845
|
+
var redeemCommand = new Command59("redeem").description("redeem a promo code for credit, on your account or (--org) an org you own").argument("<code>", "the code, like KV-7F3K-9QXM-2HBD").option("--org <slug>", "give the credit to this org, which you own; it cannot be moved later").option("--json", "print as JSON").action(async (code, opts, cmd) => {
|
|
5720
5846
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
5721
5847
|
try {
|
|
5722
5848
|
if (client.target.kind === "local") throw new KvboxError("codes are redeemed on the control plane: kvbox login first");
|
|
@@ -5736,7 +5862,7 @@ var redeemCommand = new Command58("redeem").description("redeem a promo code for
|
|
|
5736
5862
|
// src/commands/deploy/index.ts
|
|
5737
5863
|
import { access as access5, readFile as readFile7 } from "fs/promises";
|
|
5738
5864
|
import { basename as basename2, resolve as resolve3 } from "path";
|
|
5739
|
-
import { Command as
|
|
5865
|
+
import { Command as Command60, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
|
|
5740
5866
|
|
|
5741
5867
|
// src/commands/deploy/config.ts
|
|
5742
5868
|
import { readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
|
|
@@ -6046,7 +6172,7 @@ var nodeTemplate = {
|
|
|
6046
6172
|
};
|
|
6047
6173
|
|
|
6048
6174
|
// src/commands/deploy/templates/react.ts
|
|
6049
|
-
import { spawn as
|
|
6175
|
+
import { spawn as spawn6 } from "child_process";
|
|
6050
6176
|
import { access as access2 } from "fs/promises";
|
|
6051
6177
|
import { join as join4 } from "path";
|
|
6052
6178
|
var OUT_DIRS = ["dist", "build"];
|
|
@@ -6054,7 +6180,7 @@ async function runBuild(dir, pm) {
|
|
|
6054
6180
|
const args = runScript(pm, "build");
|
|
6055
6181
|
info(`${color.dim("$")} ${pm} ${args.join(" ")}`);
|
|
6056
6182
|
const status2 = await new Promise((resolve4, reject) => {
|
|
6057
|
-
const child =
|
|
6183
|
+
const child = spawn6(pm, args, { cwd: dir, stdio: ["ignore", process.stderr, process.stderr], shell: process.platform === "win32" });
|
|
6058
6184
|
child.once("error", (err) => reject(new KvboxError(`could not run ${pm}: ${err.message}`)));
|
|
6059
6185
|
child.once("close", (code) => resolve4(code ?? 1));
|
|
6060
6186
|
});
|
|
@@ -6353,7 +6479,7 @@ function subdomainFor(name) {
|
|
|
6353
6479
|
}
|
|
6354
6480
|
|
|
6355
6481
|
// src/commands/deploy/ship.ts
|
|
6356
|
-
import { spawn as
|
|
6482
|
+
import { spawn as spawn7 } from "child_process";
|
|
6357
6483
|
import { readdir, stat as stat2 } from "fs/promises";
|
|
6358
6484
|
import { join as join7 } from "path";
|
|
6359
6485
|
var IMAGE_TOO_OLD = 3;
|
|
@@ -6375,8 +6501,8 @@ async function measure(dir, exclude = []) {
|
|
|
6375
6501
|
return total;
|
|
6376
6502
|
}
|
|
6377
6503
|
async function ship(ep, dir, remote, exclude = []) {
|
|
6378
|
-
const tar =
|
|
6379
|
-
const ssh =
|
|
6504
|
+
const tar = spawn7("tar", ["-cf", "-", ...exclude.map((e) => `--exclude=${e}`), "-C", dir, "."], { stdio: ["ignore", "pipe", "pipe"] });
|
|
6505
|
+
const ssh = spawn7("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
|
|
6380
6506
|
tar.stdout.pipe(ssh.stdin);
|
|
6381
6507
|
const chunks = [];
|
|
6382
6508
|
ssh.stdout.on("data", (c2) => chunks.push(c2));
|
|
@@ -6404,7 +6530,7 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
6404
6530
|
return { status: status2, output: Buffer.concat(chunks).toString("utf8") };
|
|
6405
6531
|
}
|
|
6406
6532
|
async function run(ep, remote) {
|
|
6407
|
-
const ssh =
|
|
6533
|
+
const ssh = spawn7("ssh", [...sshArgs(ep), remote], { stdio: ["ignore", "pipe", "pipe"] });
|
|
6408
6534
|
const chunks = [];
|
|
6409
6535
|
ssh.stdout.on("data", (c2) => chunks.push(c2));
|
|
6410
6536
|
ssh.stderr.on("data", (c2) => chunks.push(c2));
|
|
@@ -7001,7 +7127,7 @@ async function readPackageJson(dir) {
|
|
|
7001
7127
|
}
|
|
7002
7128
|
|
|
7003
7129
|
// src/commands/deploy/index.ts
|
|
7004
|
-
var deployCommand = new
|
|
7130
|
+
var deployCommand = new Command60("deploy").description("put the app in this directory (React, Next.js, a Node server, a Dockerfile or a static site) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json and the directory when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the box port of a Next.js app, Node server or container (default 3000; saved to kvbox.json)", parsePort).option("--only <service>", "with several services in kvbox.json: deploy this one only (repeatable)", (v, all) => [...all ?? [], v]).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
|
|
7005
7131
|
const dir = resolve3(dirArg ?? ".");
|
|
7006
7132
|
const pkg = await readPackageJson2(dir);
|
|
7007
7133
|
const facts = { indexHtml: await exists2(resolve3(dir, "index.html")), dockerfile: await exists2(resolve3(dir, "Dockerfile")) };
|
|
@@ -7158,15 +7284,15 @@ async function settle2(dir, pkg, facts, saved, opts, orgFlag, cloud) {
|
|
|
7158
7284
|
}
|
|
7159
7285
|
|
|
7160
7286
|
// src/commands/volume/index.ts
|
|
7161
|
-
import { Command as
|
|
7287
|
+
import { Command as Command72 } from "commander";
|
|
7162
7288
|
|
|
7163
7289
|
// src/commands/volume/attach.ts
|
|
7164
|
-
import { Command as
|
|
7290
|
+
import { Command as Command61 } from "commander";
|
|
7165
7291
|
function describeMount(machine, volume2, box2) {
|
|
7166
7292
|
const path = machine.volumes?.find((v) => volume2 === v.name || volume2.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume2.slice(volume2.lastIndexOf("/") + 1));
|
|
7167
7293
|
return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box2} is ${machine.status}; the volume is at ${path} once it runs`;
|
|
7168
7294
|
}
|
|
7169
|
-
var attachCommand = new
|
|
7295
|
+
var attachCommand = new Command61("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
7170
7296
|
if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
|
|
7171
7297
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7172
7298
|
try {
|
|
@@ -7185,11 +7311,11 @@ var attachCommand = new Command60("attach").description("attach a volume to a bo
|
|
|
7185
7311
|
});
|
|
7186
7312
|
|
|
7187
7313
|
// src/commands/volume/backup/index.ts
|
|
7188
|
-
import { Command as
|
|
7314
|
+
import { Command as Command66 } from "commander";
|
|
7189
7315
|
|
|
7190
7316
|
// src/commands/volume/backup/create.ts
|
|
7191
|
-
import { Command as
|
|
7192
|
-
var createCommand4 = new
|
|
7317
|
+
import { Command as Command62 } from "commander";
|
|
7318
|
+
var createCommand4 = new Command62("create").description("back up a volume's disk to the kvbox cloud (encrypted)").argument("<volume>", "volume name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (volume2, opts, cmd) => {
|
|
7193
7319
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7194
7320
|
try {
|
|
7195
7321
|
requireCloud3(client);
|
|
@@ -7216,8 +7342,8 @@ var createCommand4 = new Command61("create").description("back up a volume's dis
|
|
|
7216
7342
|
});
|
|
7217
7343
|
|
|
7218
7344
|
// src/commands/volume/backup/ls.ts
|
|
7219
|
-
import { Command as
|
|
7220
|
-
var lsCommand9 = new
|
|
7345
|
+
import { Command as Command63 } from "commander";
|
|
7346
|
+
var lsCommand9 = new Command63("ls").alias("list").description("list volume backups: every volume's, or one volume's").argument("[volume]", "volume name (default: every volume)").option("--json", "print as JSON").action(async (volume2, opts, cmd) => {
|
|
7221
7347
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7222
7348
|
try {
|
|
7223
7349
|
requireCloud3(client);
|
|
@@ -7250,8 +7376,8 @@ var lsCommand9 = new Command62("ls").alias("list").description("list volume back
|
|
|
7250
7376
|
});
|
|
7251
7377
|
|
|
7252
7378
|
// src/commands/volume/backup/restore.ts
|
|
7253
|
-
import { Command as
|
|
7254
|
-
var restoreCommand2 = new
|
|
7379
|
+
import { Command as Command64 } from "commander";
|
|
7380
|
+
var restoreCommand2 = new Command64("restore").description("put a backup back: the volume's data becomes the backup's (a running box holding it restarts)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the volume as JSON").action(async (volume2, id, opts, cmd) => {
|
|
7255
7381
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7256
7382
|
try {
|
|
7257
7383
|
requireCloud3(client);
|
|
@@ -7274,8 +7400,8 @@ var restoreCommand2 = new Command63("restore").description("put a backup back: t
|
|
|
7274
7400
|
});
|
|
7275
7401
|
|
|
7276
7402
|
// src/commands/volume/backup/rm.ts
|
|
7277
|
-
import { Command as
|
|
7278
|
-
var rmCommand9 = new
|
|
7403
|
+
import { Command as Command65 } from "commander";
|
|
7404
|
+
var rmCommand9 = new Command65("rm").alias("remove").description("remove a backup for good (a volume's that is gone too)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").action(async (volume2, id, opts, cmd) => {
|
|
7279
7405
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7280
7406
|
try {
|
|
7281
7407
|
requireCloud3(client);
|
|
@@ -7286,11 +7412,11 @@ var rmCommand9 = new Command64("rm").alias("remove").description("remove a backu
|
|
|
7286
7412
|
});
|
|
7287
7413
|
|
|
7288
7414
|
// src/commands/volume/backup/index.ts
|
|
7289
|
-
var backupCommand2 = new
|
|
7415
|
+
var backupCommand2 = new Command66("backup").description("back up a volume's disk to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand4).addCommand(lsCommand9).addCommand(restoreCommand2).addCommand(rmCommand9);
|
|
7290
7416
|
for (const cmd of backupCommand2.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
7291
7417
|
|
|
7292
7418
|
// src/commands/volume/create.ts
|
|
7293
|
-
import { Command as
|
|
7419
|
+
import { Command as Command67 } from "commander";
|
|
7294
7420
|
function parseGib2(text2, label = "--size") {
|
|
7295
7421
|
const mib = parseMib(text2);
|
|
7296
7422
|
if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`${label} ${text2}: write whole GB, like 50 or 50GB`);
|
|
@@ -7306,7 +7432,7 @@ function sizeProblem(answer) {
|
|
|
7306
7432
|
return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
|
|
7307
7433
|
}
|
|
7308
7434
|
}
|
|
7309
|
-
var createCommand5 = new
|
|
7435
|
+
var createCommand5 = new Command67("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
|
|
7310
7436
|
const ask = interactive();
|
|
7311
7437
|
if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
|
|
7312
7438
|
const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
|
|
@@ -7339,8 +7465,8 @@ var createCommand5 = new Command66("create").alias("new").description("create a
|
|
|
7339
7465
|
});
|
|
7340
7466
|
|
|
7341
7467
|
// src/commands/volume/detach.ts
|
|
7342
|
-
import { Command as
|
|
7343
|
-
var detachCommand = new
|
|
7468
|
+
import { Command as Command68 } from "commander";
|
|
7469
|
+
var detachCommand = new Command68("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
7344
7470
|
if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
|
|
7345
7471
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7346
7472
|
try {
|
|
@@ -7365,8 +7491,8 @@ var detachCommand = new Command67("detach").description("detach a volume from a
|
|
|
7365
7491
|
});
|
|
7366
7492
|
|
|
7367
7493
|
// src/commands/volume/grow.ts
|
|
7368
|
-
import { Command as
|
|
7369
|
-
var growCommand = new
|
|
7494
|
+
import { Command as Command69 } from "commander";
|
|
7495
|
+
var growCommand = new Command69("grow").alias("resize").description("make a volume larger (a running box holding it is restarted once)").argument("<volume>", "volume name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the volume as JSON").action(async (name, size, opts, cmd) => {
|
|
7370
7496
|
const sizeGib = parseGib2(size, "size");
|
|
7371
7497
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7372
7498
|
try {
|
|
@@ -7379,8 +7505,8 @@ var growCommand = new Command68("grow").alias("resize").description("make a volu
|
|
|
7379
7505
|
});
|
|
7380
7506
|
|
|
7381
7507
|
// src/commands/volume/ls.ts
|
|
7382
|
-
import { Command as
|
|
7383
|
-
var lsCommand10 = new
|
|
7508
|
+
import { Command as Command70 } from "commander";
|
|
7509
|
+
var lsCommand10 = new Command70("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7384
7510
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7385
7511
|
try {
|
|
7386
7512
|
const cloud = client.target.kind === "cloud";
|
|
@@ -7411,8 +7537,8 @@ var lsCommand10 = new Command69("ls").alias("list").description("list volumes: s
|
|
|
7411
7537
|
});
|
|
7412
7538
|
|
|
7413
7539
|
// src/commands/volume/rm.ts
|
|
7414
|
-
import { Command as
|
|
7415
|
-
var rmCommand10 = new
|
|
7540
|
+
import { Command as Command71 } from "commander";
|
|
7541
|
+
var rmCommand10 = new Command71("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
7416
7542
|
if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
|
|
7417
7543
|
info("cancelled");
|
|
7418
7544
|
process.exitCode = 1;
|
|
@@ -7428,18 +7554,18 @@ var rmCommand10 = new Command70("rm").alias("remove").description("delete a volu
|
|
|
7428
7554
|
});
|
|
7429
7555
|
|
|
7430
7556
|
// src/commands/volume/index.ts
|
|
7431
|
-
var volumeCommand = new
|
|
7557
|
+
var volumeCommand = new Command72("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand5).addCommand(lsCommand10).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand10);
|
|
7432
7558
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
7433
7559
|
volumeCommand.addCommand(backupCommand2);
|
|
7434
7560
|
|
|
7435
7561
|
// src/commands/bucket/index.ts
|
|
7436
|
-
import { Command as
|
|
7562
|
+
import { Command as Command88 } from "commander";
|
|
7437
7563
|
|
|
7438
7564
|
// src/commands/bucket/backup/index.ts
|
|
7439
|
-
import { Command as
|
|
7565
|
+
import { Command as Command77 } from "commander";
|
|
7440
7566
|
|
|
7441
7567
|
// src/commands/bucket/backup/create.ts
|
|
7442
|
-
import { Command as
|
|
7568
|
+
import { Command as Command73 } from "commander";
|
|
7443
7569
|
|
|
7444
7570
|
// src/commands/bucket/shared.ts
|
|
7445
7571
|
async function bucketClient(cmd) {
|
|
@@ -7465,7 +7591,7 @@ function printRows(rows2) {
|
|
|
7465
7591
|
}
|
|
7466
7592
|
|
|
7467
7593
|
// src/commands/bucket/backup/create.ts
|
|
7468
|
-
var createCommand6 = new
|
|
7594
|
+
var createCommand6 = new Command73("create").description("back up your object storage (every bucket and key) to the kvbox cloud, encrypted").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (opts, cmd) => {
|
|
7469
7595
|
const client = await bucketClient(cmd);
|
|
7470
7596
|
const ls = "kvbox bucket backup ls";
|
|
7471
7597
|
try {
|
|
@@ -7493,8 +7619,8 @@ var createCommand6 = new Command72("create").description("back up your object st
|
|
|
7493
7619
|
});
|
|
7494
7620
|
|
|
7495
7621
|
// src/commands/bucket/backup/ls.ts
|
|
7496
|
-
import { Command as
|
|
7497
|
-
var lsCommand11 = new
|
|
7622
|
+
import { Command as Command74 } from "commander";
|
|
7623
|
+
var lsCommand11 = new Command74("ls").alias("list").description("list the backups of your object storage").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7498
7624
|
const client = await bucketClient(cmd);
|
|
7499
7625
|
try {
|
|
7500
7626
|
const list = await client.storageBackups();
|
|
@@ -7526,8 +7652,8 @@ var lsCommand11 = new Command73("ls").alias("list").description("list the backup
|
|
|
7526
7652
|
});
|
|
7527
7653
|
|
|
7528
7654
|
// src/commands/bucket/backup/restore.ts
|
|
7529
|
-
import { Command as
|
|
7530
|
-
var restoreCommand3 = new
|
|
7655
|
+
import { Command as Command75 } from "commander";
|
|
7656
|
+
var restoreCommand3 = new Command75("restore").description("put a backup back: every bucket and key becomes the backup's (the storage restarts)").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").option("--json", "print what changed as JSON").action(async (id, opts, cmd) => {
|
|
7531
7657
|
const client = await bucketClient(cmd);
|
|
7532
7658
|
try {
|
|
7533
7659
|
const backup = await client.storageBackup(id);
|
|
@@ -7557,8 +7683,8 @@ var restoreCommand3 = new Command74("restore").description("put a backup back: e
|
|
|
7557
7683
|
});
|
|
7558
7684
|
|
|
7559
7685
|
// src/commands/bucket/backup/rm.ts
|
|
7560
|
-
import { Command as
|
|
7561
|
-
var rmCommand11 = new
|
|
7686
|
+
import { Command as Command76 } from "commander";
|
|
7687
|
+
var rmCommand11 = new Command76("rm").alias("remove").description("remove a backup of your object storage for good").argument("<id>", "the backup's id (kvbox bucket backup ls)").option("-y, --yes", "do not ask for confirmation").action(async (id, opts, cmd) => {
|
|
7562
7688
|
const client = await bucketClient(cmd);
|
|
7563
7689
|
try {
|
|
7564
7690
|
const backup = (await client.storageBackups()).find((b) => b.id === id);
|
|
@@ -7577,11 +7703,11 @@ var rmCommand11 = new Command75("rm").alias("remove").description("remove a back
|
|
|
7577
7703
|
});
|
|
7578
7704
|
|
|
7579
7705
|
// src/commands/bucket/backup/index.ts
|
|
7580
|
-
var backupCommand3 = new
|
|
7706
|
+
var backupCommand3 = new Command77("backup").aliases(["backups"]).description("back up your object storage to the kvbox cloud, list backups, restore or remove one").addCommand(createCommand6).addCommand(lsCommand11).addCommand(restoreCommand3).addCommand(rmCommand11);
|
|
7581
7707
|
|
|
7582
7708
|
// src/commands/bucket/create.ts
|
|
7583
|
-
import { Command as
|
|
7584
|
-
var createCommand7 = new
|
|
7709
|
+
import { Command as Command78 } from "commander";
|
|
7710
|
+
var createCommand7 = new Command78("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--region <region>", "the S3 region of your object storage (ro-west-1, de-center-1), when this is your first bucket").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7585
7711
|
const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
|
|
7586
7712
|
const client = await bucketClient(cmd);
|
|
7587
7713
|
try {
|
|
@@ -7601,8 +7727,8 @@ var createCommand7 = new Command77("create").description("make a bucket (the fir
|
|
|
7601
7727
|
});
|
|
7602
7728
|
|
|
7603
7729
|
// src/commands/bucket/grow.ts
|
|
7604
|
-
import { Command as
|
|
7605
|
-
var growCommand2 = new
|
|
7730
|
+
import { Command as Command79 } from "commander";
|
|
7731
|
+
var growCommand2 = new Command79("grow").description("make your object storage larger (all your buckets share it; it restarts once)").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the object storage as JSON").action(async (size, opts, cmd) => {
|
|
7606
7732
|
const sizeGib = parseGib2(size, "size");
|
|
7607
7733
|
const client = await bucketClient(cmd);
|
|
7608
7734
|
try {
|
|
@@ -7615,8 +7741,8 @@ var growCommand2 = new Command78("grow").description("make your object storage l
|
|
|
7615
7741
|
});
|
|
7616
7742
|
|
|
7617
7743
|
// src/commands/bucket/info.ts
|
|
7618
|
-
import { Command as
|
|
7619
|
-
var infoCommand = new
|
|
7744
|
+
import { Command as Command80 } from "commander";
|
|
7745
|
+
var infoCommand = new Command80("info").description("one bucket: its address, what it holds, how full your object storage is").argument("<name>", "bucket name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7620
7746
|
const client = await bucketClient(cmd);
|
|
7621
7747
|
try {
|
|
7622
7748
|
const b = await client.getBucket(name);
|
|
@@ -7630,6 +7756,7 @@ var infoCommand = new Command79("info").description("one bucket: its address, wh
|
|
|
7630
7756
|
["name", color.bold(shown)],
|
|
7631
7757
|
["endpoint", endpointText(b.endpoint)],
|
|
7632
7758
|
["region", `${b.region} ${color.dim("(path-style addressing)")}`],
|
|
7759
|
+
["public", b.publicUrl === void 0 ? color.dim(`no (kvbox bucket public ${shown} on)`) : `${b.publicUrl}/<key> ${color.dim("(anyone can read every object)")}`],
|
|
7633
7760
|
["holds", b.objects === void 0 || b.bytes === void 0 ? color.dim(s.status === "running" ? "not answering yet" : `unknown (the storage is ${s.status})`) : `${b.objects} ${b.objects === 1 ? "object" : "objects"}, ${gb(b.bytes)}`],
|
|
7634
7761
|
["keys", b.keys === 0 ? color.dim(`none (kvbox bucket key create ${shown})`) : `${b.keys} ${color.dim(`(kvbox bucket key ls ${shown})`)}`],
|
|
7635
7762
|
["storage", `${fullness(s)}, ${s.buckets} ${s.buckets === 1 ? "bucket" : "buckets"}${nearlyFull(s) ? color.yellow(" almost full: kvbox bucket grow <GB>") : ""}`],
|
|
@@ -7645,11 +7772,11 @@ with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
|
|
|
7645
7772
|
});
|
|
7646
7773
|
|
|
7647
7774
|
// src/commands/bucket/key/index.ts
|
|
7648
|
-
import { Command as
|
|
7775
|
+
import { Command as Command84 } from "commander";
|
|
7649
7776
|
|
|
7650
7777
|
// src/commands/bucket/key/create.ts
|
|
7651
|
-
import { Command as
|
|
7652
|
-
var createCommand8 = new
|
|
7778
|
+
import { Command as Command81 } from "commander";
|
|
7779
|
+
var createCommand8 = new Command81("create").description("make an access key for a bucket (the secret is shown once)").argument("<bucket>", "bucket name").option("--name <label>", "what to call the key, to tell it from the others").option("--read-only", "the key reads the bucket but cannot write to it").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
|
|
7653
7780
|
const client = await bucketClient(cmd);
|
|
7654
7781
|
try {
|
|
7655
7782
|
const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
|
|
@@ -7672,8 +7799,8 @@ var createCommand8 = new Command80("create").description("make an access key for
|
|
|
7672
7799
|
});
|
|
7673
7800
|
|
|
7674
7801
|
// src/commands/bucket/key/ls.ts
|
|
7675
|
-
import { Command as
|
|
7676
|
-
var lsCommand12 = new
|
|
7802
|
+
import { Command as Command82 } from "commander";
|
|
7803
|
+
var lsCommand12 = new Command82("ls").alias("list").description("list a bucket's access keys (never their secrets)").argument("<bucket>", "bucket name").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
|
|
7677
7804
|
const client = await bucketClient(cmd);
|
|
7678
7805
|
try {
|
|
7679
7806
|
const keys = await client.listBucketKeys(bucket);
|
|
@@ -7692,8 +7819,8 @@ var lsCommand12 = new Command81("ls").alias("list").description("list a bucket's
|
|
|
7692
7819
|
});
|
|
7693
7820
|
|
|
7694
7821
|
// src/commands/bucket/key/rm.ts
|
|
7695
|
-
import { Command as
|
|
7696
|
-
var rmCommand12 = new
|
|
7822
|
+
import { Command as Command83 } from "commander";
|
|
7823
|
+
var rmCommand12 = new Command83("rm").alias("remove").description("delete an access key: whatever uses it stops reaching the bucket").argument("<bucket>", "bucket name").argument("<access-key>", "the access key id (kvbox bucket key ls)").option("-y, --yes", "do not ask for confirmation").action(async (bucket, id, opts, cmd) => {
|
|
7697
7824
|
const client = await bucketClient(cmd);
|
|
7698
7825
|
try {
|
|
7699
7826
|
if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
|
|
@@ -7709,11 +7836,11 @@ var rmCommand12 = new Command82("rm").alias("remove").description("delete an acc
|
|
|
7709
7836
|
});
|
|
7710
7837
|
|
|
7711
7838
|
// src/commands/bucket/key/index.ts
|
|
7712
|
-
var keyCommand2 = new
|
|
7839
|
+
var keyCommand2 = new Command84("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand8).addCommand(lsCommand12).addCommand(rmCommand12);
|
|
7713
7840
|
|
|
7714
7841
|
// src/commands/bucket/ls.ts
|
|
7715
|
-
import { Command as
|
|
7716
|
-
var lsCommand13 = new
|
|
7842
|
+
import { Command as Command85 } from "commander";
|
|
7843
|
+
var lsCommand13 = new Command85("ls").alias("list").description("list buckets, and the object storage they are in").option("-a, --all", "every bucket on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7717
7844
|
const client = await bucketClient(cmd);
|
|
7718
7845
|
try {
|
|
7719
7846
|
const buckets = await client.listBuckets({ all: opts.all });
|
|
@@ -7731,6 +7858,7 @@ var lsCommand13 = new Command84("ls").alias("list").description("list buckets, a
|
|
|
7731
7858
|
owner: b.owner === me2 ? "private" : b.owner,
|
|
7732
7859
|
name: b.name,
|
|
7733
7860
|
keys: b.keys,
|
|
7861
|
+
public: b.publicUrl ?? "-",
|
|
7734
7862
|
created: age(b.createdAt)
|
|
7735
7863
|
}))
|
|
7736
7864
|
);
|
|
@@ -7742,9 +7870,38 @@ var lsCommand13 = new Command84("ls").alias("list").description("list buckets, a
|
|
|
7742
7870
|
}
|
|
7743
7871
|
});
|
|
7744
7872
|
|
|
7873
|
+
// src/commands/bucket/public.ts
|
|
7874
|
+
import { Command as Command86 } from "commander";
|
|
7875
|
+
var publicCommand = new Command86("public").description("let anyone read a bucket's files at its own HTTPS address (on), or make it private again (off)").argument("<name>", "bucket name").argument("<state>", "on (public) or off (private)").option("--sub <name>", "the address to use, <name>.kvbox.app (default: <bucket>-<account>)").option("--json", "print the bucket as JSON").action(async (name, state, opts, cmd) => {
|
|
7876
|
+
if (state !== "on" && state !== "off") throw new KvboxError(`"${state}": say on or off`);
|
|
7877
|
+
const on = state === "on";
|
|
7878
|
+
if (!on && opts.sub !== void 0) throw new KvboxError("--sub goes with on");
|
|
7879
|
+
if (opts.sub !== void 0) assertSubdomain(opts.sub.trim().toLowerCase());
|
|
7880
|
+
const client = await bucketClient(cmd);
|
|
7881
|
+
try {
|
|
7882
|
+
const b = await spin(
|
|
7883
|
+
on ? `making bucket ${name} public\u2026` : `making bucket ${name} private\u2026`,
|
|
7884
|
+
client.setBucketPublic(name, { on, ...opts.sub !== void 0 ? { sub: opts.sub } : {} })
|
|
7885
|
+
);
|
|
7886
|
+
if (opts.json) {
|
|
7887
|
+
json(b);
|
|
7888
|
+
return;
|
|
7889
|
+
}
|
|
7890
|
+
const shown = shownName(b, client);
|
|
7891
|
+
if (b.publicUrl === void 0) {
|
|
7892
|
+
info(`${color.green("\u2713")} bucket ${color.bold(shown)} is private: its files open only with a key or a signed link`);
|
|
7893
|
+
return;
|
|
7894
|
+
}
|
|
7895
|
+
info(`${color.green("\u2713")} anyone can now read the files of bucket ${color.bold(shown)} at ${color.bold(`${b.publicUrl}/<key>`)}`);
|
|
7896
|
+
info(color.dim(` e.g. ${b.publicUrl}/images/logo.png for the object images/logo.png. Files are never listed. Undo with: kvbox bucket public ${shown} off`));
|
|
7897
|
+
} finally {
|
|
7898
|
+
await client.close();
|
|
7899
|
+
}
|
|
7900
|
+
});
|
|
7901
|
+
|
|
7745
7902
|
// src/commands/bucket/rm.ts
|
|
7746
|
-
import { Command as
|
|
7747
|
-
var rmCommand13 = new
|
|
7903
|
+
import { Command as Command87 } from "commander";
|
|
7904
|
+
var rmCommand13 = new Command87("rm").alias("remove").description("delete an empty bucket and its keys (the last one takes your object storage with it)").argument("<name>", "bucket name").option("--force", "your last bucket only: delete it with everything in it").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
7748
7905
|
const client = await bucketClient(cmd);
|
|
7749
7906
|
try {
|
|
7750
7907
|
const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
|
|
@@ -7763,7 +7920,7 @@ var rmCommand13 = new Command85("rm").alias("remove").description("delete an emp
|
|
|
7763
7920
|
});
|
|
7764
7921
|
|
|
7765
7922
|
// src/commands/bucket/index.ts
|
|
7766
|
-
var bucketCommand = new
|
|
7923
|
+
var bucketCommand = new Command88("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand7).addCommand(lsCommand13).addCommand(infoCommand).addCommand(growCommand2).addCommand(publicCommand).addCommand(rmCommand13).addCommand(keyCommand2).addCommand(backupCommand3);
|
|
7767
7924
|
var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
|
|
7768
7925
|
for (const cmd of bucketCommand.commands) {
|
|
7769
7926
|
if (cmd === keyCommand2 || cmd === backupCommand3) cmd.commands.forEach(withOrg);
|
|
@@ -7771,10 +7928,10 @@ for (const cmd of bucketCommand.commands) {
|
|
|
7771
7928
|
}
|
|
7772
7929
|
|
|
7773
7930
|
// src/commands/cron/index.ts
|
|
7774
|
-
import { Command as
|
|
7931
|
+
import { Command as Command101 } from "commander";
|
|
7775
7932
|
|
|
7776
7933
|
// src/commands/cron/create.ts
|
|
7777
|
-
import { Command as
|
|
7934
|
+
import { Command as Command89 } from "commander";
|
|
7778
7935
|
|
|
7779
7936
|
// src/commands/cron/shared.ts
|
|
7780
7937
|
async function cronClient(cmd) {
|
|
@@ -7835,7 +7992,7 @@ function printRows2(rows2) {
|
|
|
7835
7992
|
var noTriggers = (service) => info(`cron service ${service} has no triggers yet; add one with: kvbox cron trigger add ${service} <box> "0 6 * * *" --port 3000 (or --run "<command>")`);
|
|
7836
7993
|
|
|
7837
7994
|
// src/commands/cron/create.ts
|
|
7838
|
-
var createCommand9 = new
|
|
7995
|
+
var createCommand9 = new Command89("create").description("make a cron service: a named set of triggers").argument("<name>", "what to call it (lowercase letters, digits and '-')").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7839
7996
|
const client = await cronClient(cmd);
|
|
7840
7997
|
try {
|
|
7841
7998
|
const service = await client.createCronService(name);
|
|
@@ -7852,8 +8009,8 @@ var createCommand9 = new Command87("create").description("make a cron service: a
|
|
|
7852
8009
|
});
|
|
7853
8010
|
|
|
7854
8011
|
// src/commands/cron/info.ts
|
|
7855
|
-
import { Command as
|
|
7856
|
-
var infoCommand2 = new
|
|
8012
|
+
import { Command as Command90 } from "commander";
|
|
8013
|
+
var infoCommand2 = new Command90("info").alias("get").description("show a cron service and its triggers").argument("<name>", "cron service name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7857
8014
|
const client = await cronClient(cmd);
|
|
7858
8015
|
try {
|
|
7859
8016
|
const service = await client.getCronService(name);
|
|
@@ -7877,8 +8034,8 @@ var infoCommand2 = new Command88("info").alias("get").description("show a cron s
|
|
|
7877
8034
|
});
|
|
7878
8035
|
|
|
7879
8036
|
// src/commands/cron/ls.ts
|
|
7880
|
-
import { Command as
|
|
7881
|
-
var lsCommand14 = new
|
|
8037
|
+
import { Command as Command91 } from "commander";
|
|
8038
|
+
var lsCommand14 = new Command91("ls").alias("list").description("list cron services").option("-a, --all", "every cron service on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7882
8039
|
const client = await cronClient(cmd);
|
|
7883
8040
|
try {
|
|
7884
8041
|
const services = await client.listCronServices({ all: opts.all });
|
|
@@ -7898,8 +8055,8 @@ var lsCommand14 = new Command89("ls").alias("list").description("list cron servi
|
|
|
7898
8055
|
});
|
|
7899
8056
|
|
|
7900
8057
|
// src/commands/cron/rm.ts
|
|
7901
|
-
import { Command as
|
|
7902
|
-
var rmCommand14 = new
|
|
8058
|
+
import { Command as Command92 } from "commander";
|
|
8059
|
+
var rmCommand14 = new Command92("rm").alias("remove").description("delete a cron service, its triggers and their run history").argument("<name>", "cron service name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
7903
8060
|
const client = await cronClient(cmd);
|
|
7904
8061
|
try {
|
|
7905
8062
|
if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
|
|
@@ -7915,10 +8072,10 @@ var rmCommand14 = new Command90("rm").alias("remove").description("delete a cron
|
|
|
7915
8072
|
});
|
|
7916
8073
|
|
|
7917
8074
|
// src/commands/cron/trigger/index.ts
|
|
7918
|
-
import { Command as
|
|
8075
|
+
import { Command as Command100 } from "commander";
|
|
7919
8076
|
|
|
7920
8077
|
// src/commands/cron/trigger/add.ts
|
|
7921
|
-
import { Command as
|
|
8078
|
+
import { Command as Command93 } from "commander";
|
|
7922
8079
|
function portOf(value) {
|
|
7923
8080
|
const n = Number(value);
|
|
7924
8081
|
if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
|
|
@@ -7938,7 +8095,7 @@ function timeoutOf(value) {
|
|
|
7938
8095
|
if (sec > MAX_CRON_COMMAND_TIMEOUT_SEC) throw new KvboxError(`--timeout ${value}: a command may run for ${MAX_CRON_COMMAND_TIMEOUT_SEC / 60} minutes at most`);
|
|
7939
8096
|
return sec;
|
|
7940
8097
|
}
|
|
7941
|
-
var addCommand3 = new
|
|
8098
|
+
var addCommand3 = new Command93("add").description("add a trigger: on a schedule, call a port of a box or run a command in it").argument("<service>", "cron service name").argument("<box>", "the box it acts on").argument("<expr>", 'cron expression in quotes, five fields: "0 6 * * *" is every day at 06:00').option("--port <n>", "call this port, the one your app listens on in the box").option("--path <path>", "with --port: path and query to request (default: /)").option("--method <method>", `with --port: HTTP method, ${CRON_METHODS.join(" or ")} (default: POST)`).option("--run <command>", 'or run this command in the box, in quotes: "node ~/app/embed.js"').option("--timeout <duration>", `with --run: stop the command after this long (90s, 10m, 1h; default: ${DEFAULT_CRON_COMMAND_TIMEOUT_SEC / 60}m)`).option("--tz <zone>", "time zone the schedule is read in, like Europe/Bucharest", "UTC").option("--json", "print as JSON").action(async (service, box2, expr, opts, cmd) => {
|
|
7942
8099
|
let action;
|
|
7943
8100
|
if (opts.run !== void 0) {
|
|
7944
8101
|
if (opts.port !== void 0 || opts.path !== void 0 || opts.method !== void 0) throw new KvboxError("a trigger runs a command or calls a port: use --run, or --port with --path and --method, not both");
|
|
@@ -7965,8 +8122,8 @@ var addCommand3 = new Command91("add").description("add a trigger: on a schedule
|
|
|
7965
8122
|
});
|
|
7966
8123
|
|
|
7967
8124
|
// src/commands/cron/trigger/ls.ts
|
|
7968
|
-
import { Command as
|
|
7969
|
-
var lsCommand15 = new
|
|
8125
|
+
import { Command as Command94 } from "commander";
|
|
8126
|
+
var lsCommand15 = new Command94("ls").alias("list").description("list a cron service's triggers").argument("<service>", "cron service name").option("--json", "print as JSON").action(async (service, opts, cmd) => {
|
|
7970
8127
|
const client = await cronClient(cmd);
|
|
7971
8128
|
try {
|
|
7972
8129
|
const triggers = await client.listCronTriggers(service);
|
|
@@ -7982,8 +8139,8 @@ var lsCommand15 = new Command92("ls").alias("list").description("list a cron ser
|
|
|
7982
8139
|
});
|
|
7983
8140
|
|
|
7984
8141
|
// src/commands/cron/trigger/pause.ts
|
|
7985
|
-
import { Command as
|
|
7986
|
-
var pauseCommand2 = new
|
|
8142
|
+
import { Command as Command95 } from "commander";
|
|
8143
|
+
var pauseCommand2 = new Command95("pause").description("stop a trigger from firing until it is resumed").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
|
|
7987
8144
|
const client = await cronClient(cmd);
|
|
7988
8145
|
try {
|
|
7989
8146
|
const trigger = await client.setCronTriggerEnabled(service, id, false);
|
|
@@ -7998,8 +8155,8 @@ var pauseCommand2 = new Command93("pause").description("stop a trigger from firi
|
|
|
7998
8155
|
});
|
|
7999
8156
|
|
|
8000
8157
|
// src/commands/cron/trigger/resume.ts
|
|
8001
|
-
import { Command as
|
|
8002
|
-
var resumeCommand2 = new
|
|
8158
|
+
import { Command as Command96 } from "commander";
|
|
8159
|
+
var resumeCommand2 = new Command96("resume").description("let a paused trigger fire again").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
|
|
8003
8160
|
const client = await cronClient(cmd);
|
|
8004
8161
|
try {
|
|
8005
8162
|
const trigger = await client.setCronTriggerEnabled(service, id, true);
|
|
@@ -8014,8 +8171,8 @@ var resumeCommand2 = new Command94("resume").description("let a paused trigger f
|
|
|
8014
8171
|
});
|
|
8015
8172
|
|
|
8016
8173
|
// src/commands/cron/trigger/rm.ts
|
|
8017
|
-
import { Command as
|
|
8018
|
-
var rmCommand15 = new
|
|
8174
|
+
import { Command as Command97 } from "commander";
|
|
8175
|
+
var rmCommand15 = new Command97("rm").alias("remove").description("delete a trigger and its run history").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-y, --yes", "do not ask for confirmation").action(async (service, id, opts, cmd) => {
|
|
8019
8176
|
const client = await cronClient(cmd);
|
|
8020
8177
|
try {
|
|
8021
8178
|
if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
|
|
@@ -8031,8 +8188,8 @@ var rmCommand15 = new Command95("rm").alias("remove").description("delete a trig
|
|
|
8031
8188
|
});
|
|
8032
8189
|
|
|
8033
8190
|
// src/commands/cron/trigger/run.ts
|
|
8034
|
-
import { Command as
|
|
8035
|
-
var runCommand = new
|
|
8191
|
+
import { Command as Command98 } from "commander";
|
|
8192
|
+
var runCommand = new Command98("run").description("fire a trigger now, once, besides its schedule").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
|
|
8036
8193
|
const client = await cronClient(cmd);
|
|
8037
8194
|
try {
|
|
8038
8195
|
const trigger = await client.runCronTrigger(service, id);
|
|
@@ -8048,13 +8205,13 @@ var runCommand = new Command96("run").description("fire a trigger now, once, bes
|
|
|
8048
8205
|
});
|
|
8049
8206
|
|
|
8050
8207
|
// src/commands/cron/trigger/runs.ts
|
|
8051
|
-
import { Command as
|
|
8208
|
+
import { Command as Command99 } from "commander";
|
|
8052
8209
|
function limitOf(value) {
|
|
8053
8210
|
const n = Number(value);
|
|
8054
8211
|
if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
|
|
8055
8212
|
return n;
|
|
8056
8213
|
}
|
|
8057
|
-
var runsCommand = new
|
|
8214
|
+
var runsCommand = new Command99("runs").aliases(["logs"]).description("show how a trigger's last runs ended").argument("<service>", "cron service name").argument("<id>", "trigger id (kvbox cron trigger ls)").option("-n, --limit <count>", "how many runs to show", "20").option("--json", "print as JSON").action(async (service, id, opts, cmd) => {
|
|
8058
8215
|
const limit = limitOf(opts.limit);
|
|
8059
8216
|
const client = await cronClient(cmd);
|
|
8060
8217
|
try {
|
|
@@ -8084,10 +8241,10 @@ var runsCommand = new Command97("runs").aliases(["logs"]).description("show how
|
|
|
8084
8241
|
});
|
|
8085
8242
|
|
|
8086
8243
|
// src/commands/cron/trigger/index.ts
|
|
8087
|
-
var triggerCommand = new
|
|
8244
|
+
var triggerCommand = new Command100("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand15).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand15);
|
|
8088
8245
|
|
|
8089
8246
|
// src/commands/cron/index.ts
|
|
8090
|
-
var cronCommand = new
|
|
8247
|
+
var cronCommand = new Command101("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand9).addCommand(lsCommand14).addCommand(infoCommand2).addCommand(rmCommand14).addCommand(triggerCommand);
|
|
8091
8248
|
var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
|
|
8092
8249
|
for (const cmd of cronCommand.commands) {
|
|
8093
8250
|
if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
|
|
@@ -8095,13 +8252,13 @@ for (const cmd of cronCommand.commands) {
|
|
|
8095
8252
|
}
|
|
8096
8253
|
|
|
8097
8254
|
// src/commands/managed/kind.ts
|
|
8098
|
-
import { Command as
|
|
8255
|
+
import { Command as Command120 } from "commander";
|
|
8099
8256
|
|
|
8100
8257
|
// src/commands/managed/backup/index.ts
|
|
8101
|
-
import { Command as
|
|
8258
|
+
import { Command as Command108 } from "commander";
|
|
8102
8259
|
|
|
8103
8260
|
// src/commands/managed/backup/create.ts
|
|
8104
|
-
import { Command as
|
|
8261
|
+
import { Command as Command103 } from "commander";
|
|
8105
8262
|
|
|
8106
8263
|
// src/commands/managed/shared.ts
|
|
8107
8264
|
import "commander";
|
|
@@ -8199,7 +8356,7 @@ function parseStorage(text2, flag) {
|
|
|
8199
8356
|
}
|
|
8200
8357
|
|
|
8201
8358
|
// src/commands/managed/backup/create.ts
|
|
8202
|
-
var createCommand10 = (spec) => new
|
|
8359
|
+
var createCommand10 = (spec) => new Command103("create").description("back up a database to the kvbox cloud (encrypted)").argument("<db>", "its name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (name, opts, cmd) => {
|
|
8203
8360
|
const client = await managedClient(cmd);
|
|
8204
8361
|
const ls = `kvbox ${spec.command} backup ls ${name}`;
|
|
8205
8362
|
try {
|
|
@@ -8226,7 +8383,7 @@ var createCommand10 = (spec) => new Command101("create").description("back up a
|
|
|
8226
8383
|
});
|
|
8227
8384
|
|
|
8228
8385
|
// src/commands/managed/backup/ls.ts
|
|
8229
|
-
import { Command as
|
|
8386
|
+
import { Command as Command104 } from "commander";
|
|
8230
8387
|
var lsCommand16 = (spec) => {
|
|
8231
8388
|
const removedOnes = async (err, name, client) => {
|
|
8232
8389
|
if (!(err instanceof CallError && err.status === 404)) throw err;
|
|
@@ -8235,7 +8392,7 @@ var lsCommand16 = (spec) => {
|
|
|
8235
8392
|
const own = name.includes("/") ? [] : gone.filter((b) => b.owner === me(client));
|
|
8236
8393
|
return own.length > 0 ? own : gone;
|
|
8237
8394
|
};
|
|
8238
|
-
return new
|
|
8395
|
+
return new Command104("ls").alias("list").description("list backups: every database's, or one database's").argument("[db]", "its name (default: every database)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8239
8396
|
const client = await managedClient(cmd);
|
|
8240
8397
|
try {
|
|
8241
8398
|
const list = name === void 0 ? await client.listManagedBackups(spec.kind) : await client.managedBackups(spec.kind, name).catch((err) => removedOnes(err, name, client));
|
|
@@ -8278,8 +8435,8 @@ var lsCommand16 = (spec) => {
|
|
|
8278
8435
|
};
|
|
8279
8436
|
|
|
8280
8437
|
// src/commands/managed/backup/restore.ts
|
|
8281
|
-
import { Command as
|
|
8282
|
-
var restoreCommand4 = (spec) => new
|
|
8438
|
+
import { Command as Command105 } from "commander";
|
|
8439
|
+
var restoreCommand4 = (spec) => new Command105("restore").description("put a backup back: the database's data becomes the backup's (it restarts)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").option("--json", "print the database as JSON").action(async (name, id, opts, cmd) => {
|
|
8283
8440
|
const client = await managedClient(cmd);
|
|
8284
8441
|
try {
|
|
8285
8442
|
const backup = await client.managedBackup(spec.kind, name, id);
|
|
@@ -8301,8 +8458,8 @@ var restoreCommand4 = (spec) => new Command103("restore").description("put a bac
|
|
|
8301
8458
|
});
|
|
8302
8459
|
|
|
8303
8460
|
// src/commands/managed/backup/rm.ts
|
|
8304
|
-
import { Command as
|
|
8305
|
-
var rmCommand16 = (spec) => new
|
|
8461
|
+
import { Command as Command106 } from "commander";
|
|
8462
|
+
var rmCommand16 = (spec) => new Command106("rm").alias("remove").description("remove a backup for good (a database's that is gone too)").argument("<db>", "its name").argument("<id>", `the backup's id (kvbox ${spec.command} backup ls <db>)`).option("-y, --yes", "do not ask for confirmation").action(async (name, id, opts, cmd) => {
|
|
8306
8463
|
const client = await managedClient(cmd);
|
|
8307
8464
|
try {
|
|
8308
8465
|
await removeListed(client, await client.listManagedBackups(spec.kind), (b) => b.name, name, id, `database ${name}`, opts.yes ?? false);
|
|
@@ -8312,8 +8469,8 @@ var rmCommand16 = (spec) => new Command104("rm").alias("remove").description("re
|
|
|
8312
8469
|
});
|
|
8313
8470
|
|
|
8314
8471
|
// src/commands/managed/backup/schedule.ts
|
|
8315
|
-
import { Command as
|
|
8316
|
-
var scheduleCommand = (spec) => new
|
|
8472
|
+
import { Command as Command107 } from "commander";
|
|
8473
|
+
var scheduleCommand = (spec) => new Command107("schedule").description("show or change when a database is backed up on its own (daily, UTC)").argument("<db>", "its name").option("--at <hour>", "back it up daily at this hour, 0-23 UTC (turns it on)").option("--off", "stop backing it up on its own").option("--on", "back it up on its own again, at the hour it had").option("--json", "print the schedule as JSON").action(async (name, opts, cmd) => {
|
|
8317
8474
|
if (opts.off && (opts.on || opts.at !== void 0)) throw new KvboxError("--off takes neither --on nor --at");
|
|
8318
8475
|
const hour = opts.at === void 0 ? void 0 : parseHour(opts.at);
|
|
8319
8476
|
const client = await managedClient(cmd);
|
|
@@ -8343,18 +8500,18 @@ function parseHour(text2) {
|
|
|
8343
8500
|
|
|
8344
8501
|
// src/commands/managed/backup/index.ts
|
|
8345
8502
|
var backupCommand4 = (spec) => {
|
|
8346
|
-
const command = new
|
|
8503
|
+
const command = new Command108("backup").description("back up a database to the kvbox cloud, list backups, restore or remove one, or change its nightly schedule");
|
|
8347
8504
|
for (const make of [createCommand10, lsCommand16, restoreCommand4, rmCommand16, scheduleCommand]) command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8348
8505
|
return command;
|
|
8349
8506
|
};
|
|
8350
8507
|
|
|
8351
8508
|
// src/commands/managed/create.ts
|
|
8352
|
-
import { Command as
|
|
8509
|
+
import { Command as Command109 } from "commander";
|
|
8353
8510
|
import { setTimeout as sleep5 } from "timers/promises";
|
|
8354
8511
|
var READY_WAIT_MS = 9e4;
|
|
8355
8512
|
var READY_STEP_MS = 2e3;
|
|
8356
8513
|
var createCommand11 = (spec) => {
|
|
8357
|
-
const command = new
|
|
8514
|
+
const command = new Command109("create").alias("new").description(`create a ${spec.title} database: a name is all it needs`).argument("<name>", "its name (1-12 chars, lowercase letters, digits and '-'); a linked box reaches it at <name>.<account>.kvbox");
|
|
8358
8515
|
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
8359
8516
|
return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--from-backup <id>", `start it on this backup's data, a removed database's too (kvbox ${spec.command} backup ls)`).option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
|
|
8360
8517
|
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
@@ -8403,8 +8560,8 @@ var createCommand11 = (spec) => {
|
|
|
8403
8560
|
};
|
|
8404
8561
|
|
|
8405
8562
|
// src/commands/managed/grow.ts
|
|
8406
|
-
import { Command as
|
|
8407
|
-
var growCommand3 = (spec) => new
|
|
8563
|
+
import { Command as Command110 } from "commander";
|
|
8564
|
+
var growCommand3 = (spec) => new Command110("grow").description("give a database more storage (it restarts once)").argument("<db>", "its name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print as JSON").action(async (name, size, opts, cmd) => {
|
|
8408
8565
|
const storageGib = parseStorage(size, "size");
|
|
8409
8566
|
const client = await managedClient(cmd);
|
|
8410
8567
|
try {
|
|
@@ -8417,8 +8574,8 @@ var growCommand3 = (spec) => new Command108("grow").description("give a database
|
|
|
8417
8574
|
});
|
|
8418
8575
|
|
|
8419
8576
|
// src/commands/managed/info.ts
|
|
8420
|
-
import { Command as
|
|
8421
|
-
var infoCommand3 = (spec) => new
|
|
8577
|
+
import { Command as Command111 } from "commander";
|
|
8578
|
+
var infoCommand3 = (spec) => new Command111("info").alias("get").description("show one database: status, storage used, how to connect").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8422
8579
|
const client = await managedClient(cmd);
|
|
8423
8580
|
try {
|
|
8424
8581
|
const m = await client.getManaged(spec.kind, name);
|
|
@@ -8430,8 +8587,8 @@ var infoCommand3 = (spec) => new Command109("info").alias("get").description("sh
|
|
|
8430
8587
|
});
|
|
8431
8588
|
|
|
8432
8589
|
// src/commands/managed/link.ts
|
|
8433
|
-
import { Command as
|
|
8434
|
-
var linkCommand2 = (spec) => new
|
|
8590
|
+
import { Command as Command112 } from "commander";
|
|
8591
|
+
var linkCommand2 = (spec) => new Command112("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
|
|
8435
8592
|
const client = await managedClient(cmd);
|
|
8436
8593
|
try {
|
|
8437
8594
|
const m = await spin(`linking ${box2} to ${name}\u2026`, client.linkManaged(spec.kind, name, box2));
|
|
@@ -8447,7 +8604,7 @@ var linkCommand2 = (spec) => new Command110("link").description("let a box reach
|
|
|
8447
8604
|
});
|
|
8448
8605
|
|
|
8449
8606
|
// src/commands/managed/ls.ts
|
|
8450
|
-
import { Command as
|
|
8607
|
+
import { Command as Command113 } from "commander";
|
|
8451
8608
|
function listRows(items, user, kindColumn) {
|
|
8452
8609
|
return items.map((m) => ({
|
|
8453
8610
|
owner: m.owner === user ? "private" : m.owner,
|
|
@@ -8461,7 +8618,7 @@ function listRows(items, user, kindColumn) {
|
|
|
8461
8618
|
created: age(m.createdAt)
|
|
8462
8619
|
}));
|
|
8463
8620
|
}
|
|
8464
|
-
var lsCommand17 = (spec) => new
|
|
8621
|
+
var lsCommand17 = (spec) => new Command113("ls").alias("list").description(spec ? `list your ${spec.title} databases` : "list every managed database, whatever its kind").option("-a, --all", "every one on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
8465
8622
|
const client = await managedClient(cmd);
|
|
8466
8623
|
try {
|
|
8467
8624
|
const items = await client.listManaged(spec?.kind, { all: opts.all });
|
|
@@ -8481,8 +8638,8 @@ var lsCommand17 = (spec) => new Command111("ls").alias("list").description(spec
|
|
|
8481
8638
|
});
|
|
8482
8639
|
|
|
8483
8640
|
// src/commands/managed/password.ts
|
|
8484
|
-
import { Command as
|
|
8485
|
-
var passwordCommand = (spec) => new
|
|
8641
|
+
import { Command as Command114 } from "commander";
|
|
8642
|
+
var passwordCommand = (spec) => new Command114("password").description("show a database's password, or set a new one with --reset").argument("<db>", "its name").option("--reset", "make a new password; the old one stops working").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8486
8643
|
const client = await managedClient(cmd);
|
|
8487
8644
|
try {
|
|
8488
8645
|
const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
|
|
@@ -8498,8 +8655,8 @@ var passwordCommand = (spec) => new Command112("password").description("show a d
|
|
|
8498
8655
|
});
|
|
8499
8656
|
|
|
8500
8657
|
// src/commands/managed/public.ts
|
|
8501
|
-
import { Command as
|
|
8502
|
-
var
|
|
8658
|
+
import { Command as Command115 } from "commander";
|
|
8659
|
+
var publicCommand2 = (spec) => new Command115("public").description("open a database to the internet, or close it again").argument("<db>", "its name").argument("<state>", "on: reachable from anywhere with the password; off: only linked boxes").option("--json", "print as JSON").action(async (name, state, opts, cmd) => {
|
|
8503
8660
|
if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
|
|
8504
8661
|
const client = await managedClient(cmd);
|
|
8505
8662
|
try {
|
|
@@ -8520,8 +8677,8 @@ var publicCommand = (spec) => new Command113("public").description("open a datab
|
|
|
8520
8677
|
});
|
|
8521
8678
|
|
|
8522
8679
|
// src/commands/managed/rm.ts
|
|
8523
|
-
import { Command as
|
|
8524
|
-
var rmCommand17 = (spec) => new
|
|
8680
|
+
import { Command as Command116 } from "commander";
|
|
8681
|
+
var rmCommand17 = (spec) => new Command116("rm").alias("remove").description("delete a database and all its data").argument("<db>", "its name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
8525
8682
|
const client = await managedClient(cmd);
|
|
8526
8683
|
try {
|
|
8527
8684
|
if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
|
|
@@ -8537,8 +8694,8 @@ var rmCommand17 = (spec) => new Command114("rm").alias("remove").description("de
|
|
|
8537
8694
|
});
|
|
8538
8695
|
|
|
8539
8696
|
// src/commands/managed/start.ts
|
|
8540
|
-
import { Command as
|
|
8541
|
-
var startCommand2 = (spec) => new
|
|
8697
|
+
import { Command as Command117 } from "commander";
|
|
8698
|
+
var startCommand2 = (spec) => new Command117("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8542
8699
|
const client = await managedClient(cmd);
|
|
8543
8700
|
try {
|
|
8544
8701
|
const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
|
|
@@ -8550,8 +8707,8 @@ var startCommand2 = (spec) => new Command115("start").description("run a stopped
|
|
|
8550
8707
|
});
|
|
8551
8708
|
|
|
8552
8709
|
// src/commands/managed/stop.ts
|
|
8553
|
-
import { Command as
|
|
8554
|
-
var stopCommand2 = (spec) => new
|
|
8710
|
+
import { Command as Command118 } from "commander";
|
|
8711
|
+
var stopCommand2 = (spec) => new Command118("stop").description("shut a database down, keeping its data (only its storage is charged)").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
8555
8712
|
const client = await managedClient(cmd);
|
|
8556
8713
|
try {
|
|
8557
8714
|
const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
|
|
@@ -8563,8 +8720,8 @@ var stopCommand2 = (spec) => new Command116("stop").description("shut a database
|
|
|
8563
8720
|
});
|
|
8564
8721
|
|
|
8565
8722
|
// src/commands/managed/unlink.ts
|
|
8566
|
-
import { Command as
|
|
8567
|
-
var unlinkCommand2 = (spec) => new
|
|
8723
|
+
import { Command as Command119 } from "commander";
|
|
8724
|
+
var unlinkCommand2 = (spec) => new Command119("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
|
|
8568
8725
|
const client = await managedClient(cmd);
|
|
8569
8726
|
try {
|
|
8570
8727
|
const m = await spin(`unlinking ${box2} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box2));
|
|
@@ -8577,8 +8734,8 @@ var unlinkCommand2 = (spec) => new Command117("unlink").description("stop a box
|
|
|
8577
8734
|
|
|
8578
8735
|
// src/commands/managed/kind.ts
|
|
8579
8736
|
function kindCommand(spec, description) {
|
|
8580
|
-
const command = new
|
|
8581
|
-
for (const make of [createCommand11, lsCommand17, infoCommand3, passwordCommand,
|
|
8737
|
+
const command = new Command120(spec.command).aliases(spec.aliases).description(description);
|
|
8738
|
+
for (const make of [createCommand11, lsCommand17, infoCommand3, passwordCommand, publicCommand2, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand17]) {
|
|
8582
8739
|
command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8583
8740
|
}
|
|
8584
8741
|
command.addCommand(backupCommand4(spec));
|
|
@@ -8592,14 +8749,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
|
|
|
8592
8749
|
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
8593
8750
|
|
|
8594
8751
|
// src/commands/managed/index.ts
|
|
8595
|
-
import { Command as
|
|
8596
|
-
var managedCommand = new
|
|
8752
|
+
import { Command as Command121 } from "commander";
|
|
8753
|
+
var managedCommand = new Command121("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand17().option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8597
8754
|
|
|
8598
8755
|
// src/commands/env/index.ts
|
|
8599
|
-
import { Command as
|
|
8756
|
+
import { Command as Command125 } from "commander";
|
|
8600
8757
|
|
|
8601
8758
|
// src/commands/env/ls.ts
|
|
8602
|
-
import { Command as
|
|
8759
|
+
import { Command as Command122 } from "commander";
|
|
8603
8760
|
|
|
8604
8761
|
// src/commands/env/shared.ts
|
|
8605
8762
|
function requireCloud4(client) {
|
|
@@ -8626,7 +8783,7 @@ function firstBootHint(box2, name) {
|
|
|
8626
8783
|
}
|
|
8627
8784
|
|
|
8628
8785
|
// src/commands/env/ls.ts
|
|
8629
|
-
var lsCommand18 = new
|
|
8786
|
+
var lsCommand18 = new Command122("ls").alias("list").description("list the variables (a secret shows as (sealed))").option("--box <box>", "what this box gets: its own variables and the ones it inherits").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
8630
8787
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8631
8788
|
try {
|
|
8632
8789
|
if (opts.box !== void 0) {
|
|
@@ -8665,8 +8822,8 @@ var lsCommand18 = new Command120("ls").alias("list").description("list the varia
|
|
|
8665
8822
|
});
|
|
8666
8823
|
|
|
8667
8824
|
// src/commands/env/rm.ts
|
|
8668
|
-
import { Command as
|
|
8669
|
-
var rmCommand18 = new
|
|
8825
|
+
import { Command as Command123 } from "commander";
|
|
8826
|
+
var rmCommand18 = new Command123("rm").alias("remove").description("remove variables; boxes lose them when they next start").argument("<names...>", "variable names").option("-y, --yes", "do not ask for confirmation").option("--box <box>", "remove this box's own variables (yours, or the org's, of the same name come back)").option("--json", "print as JSON").action(async (names2, opts, cmd) => {
|
|
8670
8827
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8671
8828
|
try {
|
|
8672
8829
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -8703,8 +8860,8 @@ var rmCommand18 = new Command121("rm").alias("remove").description("remove varia
|
|
|
8703
8860
|
});
|
|
8704
8861
|
|
|
8705
8862
|
// src/commands/env/set.ts
|
|
8706
|
-
import { Command as
|
|
8707
|
-
var setCommand2 = new
|
|
8863
|
+
import { Command as Command124 } from "commander";
|
|
8864
|
+
var setCommand2 = new Command124("set").description("add or change a variable; boxes get it when they next start").argument("[name]", "variable name, e.g. DATABASE_URL (asked for when left out)").argument("[value]", "its value (asked for when left out; hidden with --secret)").option("--secret", "write-only: the value is never shown again, by any command").option("--box <box>", "this box's own variable, over yours (or the org's) of the same name").option("--json", "print as JSON").action(async (nameArg, valueArg, opts, cmd) => {
|
|
8708
8865
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8709
8866
|
try {
|
|
8710
8867
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -8741,14 +8898,14 @@ var setCommand2 = new Command122("set").description("add or change a variable; b
|
|
|
8741
8898
|
});
|
|
8742
8899
|
|
|
8743
8900
|
// src/commands/env/index.ts
|
|
8744
|
-
var envCommand = new
|
|
8901
|
+
var envCommand = new Command125("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand18, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand18);
|
|
8745
8902
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
8746
8903
|
|
|
8747
8904
|
// src/commands/domain/index.ts
|
|
8748
|
-
import { Command as
|
|
8905
|
+
import { Command as Command129 } from "commander";
|
|
8749
8906
|
|
|
8750
8907
|
// src/commands/domain/add.ts
|
|
8751
|
-
import { Command as
|
|
8908
|
+
import { Command as Command126 } from "commander";
|
|
8752
8909
|
|
|
8753
8910
|
// src/commands/domain/shared.ts
|
|
8754
8911
|
function requireCloud5(client) {
|
|
@@ -8768,7 +8925,7 @@ function hostIn(name, zone) {
|
|
|
8768
8925
|
}
|
|
8769
8926
|
|
|
8770
8927
|
// src/commands/domain/add.ts
|
|
8771
|
-
var addCommand4 = new
|
|
8928
|
+
var addCommand4 = new Command126("add").description("serve a box at a domain of your own, https://<domain>, with its certificate made for you").argument("<domain>", "a domain you control, like example.com or app.example.com").argument("<box>", "box name").option("--port <port>", "the box port the domain serves (default: the port of its kvbox.app address)").option("--json", "print the domain as JSON").action(async (domainArg, name, opts, cmd) => {
|
|
8772
8929
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
8773
8930
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
8774
8931
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -8804,8 +8961,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
8804
8961
|
});
|
|
8805
8962
|
|
|
8806
8963
|
// src/commands/domain/ls.ts
|
|
8807
|
-
import { Command as
|
|
8808
|
-
var lsCommand19 = new
|
|
8964
|
+
import { Command as Command127 } from "commander";
|
|
8965
|
+
var lsCommand19 = new Command127("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
8809
8966
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8810
8967
|
try {
|
|
8811
8968
|
requireCloud5(client);
|
|
@@ -8834,8 +8991,8 @@ var lsCommand19 = new Command125("ls").alias("list").description("list your cust
|
|
|
8834
8991
|
});
|
|
8835
8992
|
|
|
8836
8993
|
// src/commands/domain/rm.ts
|
|
8837
|
-
import { Command as
|
|
8838
|
-
var rmCommand19 = new
|
|
8994
|
+
import { Command as Command128 } from "commander";
|
|
8995
|
+
var rmCommand19 = new Command128("rm").alias("remove").description("stop serving a box at a custom domain").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (domainArg, opts, cmd) => {
|
|
8839
8996
|
const domain = domainArg.trim().toLowerCase();
|
|
8840
8997
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8841
8998
|
try {
|
|
@@ -8856,15 +9013,15 @@ var rmCommand19 = new Command126("rm").alias("remove").description("stop serving
|
|
|
8856
9013
|
});
|
|
8857
9014
|
|
|
8858
9015
|
// src/commands/domain/index.ts
|
|
8859
|
-
var domainCommand = new
|
|
9016
|
+
var domainCommand = new Command129("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand19).addCommand(rmCommand19);
|
|
8860
9017
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
8861
9018
|
|
|
8862
9019
|
// src/commands/update.ts
|
|
8863
|
-
import { spawn as
|
|
9020
|
+
import { spawn as spawn8 } from "child_process";
|
|
8864
9021
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
8865
9022
|
import { tmpdir } from "os";
|
|
8866
9023
|
import { join as join9 } from "path";
|
|
8867
|
-
import { Command as
|
|
9024
|
+
import { Command as Command130 } from "commander";
|
|
8868
9025
|
|
|
8869
9026
|
// src/update.ts
|
|
8870
9027
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -8978,12 +9135,12 @@ async function download(url) {
|
|
|
8978
9135
|
}
|
|
8979
9136
|
function run2(cmd, args) {
|
|
8980
9137
|
return new Promise((resolve4, reject) => {
|
|
8981
|
-
const child =
|
|
9138
|
+
const child = spawn8(cmd, args, { stdio: "inherit" });
|
|
8982
9139
|
child.on("error", (err) => reject(new KvboxError(`could not run ${cmd}: ${err.message}`)));
|
|
8983
9140
|
child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
|
|
8984
9141
|
});
|
|
8985
9142
|
}
|
|
8986
|
-
var selfUpdateCommand = new
|
|
9143
|
+
var selfUpdateCommand = new Command130("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
|
|
8987
9144
|
suppressUpdateNotice();
|
|
8988
9145
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
8989
9146
|
let code;
|
|
@@ -9025,6 +9182,7 @@ var HELP_GROUPS = [
|
|
|
9025
9182
|
["get", "show one box in full"],
|
|
9026
9183
|
["connect", "open a shell in a box, or run a command there (short: cn)"],
|
|
9027
9184
|
["exec", "run a command in a box and exit with its status"],
|
|
9185
|
+
["cp", "copy files between this machine and a box"],
|
|
9028
9186
|
["claim", "give a box an HTTPS address, https://<name>.kvbox.app"],
|
|
9029
9187
|
["deploy", "put the app in this directory on a box with its own HTTPS address"],
|
|
9030
9188
|
["rm", "destroy a box and its disk"]
|
|
@@ -9110,7 +9268,7 @@ function installRootHelp(program) {
|
|
|
9110
9268
|
|
|
9111
9269
|
// src/program.ts
|
|
9112
9270
|
function buildProgram() {
|
|
9113
|
-
const program = new
|
|
9271
|
+
const program = new Command131("kvbox").description("self-hosted Firecracker microVMs with Docker-like ergonomics").version(VERSION, "-v, --version").option("--local", "use this machine's kvbox-server over its socket, ignoring kvbox login and KVBOX_TOKEN").option("--org <slug>", "the org: where kvbox new creates, and which box a name means when it is not one of yours; before the command here, or after it").showHelpAfterError().enablePositionalOptions();
|
|
9114
9272
|
program.addCommand(vmCommand);
|
|
9115
9273
|
program.addCommand(snapshotsCommand);
|
|
9116
9274
|
program.addCommand(volumeCommand);
|