@kvbox/cli 0.6.11 → 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 +196 -101
- 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,7 +170,7 @@ 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
176
|
import { Command as Command39 } from "commander";
|
|
@@ -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
|
/**
|
|
@@ -913,7 +925,9 @@ var CapacitySchema = z.object({
|
|
|
913
925
|
/** Present on a host set up as a backup store: the disk its Garage keeps chunks on, and whether Garage runs. */
|
|
914
926
|
backupStore: z.object({ totalBytes: z.number().int(), freeBytes: z.number().int(), running: z.boolean() }).optional(),
|
|
915
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. */
|
|
916
|
-
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()
|
|
917
931
|
});
|
|
918
932
|
var ImageSchema = z.object({ name: z.string(), version: z.string().nullable() });
|
|
919
933
|
var ImageIndexSchema = z.object({
|
|
@@ -1696,6 +1710,7 @@ var FORK_TIMEOUT_MS = 66e4;
|
|
|
1696
1710
|
var listQuery = (opts) => opts.all ? "?all=1" : "";
|
|
1697
1711
|
var box = (name, rest = "") => `/machines/${encodeURIComponent(name)}${rest}`;
|
|
1698
1712
|
var sleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
1713
|
+
var FROM_BACKUP_TIMEOUT_MS = 2 * 36e5;
|
|
1699
1714
|
var passing = (err) => err instanceof KvboxConnectionError || err instanceof KvboxTimeoutError || err instanceof KvboxApiError && [502, 503, 504].includes(err.status);
|
|
1700
1715
|
var Machines = class {
|
|
1701
1716
|
constructor(transport) {
|
|
@@ -1739,9 +1754,15 @@ var Machines = class {
|
|
|
1739
1754
|
* system inside is still booting for a few seconds after (see `waitUntilReady`). A box from an
|
|
1740
1755
|
* image that serves something answers `connect` (its URL with the password) this once.
|
|
1741
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.
|
|
1742
1759
|
*/
|
|
1743
|
-
create(req = {}, opts = {}) {
|
|
1744
|
-
|
|
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;
|
|
1745
1766
|
}
|
|
1746
1767
|
/** Remove the box and its disk. */
|
|
1747
1768
|
async remove(name, opts = {}) {
|
|
@@ -2369,6 +2390,8 @@ var cronTarget = (t) => t.kind === "command" ? `${t.box}$ ${t.command}` : `${t.m
|
|
|
2369
2390
|
// ../shared/src/storage.ts
|
|
2370
2391
|
import { z as z10 } from "zod";
|
|
2371
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;
|
|
2372
2395
|
var ObjectStorageSchema = z10.object({
|
|
2373
2396
|
owner: z10.string(),
|
|
2374
2397
|
ownerKind: z10.enum(["user", "org"]),
|
|
@@ -2396,6 +2419,7 @@ var BucketSchema = z10.object({
|
|
|
2396
2419
|
owner: z10.string(),
|
|
2397
2420
|
ownerKind: z10.enum(["user", "org"]),
|
|
2398
2421
|
endpoint: z10.string().nullable(),
|
|
2422
|
+
publicUrl: z10.string().optional(),
|
|
2399
2423
|
region: z10.string(),
|
|
2400
2424
|
keys: z10.number().int(),
|
|
2401
2425
|
objects: z10.number().optional(),
|
|
@@ -2411,6 +2435,7 @@ var CreateBucketRequest = z10.object({
|
|
|
2411
2435
|
});
|
|
2412
2436
|
var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z10.boolean() });
|
|
2413
2437
|
var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
|
|
2438
|
+
var SetBucketPublicRequest = z10.object({ on: z10.boolean(), sub: z10.string().optional() });
|
|
2414
2439
|
var BucketKeySchema = z10.object({
|
|
2415
2440
|
id: z10.string(),
|
|
2416
2441
|
name: z10.string(),
|
|
@@ -2681,7 +2706,7 @@ var ServerClient = class {
|
|
|
2681
2706
|
return this.call("GET", `/machines${allQuery(opts)}`, z11.array(MachineSchema), void 0, opts.org);
|
|
2682
2707
|
}
|
|
2683
2708
|
createMachine(req) {
|
|
2684
|
-
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);
|
|
2685
2710
|
}
|
|
2686
2711
|
/** `kvbox vm fork` (#79): `name` is the source; the copy goes to the `--org` slug, else the caller's own. */
|
|
2687
2712
|
forkMachine(name, req) {
|
|
@@ -2945,6 +2970,10 @@ var ServerClient = class {
|
|
|
2945
2970
|
getBucket(name) {
|
|
2946
2971
|
return this.call("GET", `/buckets/${encodeURIComponent(name)}`, BucketInfoSchema);
|
|
2947
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
|
+
}
|
|
2948
2977
|
deleteBucket(name, force = false) {
|
|
2949
2978
|
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z11.undefined());
|
|
2950
2979
|
}
|
|
@@ -3536,12 +3565,20 @@ function parseDuration(text2) {
|
|
|
3536
3565
|
}
|
|
3537
3566
|
|
|
3538
3567
|
// src/commands/vm/new.ts
|
|
3539
|
-
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) => {
|
|
3540
3569
|
const autoHibernateSec = opts.autoHibernate === void 0 ? void 0 : parseIdleTimeout(opts.autoHibernate);
|
|
3541
3570
|
const env = parseEnvFlags(opts.env);
|
|
3542
3571
|
const country = opts.country === void 0 ? void 0 : parseCountry(opts.country);
|
|
3543
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
|
+
}
|
|
3544
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
|
+
}
|
|
3545
3582
|
if (country !== void 0 && client.target.kind !== "cloud") {
|
|
3546
3583
|
await client.close();
|
|
3547
3584
|
throw new KvboxError("--country picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
@@ -3551,11 +3588,12 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
3551
3588
|
throw new KvboxError("--host picks a host through the control plane; this machine is the only host here (kvbox login first)");
|
|
3552
3589
|
}
|
|
3553
3590
|
try {
|
|
3554
|
-
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`;
|
|
3555
3592
|
const box2 = await spin(what, client.createMachine({
|
|
3556
3593
|
...name !== void 0 ? { name } : {},
|
|
3557
3594
|
...opts.size !== void 0 ? { size: opts.size } : {},
|
|
3558
3595
|
...opts.from !== void 0 ? { from: opts.from } : {},
|
|
3596
|
+
...opts.fromBackup !== void 0 ? { fromBackup: opts.fromBackup } : {},
|
|
3559
3597
|
...opts.base !== void 0 ? { image: opts.base } : {},
|
|
3560
3598
|
...env.length > 0 ? { env } : {},
|
|
3561
3599
|
...opts.near !== void 0 ? { near: opts.near } : {},
|
|
@@ -3564,6 +3602,9 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
3564
3602
|
...autoHibernateSec !== void 0 ? { autoHibernateSec } : {},
|
|
3565
3603
|
...opts.force ? { force: true } : {}
|
|
3566
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
|
+
}
|
|
3567
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`);
|
|
3568
3609
|
if (opts.base !== void 0 && opts.base !== "base" && box2.image === void 0) {
|
|
3569
3610
|
warn(`box ${box2.name}: its host runs a kvbox-server too old for images; it booted the base image, not ${opts.base}`);
|
|
@@ -3582,6 +3623,7 @@ var newCommand = new Command("new").description("boot a new box from an image (t
|
|
|
3582
3623
|
`);
|
|
3583
3624
|
info(`${color.green("\u2713")} ${describe(box2, user)}`);
|
|
3584
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)`);
|
|
3585
3627
|
else info(` connect with: kvbox connect ${displayName(box2, user)} (SSH is up a couple of seconds after boot)`);
|
|
3586
3628
|
if (box2.autoHibernateSec) info(` it ${autoHibernateText(box2.autoHibernateSec, box2.idleCheck)}`);
|
|
3587
3629
|
if (box2.connect !== void 0) {
|
|
@@ -4579,8 +4621,7 @@ var lsCommand4 = new Command25("ls").alias("list").description("list backups: ev
|
|
|
4579
4621
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4580
4622
|
try {
|
|
4581
4623
|
requireCloud3(client);
|
|
4582
|
-
const
|
|
4583
|
-
const list = box2 === void 0 ? await client.listBackups() : await client.boxBackups(box2);
|
|
4624
|
+
const { box: box2, list } = await backupsOf(client, name);
|
|
4584
4625
|
if (opts.json) {
|
|
4585
4626
|
json(list);
|
|
4586
4627
|
return;
|
|
@@ -4590,10 +4631,12 @@ var lsCommand4 = new Command25("ls").alias("list").description("list backups: ev
|
|
|
4590
4631
|
return;
|
|
4591
4632
|
}
|
|
4592
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)") : "";
|
|
4593
4636
|
table(
|
|
4594
4637
|
list.map((b) => ({
|
|
4595
4638
|
id: b.id,
|
|
4596
|
-
...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" } : {},
|
|
4597
4640
|
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
4598
4641
|
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
4599
4642
|
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
@@ -4603,10 +4646,31 @@ var lsCommand4 = new Command25("ls").alias("list").description("list backups: ev
|
|
|
4603
4646
|
...anyError ? { error: b.error ?? "" } : {}
|
|
4604
4647
|
}))
|
|
4605
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
|
+
}
|
|
4606
4653
|
} finally {
|
|
4607
4654
|
await client.close();
|
|
4608
4655
|
}
|
|
4609
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
|
+
}
|
|
4610
4674
|
|
|
4611
4675
|
// src/commands/vm/backup/restore.ts
|
|
4612
4676
|
import { Command as Command26 } from "commander";
|
|
@@ -7495,7 +7559,7 @@ for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in thi
|
|
|
7495
7559
|
volumeCommand.addCommand(backupCommand2);
|
|
7496
7560
|
|
|
7497
7561
|
// src/commands/bucket/index.ts
|
|
7498
|
-
import { Command as
|
|
7562
|
+
import { Command as Command88 } from "commander";
|
|
7499
7563
|
|
|
7500
7564
|
// src/commands/bucket/backup/index.ts
|
|
7501
7565
|
import { Command as Command77 } from "commander";
|
|
@@ -7692,6 +7756,7 @@ var infoCommand = new Command80("info").description("one bucket: its address, wh
|
|
|
7692
7756
|
["name", color.bold(shown)],
|
|
7693
7757
|
["endpoint", endpointText(b.endpoint)],
|
|
7694
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)")}`],
|
|
7695
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)}`],
|
|
7696
7761
|
["keys", b.keys === 0 ? color.dim(`none (kvbox bucket key create ${shown})`) : `${b.keys} ${color.dim(`(kvbox bucket key ls ${shown})`)}`],
|
|
7697
7762
|
["storage", `${fullness(s)}, ${s.buckets} ${s.buckets === 1 ? "bucket" : "buckets"}${nearlyFull(s) ? color.yellow(" almost full: kvbox bucket grow <GB>") : ""}`],
|
|
@@ -7793,6 +7858,7 @@ var lsCommand13 = new Command85("ls").alias("list").description("list buckets, a
|
|
|
7793
7858
|
owner: b.owner === me2 ? "private" : b.owner,
|
|
7794
7859
|
name: b.name,
|
|
7795
7860
|
keys: b.keys,
|
|
7861
|
+
public: b.publicUrl ?? "-",
|
|
7796
7862
|
created: age(b.createdAt)
|
|
7797
7863
|
}))
|
|
7798
7864
|
);
|
|
@@ -7804,9 +7870,38 @@ var lsCommand13 = new Command85("ls").alias("list").description("list buckets, a
|
|
|
7804
7870
|
}
|
|
7805
7871
|
});
|
|
7806
7872
|
|
|
7807
|
-
// src/commands/bucket/
|
|
7873
|
+
// src/commands/bucket/public.ts
|
|
7808
7874
|
import { Command as Command86 } from "commander";
|
|
7809
|
-
var
|
|
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
|
+
|
|
7902
|
+
// src/commands/bucket/rm.ts
|
|
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) => {
|
|
7810
7905
|
const client = await bucketClient(cmd);
|
|
7811
7906
|
try {
|
|
7812
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?`;
|
|
@@ -7825,7 +7920,7 @@ var rmCommand13 = new Command86("rm").alias("remove").description("delete an emp
|
|
|
7825
7920
|
});
|
|
7826
7921
|
|
|
7827
7922
|
// src/commands/bucket/index.ts
|
|
7828
|
-
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);
|
|
7829
7924
|
var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
|
|
7830
7925
|
for (const cmd of bucketCommand.commands) {
|
|
7831
7926
|
if (cmd === keyCommand2 || cmd === backupCommand3) cmd.commands.forEach(withOrg);
|
|
@@ -7833,10 +7928,10 @@ for (const cmd of bucketCommand.commands) {
|
|
|
7833
7928
|
}
|
|
7834
7929
|
|
|
7835
7930
|
// src/commands/cron/index.ts
|
|
7836
|
-
import { Command as
|
|
7931
|
+
import { Command as Command101 } from "commander";
|
|
7837
7932
|
|
|
7838
7933
|
// src/commands/cron/create.ts
|
|
7839
|
-
import { Command as
|
|
7934
|
+
import { Command as Command89 } from "commander";
|
|
7840
7935
|
|
|
7841
7936
|
// src/commands/cron/shared.ts
|
|
7842
7937
|
async function cronClient(cmd) {
|
|
@@ -7897,7 +7992,7 @@ function printRows2(rows2) {
|
|
|
7897
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>")`);
|
|
7898
7993
|
|
|
7899
7994
|
// src/commands/cron/create.ts
|
|
7900
|
-
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) => {
|
|
7901
7996
|
const client = await cronClient(cmd);
|
|
7902
7997
|
try {
|
|
7903
7998
|
const service = await client.createCronService(name);
|
|
@@ -7914,8 +8009,8 @@ var createCommand9 = new Command88("create").description("make a cron service: a
|
|
|
7914
8009
|
});
|
|
7915
8010
|
|
|
7916
8011
|
// src/commands/cron/info.ts
|
|
7917
|
-
import { Command as
|
|
7918
|
-
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) => {
|
|
7919
8014
|
const client = await cronClient(cmd);
|
|
7920
8015
|
try {
|
|
7921
8016
|
const service = await client.getCronService(name);
|
|
@@ -7939,8 +8034,8 @@ var infoCommand2 = new Command89("info").alias("get").description("show a cron s
|
|
|
7939
8034
|
});
|
|
7940
8035
|
|
|
7941
8036
|
// src/commands/cron/ls.ts
|
|
7942
|
-
import { Command as
|
|
7943
|
-
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) => {
|
|
7944
8039
|
const client = await cronClient(cmd);
|
|
7945
8040
|
try {
|
|
7946
8041
|
const services = await client.listCronServices({ all: opts.all });
|
|
@@ -7960,8 +8055,8 @@ var lsCommand14 = new Command90("ls").alias("list").description("list cron servi
|
|
|
7960
8055
|
});
|
|
7961
8056
|
|
|
7962
8057
|
// src/commands/cron/rm.ts
|
|
7963
|
-
import { Command as
|
|
7964
|
-
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) => {
|
|
7965
8060
|
const client = await cronClient(cmd);
|
|
7966
8061
|
try {
|
|
7967
8062
|
if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
|
|
@@ -7977,10 +8072,10 @@ var rmCommand14 = new Command91("rm").alias("remove").description("delete a cron
|
|
|
7977
8072
|
});
|
|
7978
8073
|
|
|
7979
8074
|
// src/commands/cron/trigger/index.ts
|
|
7980
|
-
import { Command as
|
|
8075
|
+
import { Command as Command100 } from "commander";
|
|
7981
8076
|
|
|
7982
8077
|
// src/commands/cron/trigger/add.ts
|
|
7983
|
-
import { Command as
|
|
8078
|
+
import { Command as Command93 } from "commander";
|
|
7984
8079
|
function portOf(value) {
|
|
7985
8080
|
const n = Number(value);
|
|
7986
8081
|
if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
|
|
@@ -8000,7 +8095,7 @@ function timeoutOf(value) {
|
|
|
8000
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`);
|
|
8001
8096
|
return sec;
|
|
8002
8097
|
}
|
|
8003
|
-
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) => {
|
|
8004
8099
|
let action;
|
|
8005
8100
|
if (opts.run !== void 0) {
|
|
8006
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");
|
|
@@ -8027,8 +8122,8 @@ var addCommand3 = new Command92("add").description("add a trigger: on a schedule
|
|
|
8027
8122
|
});
|
|
8028
8123
|
|
|
8029
8124
|
// src/commands/cron/trigger/ls.ts
|
|
8030
|
-
import { Command as
|
|
8031
|
-
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) => {
|
|
8032
8127
|
const client = await cronClient(cmd);
|
|
8033
8128
|
try {
|
|
8034
8129
|
const triggers = await client.listCronTriggers(service);
|
|
@@ -8044,8 +8139,8 @@ var lsCommand15 = new Command93("ls").alias("list").description("list a cron ser
|
|
|
8044
8139
|
});
|
|
8045
8140
|
|
|
8046
8141
|
// src/commands/cron/trigger/pause.ts
|
|
8047
|
-
import { Command as
|
|
8048
|
-
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) => {
|
|
8049
8144
|
const client = await cronClient(cmd);
|
|
8050
8145
|
try {
|
|
8051
8146
|
const trigger = await client.setCronTriggerEnabled(service, id, false);
|
|
@@ -8060,8 +8155,8 @@ var pauseCommand2 = new Command94("pause").description("stop a trigger from firi
|
|
|
8060
8155
|
});
|
|
8061
8156
|
|
|
8062
8157
|
// src/commands/cron/trigger/resume.ts
|
|
8063
|
-
import { Command as
|
|
8064
|
-
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) => {
|
|
8065
8160
|
const client = await cronClient(cmd);
|
|
8066
8161
|
try {
|
|
8067
8162
|
const trigger = await client.setCronTriggerEnabled(service, id, true);
|
|
@@ -8076,8 +8171,8 @@ var resumeCommand2 = new Command95("resume").description("let a paused trigger f
|
|
|
8076
8171
|
});
|
|
8077
8172
|
|
|
8078
8173
|
// src/commands/cron/trigger/rm.ts
|
|
8079
|
-
import { Command as
|
|
8080
|
-
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) => {
|
|
8081
8176
|
const client = await cronClient(cmd);
|
|
8082
8177
|
try {
|
|
8083
8178
|
if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
|
|
@@ -8093,8 +8188,8 @@ var rmCommand15 = new Command96("rm").alias("remove").description("delete a trig
|
|
|
8093
8188
|
});
|
|
8094
8189
|
|
|
8095
8190
|
// src/commands/cron/trigger/run.ts
|
|
8096
|
-
import { Command as
|
|
8097
|
-
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) => {
|
|
8098
8193
|
const client = await cronClient(cmd);
|
|
8099
8194
|
try {
|
|
8100
8195
|
const trigger = await client.runCronTrigger(service, id);
|
|
@@ -8110,13 +8205,13 @@ var runCommand = new Command97("run").description("fire a trigger now, once, bes
|
|
|
8110
8205
|
});
|
|
8111
8206
|
|
|
8112
8207
|
// src/commands/cron/trigger/runs.ts
|
|
8113
|
-
import { Command as
|
|
8208
|
+
import { Command as Command99 } from "commander";
|
|
8114
8209
|
function limitOf(value) {
|
|
8115
8210
|
const n = Number(value);
|
|
8116
8211
|
if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
|
|
8117
8212
|
return n;
|
|
8118
8213
|
}
|
|
8119
|
-
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) => {
|
|
8120
8215
|
const limit = limitOf(opts.limit);
|
|
8121
8216
|
const client = await cronClient(cmd);
|
|
8122
8217
|
try {
|
|
@@ -8146,10 +8241,10 @@ var runsCommand = new Command98("runs").aliases(["logs"]).description("show how
|
|
|
8146
8241
|
});
|
|
8147
8242
|
|
|
8148
8243
|
// src/commands/cron/trigger/index.ts
|
|
8149
|
-
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);
|
|
8150
8245
|
|
|
8151
8246
|
// src/commands/cron/index.ts
|
|
8152
|
-
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);
|
|
8153
8248
|
var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
|
|
8154
8249
|
for (const cmd of cronCommand.commands) {
|
|
8155
8250
|
if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
|
|
@@ -8157,13 +8252,13 @@ for (const cmd of cronCommand.commands) {
|
|
|
8157
8252
|
}
|
|
8158
8253
|
|
|
8159
8254
|
// src/commands/managed/kind.ts
|
|
8160
|
-
import { Command as
|
|
8255
|
+
import { Command as Command120 } from "commander";
|
|
8161
8256
|
|
|
8162
8257
|
// src/commands/managed/backup/index.ts
|
|
8163
|
-
import { Command as
|
|
8258
|
+
import { Command as Command108 } from "commander";
|
|
8164
8259
|
|
|
8165
8260
|
// src/commands/managed/backup/create.ts
|
|
8166
|
-
import { Command as
|
|
8261
|
+
import { Command as Command103 } from "commander";
|
|
8167
8262
|
|
|
8168
8263
|
// src/commands/managed/shared.ts
|
|
8169
8264
|
import "commander";
|
|
@@ -8261,7 +8356,7 @@ function parseStorage(text2, flag) {
|
|
|
8261
8356
|
}
|
|
8262
8357
|
|
|
8263
8358
|
// src/commands/managed/backup/create.ts
|
|
8264
|
-
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) => {
|
|
8265
8360
|
const client = await managedClient(cmd);
|
|
8266
8361
|
const ls = `kvbox ${spec.command} backup ls ${name}`;
|
|
8267
8362
|
try {
|
|
@@ -8288,7 +8383,7 @@ var createCommand10 = (spec) => new Command102("create").description("back up a
|
|
|
8288
8383
|
});
|
|
8289
8384
|
|
|
8290
8385
|
// src/commands/managed/backup/ls.ts
|
|
8291
|
-
import { Command as
|
|
8386
|
+
import { Command as Command104 } from "commander";
|
|
8292
8387
|
var lsCommand16 = (spec) => {
|
|
8293
8388
|
const removedOnes = async (err, name, client) => {
|
|
8294
8389
|
if (!(err instanceof CallError && err.status === 404)) throw err;
|
|
@@ -8297,7 +8392,7 @@ var lsCommand16 = (spec) => {
|
|
|
8297
8392
|
const own = name.includes("/") ? [] : gone.filter((b) => b.owner === me(client));
|
|
8298
8393
|
return own.length > 0 ? own : gone;
|
|
8299
8394
|
};
|
|
8300
|
-
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) => {
|
|
8301
8396
|
const client = await managedClient(cmd);
|
|
8302
8397
|
try {
|
|
8303
8398
|
const list = name === void 0 ? await client.listManagedBackups(spec.kind) : await client.managedBackups(spec.kind, name).catch((err) => removedOnes(err, name, client));
|
|
@@ -8340,8 +8435,8 @@ var lsCommand16 = (spec) => {
|
|
|
8340
8435
|
};
|
|
8341
8436
|
|
|
8342
8437
|
// src/commands/managed/backup/restore.ts
|
|
8343
|
-
import { Command as
|
|
8344
|
-
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) => {
|
|
8345
8440
|
const client = await managedClient(cmd);
|
|
8346
8441
|
try {
|
|
8347
8442
|
const backup = await client.managedBackup(spec.kind, name, id);
|
|
@@ -8363,8 +8458,8 @@ var restoreCommand4 = (spec) => new Command104("restore").description("put a bac
|
|
|
8363
8458
|
});
|
|
8364
8459
|
|
|
8365
8460
|
// src/commands/managed/backup/rm.ts
|
|
8366
|
-
import { Command as
|
|
8367
|
-
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) => {
|
|
8368
8463
|
const client = await managedClient(cmd);
|
|
8369
8464
|
try {
|
|
8370
8465
|
await removeListed(client, await client.listManagedBackups(spec.kind), (b) => b.name, name, id, `database ${name}`, opts.yes ?? false);
|
|
@@ -8374,8 +8469,8 @@ var rmCommand16 = (spec) => new Command105("rm").alias("remove").description("re
|
|
|
8374
8469
|
});
|
|
8375
8470
|
|
|
8376
8471
|
// src/commands/managed/backup/schedule.ts
|
|
8377
|
-
import { Command as
|
|
8378
|
-
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) => {
|
|
8379
8474
|
if (opts.off && (opts.on || opts.at !== void 0)) throw new KvboxError("--off takes neither --on nor --at");
|
|
8380
8475
|
const hour = opts.at === void 0 ? void 0 : parseHour(opts.at);
|
|
8381
8476
|
const client = await managedClient(cmd);
|
|
@@ -8405,18 +8500,18 @@ function parseHour(text2) {
|
|
|
8405
8500
|
|
|
8406
8501
|
// src/commands/managed/backup/index.ts
|
|
8407
8502
|
var backupCommand4 = (spec) => {
|
|
8408
|
-
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");
|
|
8409
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)"));
|
|
8410
8505
|
return command;
|
|
8411
8506
|
};
|
|
8412
8507
|
|
|
8413
8508
|
// src/commands/managed/create.ts
|
|
8414
|
-
import { Command as
|
|
8509
|
+
import { Command as Command109 } from "commander";
|
|
8415
8510
|
import { setTimeout as sleep5 } from "timers/promises";
|
|
8416
8511
|
var READY_WAIT_MS = 9e4;
|
|
8417
8512
|
var READY_STEP_MS = 2e3;
|
|
8418
8513
|
var createCommand11 = (spec) => {
|
|
8419
|
-
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");
|
|
8420
8515
|
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
8421
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) => {
|
|
8422
8517
|
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
@@ -8465,8 +8560,8 @@ var createCommand11 = (spec) => {
|
|
|
8465
8560
|
};
|
|
8466
8561
|
|
|
8467
8562
|
// src/commands/managed/grow.ts
|
|
8468
|
-
import { Command as
|
|
8469
|
-
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) => {
|
|
8470
8565
|
const storageGib = parseStorage(size, "size");
|
|
8471
8566
|
const client = await managedClient(cmd);
|
|
8472
8567
|
try {
|
|
@@ -8479,8 +8574,8 @@ var growCommand3 = (spec) => new Command109("grow").description("give a database
|
|
|
8479
8574
|
});
|
|
8480
8575
|
|
|
8481
8576
|
// src/commands/managed/info.ts
|
|
8482
|
-
import { Command as
|
|
8483
|
-
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) => {
|
|
8484
8579
|
const client = await managedClient(cmd);
|
|
8485
8580
|
try {
|
|
8486
8581
|
const m = await client.getManaged(spec.kind, name);
|
|
@@ -8492,8 +8587,8 @@ var infoCommand3 = (spec) => new Command110("info").alias("get").description("sh
|
|
|
8492
8587
|
});
|
|
8493
8588
|
|
|
8494
8589
|
// src/commands/managed/link.ts
|
|
8495
|
-
import { Command as
|
|
8496
|
-
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) => {
|
|
8497
8592
|
const client = await managedClient(cmd);
|
|
8498
8593
|
try {
|
|
8499
8594
|
const m = await spin(`linking ${box2} to ${name}\u2026`, client.linkManaged(spec.kind, name, box2));
|
|
@@ -8509,7 +8604,7 @@ var linkCommand2 = (spec) => new Command111("link").description("let a box reach
|
|
|
8509
8604
|
});
|
|
8510
8605
|
|
|
8511
8606
|
// src/commands/managed/ls.ts
|
|
8512
|
-
import { Command as
|
|
8607
|
+
import { Command as Command113 } from "commander";
|
|
8513
8608
|
function listRows(items, user, kindColumn) {
|
|
8514
8609
|
return items.map((m) => ({
|
|
8515
8610
|
owner: m.owner === user ? "private" : m.owner,
|
|
@@ -8523,7 +8618,7 @@ function listRows(items, user, kindColumn) {
|
|
|
8523
8618
|
created: age(m.createdAt)
|
|
8524
8619
|
}));
|
|
8525
8620
|
}
|
|
8526
|
-
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) => {
|
|
8527
8622
|
const client = await managedClient(cmd);
|
|
8528
8623
|
try {
|
|
8529
8624
|
const items = await client.listManaged(spec?.kind, { all: opts.all });
|
|
@@ -8543,8 +8638,8 @@ var lsCommand17 = (spec) => new Command112("ls").alias("list").description(spec
|
|
|
8543
8638
|
});
|
|
8544
8639
|
|
|
8545
8640
|
// src/commands/managed/password.ts
|
|
8546
|
-
import { Command as
|
|
8547
|
-
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) => {
|
|
8548
8643
|
const client = await managedClient(cmd);
|
|
8549
8644
|
try {
|
|
8550
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);
|
|
@@ -8560,8 +8655,8 @@ var passwordCommand = (spec) => new Command113("password").description("show a d
|
|
|
8560
8655
|
});
|
|
8561
8656
|
|
|
8562
8657
|
// src/commands/managed/public.ts
|
|
8563
|
-
import { Command as
|
|
8564
|
-
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) => {
|
|
8565
8660
|
if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
|
|
8566
8661
|
const client = await managedClient(cmd);
|
|
8567
8662
|
try {
|
|
@@ -8582,8 +8677,8 @@ var publicCommand = (spec) => new Command114("public").description("open a datab
|
|
|
8582
8677
|
});
|
|
8583
8678
|
|
|
8584
8679
|
// src/commands/managed/rm.ts
|
|
8585
|
-
import { Command as
|
|
8586
|
-
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) => {
|
|
8587
8682
|
const client = await managedClient(cmd);
|
|
8588
8683
|
try {
|
|
8589
8684
|
if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
|
|
@@ -8599,8 +8694,8 @@ var rmCommand17 = (spec) => new Command115("rm").alias("remove").description("de
|
|
|
8599
8694
|
});
|
|
8600
8695
|
|
|
8601
8696
|
// src/commands/managed/start.ts
|
|
8602
|
-
import { Command as
|
|
8603
|
-
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) => {
|
|
8604
8699
|
const client = await managedClient(cmd);
|
|
8605
8700
|
try {
|
|
8606
8701
|
const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
|
|
@@ -8612,8 +8707,8 @@ var startCommand2 = (spec) => new Command116("start").description("run a stopped
|
|
|
8612
8707
|
});
|
|
8613
8708
|
|
|
8614
8709
|
// src/commands/managed/stop.ts
|
|
8615
|
-
import { Command as
|
|
8616
|
-
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) => {
|
|
8617
8712
|
const client = await managedClient(cmd);
|
|
8618
8713
|
try {
|
|
8619
8714
|
const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
|
|
@@ -8625,8 +8720,8 @@ var stopCommand2 = (spec) => new Command117("stop").description("shut a database
|
|
|
8625
8720
|
});
|
|
8626
8721
|
|
|
8627
8722
|
// src/commands/managed/unlink.ts
|
|
8628
|
-
import { Command as
|
|
8629
|
-
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) => {
|
|
8630
8725
|
const client = await managedClient(cmd);
|
|
8631
8726
|
try {
|
|
8632
8727
|
const m = await spin(`unlinking ${box2} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box2));
|
|
@@ -8639,8 +8734,8 @@ var unlinkCommand2 = (spec) => new Command118("unlink").description("stop a box
|
|
|
8639
8734
|
|
|
8640
8735
|
// src/commands/managed/kind.ts
|
|
8641
8736
|
function kindCommand(spec, description) {
|
|
8642
|
-
const command = new
|
|
8643
|
-
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]) {
|
|
8644
8739
|
command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
8645
8740
|
}
|
|
8646
8741
|
command.addCommand(backupCommand4(spec));
|
|
@@ -8654,14 +8749,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
|
|
|
8654
8749
|
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
8655
8750
|
|
|
8656
8751
|
// src/commands/managed/index.ts
|
|
8657
|
-
import { Command as
|
|
8658
|
-
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)"));
|
|
8659
8754
|
|
|
8660
8755
|
// src/commands/env/index.ts
|
|
8661
|
-
import { Command as
|
|
8756
|
+
import { Command as Command125 } from "commander";
|
|
8662
8757
|
|
|
8663
8758
|
// src/commands/env/ls.ts
|
|
8664
|
-
import { Command as
|
|
8759
|
+
import { Command as Command122 } from "commander";
|
|
8665
8760
|
|
|
8666
8761
|
// src/commands/env/shared.ts
|
|
8667
8762
|
function requireCloud4(client) {
|
|
@@ -8688,7 +8783,7 @@ function firstBootHint(box2, name) {
|
|
|
8688
8783
|
}
|
|
8689
8784
|
|
|
8690
8785
|
// src/commands/env/ls.ts
|
|
8691
|
-
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) => {
|
|
8692
8787
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8693
8788
|
try {
|
|
8694
8789
|
if (opts.box !== void 0) {
|
|
@@ -8727,8 +8822,8 @@ var lsCommand18 = new Command121("ls").alias("list").description("list the varia
|
|
|
8727
8822
|
});
|
|
8728
8823
|
|
|
8729
8824
|
// src/commands/env/rm.ts
|
|
8730
|
-
import { Command as
|
|
8731
|
-
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) => {
|
|
8732
8827
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8733
8828
|
try {
|
|
8734
8829
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -8765,8 +8860,8 @@ var rmCommand18 = new Command122("rm").alias("remove").description("remove varia
|
|
|
8765
8860
|
});
|
|
8766
8861
|
|
|
8767
8862
|
// src/commands/env/set.ts
|
|
8768
|
-
import { Command as
|
|
8769
|
-
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) => {
|
|
8770
8865
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
8771
8866
|
try {
|
|
8772
8867
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -8803,14 +8898,14 @@ var setCommand2 = new Command123("set").description("add or change a variable; b
|
|
|
8803
8898
|
});
|
|
8804
8899
|
|
|
8805
8900
|
// src/commands/env/index.ts
|
|
8806
|
-
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);
|
|
8807
8902
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
8808
8903
|
|
|
8809
8904
|
// src/commands/domain/index.ts
|
|
8810
|
-
import { Command as
|
|
8905
|
+
import { Command as Command129 } from "commander";
|
|
8811
8906
|
|
|
8812
8907
|
// src/commands/domain/add.ts
|
|
8813
|
-
import { Command as
|
|
8908
|
+
import { Command as Command126 } from "commander";
|
|
8814
8909
|
|
|
8815
8910
|
// src/commands/domain/shared.ts
|
|
8816
8911
|
function requireCloud5(client) {
|
|
@@ -8830,7 +8925,7 @@ function hostIn(name, zone) {
|
|
|
8830
8925
|
}
|
|
8831
8926
|
|
|
8832
8927
|
// src/commands/domain/add.ts
|
|
8833
|
-
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) => {
|
|
8834
8929
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
8835
8930
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
8836
8931
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -8866,8 +8961,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
8866
8961
|
});
|
|
8867
8962
|
|
|
8868
8963
|
// src/commands/domain/ls.ts
|
|
8869
|
-
import { Command as
|
|
8870
|
-
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) => {
|
|
8871
8966
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8872
8967
|
try {
|
|
8873
8968
|
requireCloud5(client);
|
|
@@ -8896,8 +8991,8 @@ var lsCommand19 = new Command126("ls").alias("list").description("list your cust
|
|
|
8896
8991
|
});
|
|
8897
8992
|
|
|
8898
8993
|
// src/commands/domain/rm.ts
|
|
8899
|
-
import { Command as
|
|
8900
|
-
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) => {
|
|
8901
8996
|
const domain = domainArg.trim().toLowerCase();
|
|
8902
8997
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8903
8998
|
try {
|
|
@@ -8918,7 +9013,7 @@ var rmCommand19 = new Command127("rm").alias("remove").description("stop serving
|
|
|
8918
9013
|
});
|
|
8919
9014
|
|
|
8920
9015
|
// src/commands/domain/index.ts
|
|
8921
|
-
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);
|
|
8922
9017
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
8923
9018
|
|
|
8924
9019
|
// src/commands/update.ts
|
|
@@ -8926,7 +9021,7 @@ import { spawn as spawn8 } from "child_process";
|
|
|
8926
9021
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
8927
9022
|
import { tmpdir } from "os";
|
|
8928
9023
|
import { join as join9 } from "path";
|
|
8929
|
-
import { Command as
|
|
9024
|
+
import { Command as Command130 } from "commander";
|
|
8930
9025
|
|
|
8931
9026
|
// src/update.ts
|
|
8932
9027
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -9045,7 +9140,7 @@ function run2(cmd, args) {
|
|
|
9045
9140
|
child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
|
|
9046
9141
|
});
|
|
9047
9142
|
}
|
|
9048
|
-
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 () => {
|
|
9049
9144
|
suppressUpdateNotice();
|
|
9050
9145
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
9051
9146
|
let code;
|
|
@@ -9173,7 +9268,7 @@ function installRootHelp(program) {
|
|
|
9173
9268
|
|
|
9174
9269
|
// src/program.ts
|
|
9175
9270
|
function buildProgram() {
|
|
9176
|
-
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();
|
|
9177
9272
|
program.addCommand(vmCommand);
|
|
9178
9273
|
program.addCommand(snapshotsCommand);
|
|
9179
9274
|
program.addCommand(volumeCommand);
|