@kvbox/cli 0.5.49 → 0.5.51
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 +505 -113
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -149,7 +149,7 @@ async function spin(message, work, opts = {}) {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// src/program.ts
|
|
152
|
-
import { Command as
|
|
152
|
+
import { Command as Command95 } from "commander";
|
|
153
153
|
|
|
154
154
|
// ../shared/src/version.ts
|
|
155
155
|
import { createRequire } from "module";
|
|
@@ -164,7 +164,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// src/version.ts
|
|
167
|
-
var VERSION = versionOf(import.meta.url, true ? "0.5.
|
|
167
|
+
var VERSION = versionOf(import.meta.url, true ? "0.5.51" : void 0);
|
|
168
168
|
|
|
169
169
|
// src/commands/vm/index.ts
|
|
170
170
|
import { Command as Command37 } from "commander";
|
|
@@ -220,6 +220,15 @@ function paths(home = kvboxHome()) {
|
|
|
220
220
|
firecracker: join(home, "bin", "firecracker"),
|
|
221
221
|
/** Firecracker's snapshot-editor, from the same release: merges a diff snapshot onto a full memory image. */
|
|
222
222
|
snapshotEditor: join(home, "bin", "snapshot-editor"),
|
|
223
|
+
/** Garage, on a host that is a backup store (`kvbox-server backup setup` downloads it). */
|
|
224
|
+
garage: join(home, "bin", "garage"),
|
|
225
|
+
/** The store's Garage as this host runs it: its configuration, pid and log. The data is on the disk the operator named. */
|
|
226
|
+
backupStore: {
|
|
227
|
+
dir: join(home, "backup-store"),
|
|
228
|
+
conf: join(home, "backup-store", "garage.toml"),
|
|
229
|
+
pid: join(home, "backup-store", "garage.pid"),
|
|
230
|
+
log: join(home, "backup-store", "garage.log")
|
|
231
|
+
},
|
|
223
232
|
assets: join(home, "assets"),
|
|
224
233
|
kernel: join(home, "assets", "vmlinux"),
|
|
225
234
|
/** Symlink to the current base image, assets/rootfs-<version>.ext4; boxes keep using the version they were made from. */
|
|
@@ -426,7 +435,7 @@ import { openSync } from "fs";
|
|
|
426
435
|
import { mkdir as mkdir2, readFile as readFile3, stat } from "fs/promises";
|
|
427
436
|
import { setTimeout as sleep } from "timers/promises";
|
|
428
437
|
import { Agent, request } from "undici";
|
|
429
|
-
import { z as
|
|
438
|
+
import { z as z6 } from "zod";
|
|
430
439
|
|
|
431
440
|
// ../shared/src/api.ts
|
|
432
441
|
import { z as z2 } from "zod";
|
|
@@ -547,7 +556,7 @@ var HostBackupManifestSchema = z2.object({
|
|
|
547
556
|
vcpu: z2.number().int(),
|
|
548
557
|
memMib: z2.number().int()
|
|
549
558
|
});
|
|
550
|
-
var HostUploadRequest = z2.object({ key: z2.string(), urls: z2.record(z2.string(), z2.string()) });
|
|
559
|
+
var HostUploadRequest = z2.object({ key: z2.string(), urls: z2.record(z2.string(), z2.string()), pin: z2.string().optional() });
|
|
551
560
|
var HostUploadResultSchema = z2.object({ chunks: z2.number().int(), bytes: z2.number().int(), sizes: z2.record(z2.string(), z2.number().int()) });
|
|
552
561
|
var HostRestoreRequest = z2.object({
|
|
553
562
|
/** The backup's id: its variables were sealed under it. */
|
|
@@ -557,7 +566,43 @@ var HostRestoreRequest = z2.object({
|
|
|
557
566
|
base: z2.string(),
|
|
558
567
|
image: z2.string().optional(),
|
|
559
568
|
env: z2.string().nullable(),
|
|
560
|
-
chunks: z2.array(z2.object({ index: z2.number().int().nonnegative(), hash: z2.string(), url: z2.string() }))
|
|
569
|
+
chunks: z2.array(z2.object({ index: z2.number().int().nonnegative(), hash: z2.string(), url: z2.string() })),
|
|
570
|
+
/** The certificate fingerprint of the store the URLs point at (see HostUploadRequest). */
|
|
571
|
+
pin: z2.string().optional()
|
|
572
|
+
});
|
|
573
|
+
var BackupStoreSetupRequest = z2.object({ path: z2.string().min(1), force: z2.boolean().optional(), newStore: z2.boolean().optional() });
|
|
574
|
+
var BackupStoreStatusSchema = z2.object({
|
|
575
|
+
path: z2.string(),
|
|
576
|
+
bucket: z2.string(),
|
|
577
|
+
accessKey: z2.string(),
|
|
578
|
+
/** Whether Garage is running and can store. */
|
|
579
|
+
running: z2.boolean(),
|
|
580
|
+
/** The filesystem the path is on. */
|
|
581
|
+
totalBytes: z2.number().int(),
|
|
582
|
+
freeBytes: z2.number().int(),
|
|
583
|
+
/** What the bucket holds, when Garage answers. */
|
|
584
|
+
objects: z2.number().int().optional(),
|
|
585
|
+
storedBytes: z2.number().int().optional(),
|
|
586
|
+
/** Whether the control plane took the store's registration at setup. */
|
|
587
|
+
registered: z2.boolean().optional()
|
|
588
|
+
});
|
|
589
|
+
var BackupStoreRegistration = z2.object({ bucket: z2.string().min(1), region: z2.string().min(1), accessKey: z2.string().min(1), secretKey: z2.string().min(1) });
|
|
590
|
+
var CloudBackupStoreSchema = z2.object({
|
|
591
|
+
id: z2.string(),
|
|
592
|
+
/** Null while no host serves it (its host left; it comes back when a host registers its key and secret again). */
|
|
593
|
+
host: z2.string().nullable(),
|
|
594
|
+
endpoint: z2.string().nullable(),
|
|
595
|
+
bucket: z2.string(),
|
|
596
|
+
accessKey: z2.string(),
|
|
597
|
+
createdAt: z2.string(),
|
|
598
|
+
/** The host answered a poll in the last minute and its Garage runs. */
|
|
599
|
+
live: z2.boolean(),
|
|
600
|
+
/** From the host's last poll; null when it never reported a store. */
|
|
601
|
+
totalBytes: z2.number().int().nullable(),
|
|
602
|
+
freeBytes: z2.number().int().nullable(),
|
|
603
|
+
/** Ready backups kept here, and what their chunks take (encrypted, compressed). */
|
|
604
|
+
backups: z2.number().int(),
|
|
605
|
+
storedBytes: z2.number().int()
|
|
561
606
|
});
|
|
562
607
|
var MachineSchema = z2.object({
|
|
563
608
|
/** Host-unique short id (the tap is `kv-<id>`). Missing only on a box made before ids that has not restarted since. */
|
|
@@ -799,7 +844,11 @@ var CapacitySchema = z2.object({
|
|
|
799
844
|
*/
|
|
800
845
|
images: z2.array(z2.object({ name: z2.string(), version: z2.string() })).optional(),
|
|
801
846
|
/** kvbox-server's version, so the control plane's host list shows it without a call per host. Older servers omit it. */
|
|
802
|
-
version: z2.string().optional()
|
|
847
|
+
version: z2.string().optional(),
|
|
848
|
+
/** Present on a host set up as a backup store: the disk its Garage keeps chunks on, and whether Garage runs. */
|
|
849
|
+
backupStore: z2.object({ totalBytes: z2.number().int(), freeBytes: z2.number().int(), running: z2.boolean() }).optional(),
|
|
850
|
+
/** 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. */
|
|
851
|
+
storeClient: z2.boolean().optional()
|
|
803
852
|
});
|
|
804
853
|
var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
|
|
805
854
|
var ImageIndexSchema = z2.object({
|
|
@@ -938,13 +987,21 @@ var UsageDaySchema = z2.object({
|
|
|
938
987
|
cost: z2.number(),
|
|
939
988
|
currency: z2.string(),
|
|
940
989
|
boxes: z2.array(UsageDayItemSchema),
|
|
941
|
-
volumes: z2.array(UsageDayItemSchema)
|
|
990
|
+
volumes: z2.array(UsageDayItemSchema),
|
|
991
|
+
/** Object storage that existed that day (#182); absent on a day without any. */
|
|
992
|
+
storage: z2.array(UsageDayItemSchema).optional()
|
|
942
993
|
});
|
|
943
994
|
var UsageReportSchema = z2.object({
|
|
944
995
|
window: z2.object({ from: z2.string(), to: z2.string() }),
|
|
945
996
|
boxes: z2.array(BoxUsageSchema),
|
|
946
997
|
/** Absent from a side older than #91. */
|
|
947
998
|
volumes: z2.array(VolumeUsageSchema).optional(),
|
|
999
|
+
/**
|
|
1000
|
+
* Object storage (#182, control plane only): one row per storage a slug has or had, shaped like a
|
|
1001
|
+
* volume's. `volumeHours` are the hours it existed, `volumeGibHours` those of the GiB beyond the
|
|
1002
|
+
* included ones, `sizeGib` its whole size. Absent when there is none.
|
|
1003
|
+
*/
|
|
1004
|
+
storage: z2.array(VolumeUsageSchema).optional(),
|
|
948
1005
|
/** With `?by=day` only, oldest day first. */
|
|
949
1006
|
days: z2.array(UsageDaySchema).optional(),
|
|
950
1007
|
totals: z2.object({
|
|
@@ -954,7 +1011,7 @@ var UsageReportSchema = z2.object({
|
|
|
954
1011
|
diskGibHours: z2.number(),
|
|
955
1012
|
volumeHours: z2.number().optional(),
|
|
956
1013
|
volumeGibHours: z2.number().optional(),
|
|
957
|
-
/** Boxes and
|
|
1014
|
+
/** Boxes, volumes and object storage together. */
|
|
958
1015
|
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional()
|
|
959
1016
|
})
|
|
960
1017
|
});
|
|
@@ -1207,6 +1264,8 @@ var CloudHostSchema = z2.object({
|
|
|
1207
1264
|
capacity: CapacitySchema.nullable(),
|
|
1208
1265
|
/** ISO 3166-1 alpha-2 code (`RO`), null when nobody said where the host is. */
|
|
1209
1266
|
country: z2.string().nullable(),
|
|
1267
|
+
/** The S3 region a storage made on this host answers to (`ro-west-1`); null: it takes no storage. */
|
|
1268
|
+
region: z2.string().nullable(),
|
|
1210
1269
|
/** kvbox-server's version as of the poller's last look (`capacity.version`); null before one, or for a server older than 0.5.45. */
|
|
1211
1270
|
version: z2.string().nullable()
|
|
1212
1271
|
});
|
|
@@ -1215,7 +1274,7 @@ var HostInfoSchema = z2.object({
|
|
|
1215
1274
|
health: HealthSchema.nullable(),
|
|
1216
1275
|
error: z2.string().nullable()
|
|
1217
1276
|
});
|
|
1218
|
-
var HostPatchRequest = z2.object({ country: z2.string().nullable() });
|
|
1277
|
+
var HostPatchRequest = z2.object({ country: z2.string().nullable().optional(), region: z2.string().nullable().optional() }).refine((b) => b.country !== void 0 || b.region !== void 0, { message: "give country, region or both" });
|
|
1219
1278
|
var CountrySchema = z2.object({ code: z2.string(), name: z2.string() });
|
|
1220
1279
|
|
|
1221
1280
|
// ../shared/src/managed.ts
|
|
@@ -1230,7 +1289,15 @@ var PricingSchema = z3.object({
|
|
|
1230
1289
|
diskGibHour: z3.number().nonnegative(),
|
|
1231
1290
|
volumeHour: z3.number().nonnegative().default(0),
|
|
1232
1291
|
volumeGibHour: z3.number().nonnegative().default(0),
|
|
1233
|
-
diskIncludedGib: z3.number().int().nonnegative().default(0)
|
|
1292
|
+
diskIncludedGib: z3.number().int().nonnegative().default(0),
|
|
1293
|
+
/**
|
|
1294
|
+
* Object storage (#182): an hour of a slug's storage existing, whatever it holds, which covers its
|
|
1295
|
+
* hidden box and the first `storageIncludedGib` of its size; each GiB above that is `storageGibHour`.
|
|
1296
|
+
* A price list from before object storage charges nothing for it.
|
|
1297
|
+
*/
|
|
1298
|
+
storageHour: z3.number().nonnegative().default(0),
|
|
1299
|
+
storageGibHour: z3.number().nonnegative().default(0),
|
|
1300
|
+
storageIncludedGib: z3.number().int().nonnegative().default(0)
|
|
1234
1301
|
});
|
|
1235
1302
|
var PriceListSchema = PricingSchema.extend({ welcomeCredit: z3.number().nonnegative() });
|
|
1236
1303
|
var HOUR_MS = 36e5;
|
|
@@ -1346,6 +1413,62 @@ var SetPublicRequest = z4.object({ on: z4.boolean() });
|
|
|
1346
1413
|
var ManagedLinkRequest = z4.object({ box: z4.string() });
|
|
1347
1414
|
var GrowManagedRequest = z4.object({ storageGib: z4.number().int() });
|
|
1348
1415
|
|
|
1416
|
+
// ../shared/src/storage.ts
|
|
1417
|
+
import { z as z5 } from "zod";
|
|
1418
|
+
var RegionSchema = z5.object({ name: z5.string(), country: z5.string().nullable() });
|
|
1419
|
+
var ObjectStorageSchema = z5.object({
|
|
1420
|
+
owner: z5.string(),
|
|
1421
|
+
ownerKind: z5.enum(["user", "org"]),
|
|
1422
|
+
/** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
|
|
1423
|
+
endpoint: z5.string().nullable(),
|
|
1424
|
+
/** The S3 region every client of it signs with (`ro-west-1`): its host's when it was made. */
|
|
1425
|
+
region: z5.string(),
|
|
1426
|
+
/** The most it may hold. */
|
|
1427
|
+
sizeGib: z5.number().int(),
|
|
1428
|
+
/** `running` when it answers; `unknown` while its host is not heard from. */
|
|
1429
|
+
status: BoxStatusSchema,
|
|
1430
|
+
/** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
|
|
1431
|
+
usedBytes: z5.number().optional(),
|
|
1432
|
+
totalBytes: z5.number().optional(),
|
|
1433
|
+
host: z5.string(),
|
|
1434
|
+
country: z5.string().optional(),
|
|
1435
|
+
buckets: z5.number().int(),
|
|
1436
|
+
price: z5.object({ perMonth: z5.number(), currency: z5.string() }),
|
|
1437
|
+
createdAt: z5.string()
|
|
1438
|
+
});
|
|
1439
|
+
var BucketSchema = z5.object({
|
|
1440
|
+
name: z5.string(),
|
|
1441
|
+
owner: z5.string(),
|
|
1442
|
+
ownerKind: z5.enum(["user", "org"]),
|
|
1443
|
+
endpoint: z5.string().nullable(),
|
|
1444
|
+
region: z5.string(),
|
|
1445
|
+
keys: z5.number().int(),
|
|
1446
|
+
objects: z5.number().optional(),
|
|
1447
|
+
bytes: z5.number().optional(),
|
|
1448
|
+
createdBy: z5.string().nullable(),
|
|
1449
|
+
createdAt: z5.string()
|
|
1450
|
+
});
|
|
1451
|
+
var CreateBucketRequest = z5.object({
|
|
1452
|
+
name: z5.string(),
|
|
1453
|
+
sizeGib: z5.number().int().optional(),
|
|
1454
|
+
near: z5.string().optional(),
|
|
1455
|
+
region: z5.string().optional()
|
|
1456
|
+
});
|
|
1457
|
+
var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z5.boolean() });
|
|
1458
|
+
var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
|
|
1459
|
+
var BucketKeySchema = z5.object({
|
|
1460
|
+
id: z5.string(),
|
|
1461
|
+
name: z5.string(),
|
|
1462
|
+
bucket: z5.string(),
|
|
1463
|
+
owner: z5.string(),
|
|
1464
|
+
readOnly: z5.boolean(),
|
|
1465
|
+
createdBy: z5.string().nullable(),
|
|
1466
|
+
createdAt: z5.string()
|
|
1467
|
+
});
|
|
1468
|
+
var CreateBucketKeyRequest = z5.object({ name: z5.string().optional(), readOnly: z5.boolean().optional() });
|
|
1469
|
+
var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z5.string(), endpoint: z5.string().nullable(), region: z5.string() });
|
|
1470
|
+
var GrowStorageRequest = z5.object({ sizeGib: z5.number().int() });
|
|
1471
|
+
|
|
1349
1472
|
// src/kvm.ts
|
|
1350
1473
|
import { accessSync, constants, readFileSync, statSync } from "fs";
|
|
1351
1474
|
import { userInfo } from "os";
|
|
@@ -1500,7 +1623,7 @@ var ServerClient = class {
|
|
|
1500
1623
|
* `all`: every box on the platform (platform admins only, #78).
|
|
1501
1624
|
*/
|
|
1502
1625
|
listMachines(opts = {}) {
|
|
1503
|
-
return this.call("GET", `/machines${allQuery(opts)}`,
|
|
1626
|
+
return this.call("GET", `/machines${allQuery(opts)}`, z6.array(MachineSchema), void 0, opts.org);
|
|
1504
1627
|
}
|
|
1505
1628
|
createMachine(req) {
|
|
1506
1629
|
return this.call("POST", "/machines", MachineSchema, req);
|
|
@@ -1554,10 +1677,10 @@ var ServerClient = class {
|
|
|
1554
1677
|
}
|
|
1555
1678
|
/** Backups, the control plane's only: a box's disk in object storage. Newest first. */
|
|
1556
1679
|
listBackups() {
|
|
1557
|
-
return this.call("GET", "/backups",
|
|
1680
|
+
return this.call("GET", "/backups", z6.array(BackupSchema));
|
|
1558
1681
|
}
|
|
1559
1682
|
boxBackups(name) {
|
|
1560
|
-
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`,
|
|
1683
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z6.array(BackupSchema));
|
|
1561
1684
|
}
|
|
1562
1685
|
boxBackup(name, id) {
|
|
1563
1686
|
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
|
|
@@ -1572,7 +1695,7 @@ var ServerClient = class {
|
|
|
1572
1695
|
}
|
|
1573
1696
|
/** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
|
|
1574
1697
|
boxHooks(name) {
|
|
1575
|
-
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`,
|
|
1698
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z6.array(WakeHookSchema));
|
|
1576
1699
|
}
|
|
1577
1700
|
createBoxHook(name) {
|
|
1578
1701
|
return this.call("POST", `/machines/${encodeURIComponent(name)}/hooks`, CreatedWakeHookSchema);
|
|
@@ -1600,7 +1723,7 @@ var ServerClient = class {
|
|
|
1600
1723
|
}
|
|
1601
1724
|
/** Every readable box's subdomains, one entry each. */
|
|
1602
1725
|
listSubdomains() {
|
|
1603
|
-
return this.call("GET", "/subdomains",
|
|
1726
|
+
return this.call("GET", "/subdomains", z6.array(SubdomainSchema));
|
|
1604
1727
|
}
|
|
1605
1728
|
/** Custom domains (#89), the control plane's only: serve the box at the user's own name. */
|
|
1606
1729
|
addDomain(name, req) {
|
|
@@ -1611,7 +1734,7 @@ var ServerClient = class {
|
|
|
1611
1734
|
}
|
|
1612
1735
|
/** Every readable box's custom domains. */
|
|
1613
1736
|
listDomains() {
|
|
1614
|
-
return this.call("GET", "/domains",
|
|
1737
|
+
return this.call("GET", "/domains", z6.array(DomainSchema));
|
|
1615
1738
|
}
|
|
1616
1739
|
/** A running box's own load, memory and disk, asked of its guest (#67). */
|
|
1617
1740
|
machineStats(name) {
|
|
@@ -1640,22 +1763,22 @@ var ServerClient = class {
|
|
|
1640
1763
|
return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
|
|
1641
1764
|
}
|
|
1642
1765
|
deleteMachine(name) {
|
|
1643
|
-
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`,
|
|
1766
|
+
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z6.undefined());
|
|
1644
1767
|
}
|
|
1645
1768
|
/** Like `listMachines`, for snapshots. */
|
|
1646
1769
|
listSnapshots(opts = {}) {
|
|
1647
|
-
return this.call("GET", `/snapshots${allQuery(opts)}`,
|
|
1770
|
+
return this.call("GET", `/snapshots${allQuery(opts)}`, z6.array(SnapshotSchema), void 0, opts.org);
|
|
1648
1771
|
}
|
|
1649
1772
|
createSnapshot(req) {
|
|
1650
1773
|
return this.call("POST", "/snapshots", SnapshotSchema, req);
|
|
1651
1774
|
}
|
|
1652
1775
|
deleteSnapshot(name) {
|
|
1653
|
-
return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`,
|
|
1776
|
+
return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z6.undefined());
|
|
1654
1777
|
}
|
|
1655
1778
|
// ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
|
|
1656
1779
|
/** `org`: that org's list instead of `--org`'s (or the caller's own). */
|
|
1657
1780
|
listEnv(org) {
|
|
1658
|
-
return this.call("GET", "/vars",
|
|
1781
|
+
return this.call("GET", "/vars", z6.array(EnvVarSchema), void 0, org);
|
|
1659
1782
|
}
|
|
1660
1783
|
setEnv(name, req) {
|
|
1661
1784
|
return this.call("PUT", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema, req);
|
|
@@ -1675,13 +1798,13 @@ var ServerClient = class {
|
|
|
1675
1798
|
}
|
|
1676
1799
|
// ---- volumes (#52) ----
|
|
1677
1800
|
listVolumes(opts = {}) {
|
|
1678
|
-
return this.call("GET", `/volumes${allQuery(opts)}`,
|
|
1801
|
+
return this.call("GET", `/volumes${allQuery(opts)}`, z6.array(VolumeSchema), void 0, opts.org);
|
|
1679
1802
|
}
|
|
1680
1803
|
createVolume(req) {
|
|
1681
1804
|
return this.call("POST", "/volumes", VolumeSchema, req);
|
|
1682
1805
|
}
|
|
1683
1806
|
deleteVolume(name) {
|
|
1684
|
-
return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`,
|
|
1807
|
+
return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z6.undefined());
|
|
1685
1808
|
}
|
|
1686
1809
|
/** Both answer with the box as it is afterwards (restarted when it was running). */
|
|
1687
1810
|
attachVolume(name, req) {
|
|
@@ -1694,16 +1817,45 @@ var ServerClient = class {
|
|
|
1694
1817
|
resizeVolume(name, sizeGib) {
|
|
1695
1818
|
return this.call("POST", `/volumes/${encodeURIComponent(name)}/resize`, VolumeSchema, { sizeGib });
|
|
1696
1819
|
}
|
|
1820
|
+
// ---- object storage (#182): the control plane's alone ----
|
|
1821
|
+
listBuckets(opts = {}) {
|
|
1822
|
+
return this.call("GET", `/buckets${allQuery(opts)}`, z6.array(BucketSchema), void 0, opts.org);
|
|
1823
|
+
}
|
|
1824
|
+
/** The first bucket of a slug also makes its storage: a box boots twice, so this may take a couple of minutes. */
|
|
1825
|
+
createBucket(req) {
|
|
1826
|
+
return this.call("POST", "/buckets", CreatedBucketSchema, req);
|
|
1827
|
+
}
|
|
1828
|
+
getBucket(name) {
|
|
1829
|
+
return this.call("GET", `/buckets/${encodeURIComponent(name)}`, BucketInfoSchema);
|
|
1830
|
+
}
|
|
1831
|
+
deleteBucket(name, force = false) {
|
|
1832
|
+
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z6.undefined());
|
|
1833
|
+
}
|
|
1834
|
+
listBucketKeys(name) {
|
|
1835
|
+
return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z6.array(BucketKeySchema));
|
|
1836
|
+
}
|
|
1837
|
+
createBucketKey(name, req) {
|
|
1838
|
+
return this.call("POST", `/buckets/${encodeURIComponent(name)}/keys`, CreatedBucketKeySchema, req);
|
|
1839
|
+
}
|
|
1840
|
+
deleteBucketKey(name, id) {
|
|
1841
|
+
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`, z6.undefined());
|
|
1842
|
+
}
|
|
1843
|
+
listStorage(opts = {}) {
|
|
1844
|
+
return this.call("GET", `/storage${allQuery(opts)}`, z6.array(ObjectStorageSchema), void 0, opts.org);
|
|
1845
|
+
}
|
|
1846
|
+
growStorage(sizeGib) {
|
|
1847
|
+
return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
|
|
1848
|
+
}
|
|
1697
1849
|
// ---- managed services (#173): the control plane's alone ----
|
|
1698
1850
|
managedPath(kind, name, rest = "") {
|
|
1699
1851
|
return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
|
|
1700
1852
|
}
|
|
1701
1853
|
managedCatalog() {
|
|
1702
|
-
return this.call("GET", "/managed/catalog",
|
|
1854
|
+
return this.call("GET", "/managed/catalog", z6.array(ManagedCatalogEntrySchema));
|
|
1703
1855
|
}
|
|
1704
1856
|
/** One kind's services, or every kind's when `kind` is left out. */
|
|
1705
1857
|
listManaged(kind, opts = {}) {
|
|
1706
|
-
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`,
|
|
1858
|
+
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z6.array(ManagedSchema), void 0, opts.org);
|
|
1707
1859
|
}
|
|
1708
1860
|
createManaged(kind, req) {
|
|
1709
1861
|
return this.call("POST", this.managedPath(kind), CreatedManagedSchema, req);
|
|
@@ -1713,7 +1865,7 @@ var ServerClient = class {
|
|
|
1713
1865
|
return this.call("GET", this.managedPath(kind, name), ManagedSchema);
|
|
1714
1866
|
}
|
|
1715
1867
|
deleteManaged(kind, name) {
|
|
1716
|
-
return this.call("DELETE", this.managedPath(kind, name),
|
|
1868
|
+
return this.call("DELETE", this.managedPath(kind, name), z6.undefined());
|
|
1717
1869
|
}
|
|
1718
1870
|
managedPassword(kind, name) {
|
|
1719
1871
|
return this.call("GET", this.managedPath(kind, name, "/password"), ManagedSecretSchema);
|
|
@@ -1744,14 +1896,14 @@ var ServerClient = class {
|
|
|
1744
1896
|
return this.call("POST", "/login", LoginResponseSchema, req);
|
|
1745
1897
|
}
|
|
1746
1898
|
logout() {
|
|
1747
|
-
return this.call("POST", "/logout",
|
|
1899
|
+
return this.call("POST", "/logout", z6.unknown()).then(() => void 0);
|
|
1748
1900
|
}
|
|
1749
1901
|
me() {
|
|
1750
1902
|
return this.call("GET", "/me", MeResponseSchema);
|
|
1751
1903
|
}
|
|
1752
1904
|
// ---- orgs (`kvbox org …`) ----
|
|
1753
1905
|
listOrgs() {
|
|
1754
|
-
return this.call("GET", "/orgs",
|
|
1906
|
+
return this.call("GET", "/orgs", z6.array(OrgMembershipSchema));
|
|
1755
1907
|
}
|
|
1756
1908
|
createOrg(req) {
|
|
1757
1909
|
return this.call("POST", "/orgs", CloudOrgSchema, req);
|
|
@@ -1760,16 +1912,16 @@ var ServerClient = class {
|
|
|
1760
1912
|
return this.call("GET", `/orgs/${encodeURIComponent(slug)}`, OrgDetailSchema);
|
|
1761
1913
|
}
|
|
1762
1914
|
deleteOrg(slug) {
|
|
1763
|
-
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`,
|
|
1915
|
+
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z6.undefined());
|
|
1764
1916
|
}
|
|
1765
1917
|
addMember(slug, req) {
|
|
1766
|
-
return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`,
|
|
1918
|
+
return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z6.undefined(), req);
|
|
1767
1919
|
}
|
|
1768
1920
|
setRole(slug, username, role) {
|
|
1769
|
-
return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`,
|
|
1921
|
+
return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z6.unknown(), { role }).then(() => void 0);
|
|
1770
1922
|
}
|
|
1771
1923
|
removeMember(slug, username) {
|
|
1772
|
-
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`,
|
|
1924
|
+
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z6.undefined());
|
|
1773
1925
|
}
|
|
1774
1926
|
/** Sign this machine's key again (#51); the key must be one the user logged in with. */
|
|
1775
1927
|
sshCert(req) {
|
|
@@ -3967,13 +4119,21 @@ var usageCommand2 = new Command51("usage").description("what your boxes and volu
|
|
|
3967
4119
|
const cloud = client.target.kind === "cloud" ? { me: client.target.user } : void 0;
|
|
3968
4120
|
info(`${day2(report.window.from)} to ${day2(report.window.to)}`);
|
|
3969
4121
|
const volumes = report.volumes ?? [];
|
|
3970
|
-
|
|
4122
|
+
const storage = report.storage ?? [];
|
|
4123
|
+
if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0) info("no usage in this window");
|
|
3971
4124
|
else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
|
|
3972
4125
|
if (volumes.length > 0) {
|
|
3973
4126
|
info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
|
|
3974
4127
|
table(volumeRows(report, cloud));
|
|
3975
4128
|
}
|
|
3976
|
-
if (
|
|
4129
|
+
if (storage.length > 0) {
|
|
4130
|
+
info("object storage");
|
|
4131
|
+
table(storageRows(report, cloud));
|
|
4132
|
+
}
|
|
4133
|
+
if ((volumes.length > 0 || storage.length > 0) && report.totals.cost !== void 0) {
|
|
4134
|
+
const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : []];
|
|
4135
|
+
info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
|
|
4136
|
+
}
|
|
3977
4137
|
if (cloud) {
|
|
3978
4138
|
const line = await creditLine(client, cloud.me);
|
|
3979
4139
|
if (line !== void 0) info(line);
|
|
@@ -4052,6 +4212,17 @@ function volumeRows(report, cloud) {
|
|
|
4052
4212
|
});
|
|
4053
4213
|
return rows2;
|
|
4054
4214
|
}
|
|
4215
|
+
function storageRows(report, cloud) {
|
|
4216
|
+
const priced = report.totals.cost !== void 0;
|
|
4217
|
+
const currency = report.totals.cost?.currency ?? "";
|
|
4218
|
+
return (report.storage ?? []).map((s) => ({
|
|
4219
|
+
...cloud ? { owner: ownerCell2(s, cloud.me) } : {},
|
|
4220
|
+
status: s.status === "removed" ? color.dim("removed") : "present",
|
|
4221
|
+
size: `${s.sizeGib}GB`,
|
|
4222
|
+
hours: hours(s.volumeHours),
|
|
4223
|
+
...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
|
|
4224
|
+
}));
|
|
4225
|
+
}
|
|
4055
4226
|
function byUser(report) {
|
|
4056
4227
|
const groups = /* @__PURE__ */ new Map();
|
|
4057
4228
|
for (const b of report.boxes) {
|
|
@@ -4068,7 +4239,7 @@ function byUser(report) {
|
|
|
4068
4239
|
return u;
|
|
4069
4240
|
});
|
|
4070
4241
|
users.sort((a, b) => a.user === null ? 1 : b.user === null ? -1 : a.user.localeCompare(b.user));
|
|
4071
|
-
return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, totals: report.totals };
|
|
4242
|
+
return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, totals: report.totals };
|
|
4072
4243
|
}
|
|
4073
4244
|
function userRows(r) {
|
|
4074
4245
|
const priced = r.totals.cost !== void 0;
|
|
@@ -4150,7 +4321,7 @@ import { Command as Command54, InvalidArgumentError as InvalidArgumentError2, Op
|
|
|
4150
4321
|
// src/commands/deploy/config.ts
|
|
4151
4322
|
import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
|
|
4152
4323
|
import { isAbsolute, join as join6, normalize, relative as relative2 } from "path";
|
|
4153
|
-
import { z as
|
|
4324
|
+
import { z as z7 } from "zod";
|
|
4154
4325
|
|
|
4155
4326
|
// src/commands/deploy/templates/docker.ts
|
|
4156
4327
|
import { readFile as readFile5 } from "fs/promises";
|
|
@@ -4574,21 +4745,21 @@ function detectTemplates(pkg, dir = NO_FACTS) {
|
|
|
4574
4745
|
var DEPLOY_AUTO_HIBERNATE_SEC = 3600;
|
|
4575
4746
|
var CONFIG_FILE = "kvbox.json";
|
|
4576
4747
|
var BOX_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
|
|
4577
|
-
var DeployConfigSchema =
|
|
4578
|
-
template:
|
|
4579
|
-
name:
|
|
4748
|
+
var DeployConfigSchema = z7.object({
|
|
4749
|
+
template: z7.enum(TEMPLATE_IDS),
|
|
4750
|
+
name: z7.string().regex(BOX_NAME_RE, "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit"),
|
|
4580
4751
|
/** The org whose box it is; absent for the user's own. */
|
|
4581
|
-
org:
|
|
4752
|
+
org: z7.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
|
|
4582
4753
|
/** The HTTPS name (`<subdomain>.kvbox.app`); absent when deploying to this machine's own host. */
|
|
4583
|
-
subdomain:
|
|
4754
|
+
subdomain: z7.string().check((ctx) => {
|
|
4584
4755
|
const problem = subdomainProblem(ctx.value);
|
|
4585
4756
|
if (problem) ctx.issues.push({ code: "custom", message: problem, input: ctx.value });
|
|
4586
4757
|
}).optional(),
|
|
4587
|
-
size:
|
|
4758
|
+
size: z7.enum(SIZE_NAMES).optional(),
|
|
4588
4759
|
/** The build output directory, relative to the app; the template's default when absent. */
|
|
4589
|
-
dist:
|
|
4760
|
+
dist: z7.string().optional(),
|
|
4590
4761
|
/** The port a Next.js app or Node server serves; the template's (3000) when absent. */
|
|
4591
|
-
port:
|
|
4762
|
+
port: z7.number().int().min(1).max(65535).optional()
|
|
4592
4763
|
});
|
|
4593
4764
|
var SERVICE_KEY_RE = /^[a-z][a-z0-9-]{0,19}$/;
|
|
4594
4765
|
var RESERVED_SERVICE_KEYS = ["app", "agent", "init", "volumes"];
|
|
@@ -4600,38 +4771,38 @@ var POSTGRES_PORT = 5432;
|
|
|
4600
4771
|
var POSTGRES_IMAGE = "postgres:17";
|
|
4601
4772
|
var POSTGRES_ENV = "DATABASE_URL";
|
|
4602
4773
|
var IMAGE_RE = /^[a-z0-9][a-z0-9._/:@-]*$/;
|
|
4603
|
-
var ServiceSchema =
|
|
4604
|
-
template:
|
|
4774
|
+
var ServiceSchema = z7.strictObject({
|
|
4775
|
+
template: z7.enum([...TEMPLATE_IDS, POSTGRES]),
|
|
4605
4776
|
/** The service's directory, relative to the one holding kvbox.json; every template but postgres has one. */
|
|
4606
|
-
dir:
|
|
4777
|
+
dir: z7.string().min(1).optional(),
|
|
4607
4778
|
/** A postgres service's image, `postgres:17` when absent (`pgvector/pgvector:pg17` for vectors). */
|
|
4608
|
-
image:
|
|
4779
|
+
image: z7.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
|
|
4609
4780
|
/** The volume (a key of `volumes`) a postgres service keeps its data on. */
|
|
4610
|
-
volume:
|
|
4781
|
+
volume: z7.string().optional(),
|
|
4611
4782
|
/** The box variable a postgres service's URL is written to, `DATABASE_URL` when absent. */
|
|
4612
|
-
env:
|
|
4783
|
+
env: z7.string().optional(),
|
|
4613
4784
|
/** A docker service's build context, relative to kvbox.json, when it is not `dir` (a monorepo built from its root); the Dockerfile stays in `dir`. */
|
|
4614
|
-
context:
|
|
4615
|
-
dist:
|
|
4785
|
+
context: z7.string().min(1).optional(),
|
|
4786
|
+
dist: z7.string().optional(),
|
|
4616
4787
|
/**
|
|
4617
4788
|
* A command run once per deploy in the service's new version (a docker service: in a container of
|
|
4618
4789
|
* the new image; node, nextjs: in the new source, installed and built), with the box's variables,
|
|
4619
4790
|
* before it replaces the running one. Migrations, mostly. A failing one stops that service's deploy.
|
|
4620
4791
|
*/
|
|
4621
|
-
release:
|
|
4792
|
+
release: z7.string().optional(),
|
|
4622
4793
|
/** The box port of a service with its own server; the template's (3000) when absent. */
|
|
4623
|
-
port:
|
|
4794
|
+
port: z7.number().int().min(1).max(65535).optional(),
|
|
4624
4795
|
/** The URL paths that go to this service, each with everything under it; the prefix is kept. */
|
|
4625
|
-
paths:
|
|
4796
|
+
paths: z7.array(z7.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
|
|
4626
4797
|
});
|
|
4627
|
-
var StackConfigSchema =
|
|
4798
|
+
var StackConfigSchema = z7.strictObject({
|
|
4628
4799
|
name: DeployConfigSchema.shape.name.optional(),
|
|
4629
4800
|
org: DeployConfigSchema.shape.org,
|
|
4630
4801
|
subdomain: DeployConfigSchema.shape.subdomain,
|
|
4631
4802
|
size: DeployConfigSchema.shape.size,
|
|
4632
4803
|
/** The stack's volumes, name to size ("10GB"): made for its box and attached to it on the first deploy that needs one. */
|
|
4633
|
-
volumes:
|
|
4634
|
-
services:
|
|
4804
|
+
volumes: z7.record(z7.string(), z7.string()).optional(),
|
|
4805
|
+
services: z7.record(z7.string(), ServiceSchema)
|
|
4635
4806
|
});
|
|
4636
4807
|
function volumeGib(text2) {
|
|
4637
4808
|
const mib = parseMib(text2);
|
|
@@ -5735,11 +5906,230 @@ var rmCommand7 = new Command60("rm").alias("remove").description("delete a volum
|
|
|
5735
5906
|
var volumeCommand = new Command61("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(createCommand3).addCommand(lsCommand8).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand7);
|
|
5736
5907
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
5737
5908
|
|
|
5909
|
+
// src/commands/bucket/index.ts
|
|
5910
|
+
import { Command as Command71 } from "commander";
|
|
5911
|
+
|
|
5912
|
+
// src/commands/bucket/create.ts
|
|
5913
|
+
import { Command as Command62 } from "commander";
|
|
5914
|
+
|
|
5915
|
+
// src/commands/bucket/shared.ts
|
|
5916
|
+
async function bucketClient(cmd) {
|
|
5917
|
+
const client = await clientFor(cmd.optsWithGlobals());
|
|
5918
|
+
if (client.target.kind !== "cloud") {
|
|
5919
|
+
await client.close();
|
|
5920
|
+
throw new KvboxError("object storage runs on the kvbox cloud: kvbox login first (this host's own socket has none)");
|
|
5921
|
+
}
|
|
5922
|
+
return client;
|
|
5923
|
+
}
|
|
5924
|
+
function shownName(b, client) {
|
|
5925
|
+
const context = client.target.kind === "cloud" ? client.target.org ?? client.target.user : void 0;
|
|
5926
|
+
return b.owner === context ? b.name : `${b.owner}/${b.name}`;
|
|
5927
|
+
}
|
|
5928
|
+
var fullness = (s) => s.usedBytes !== void 0 ? `${gb(s.usedBytes)} of ${s.sizeGib} GB used` : `${s.sizeGib} GB`;
|
|
5929
|
+
var nearlyFull = (s) => s.usedBytes !== void 0 && s.totalBytes !== void 0 && s.totalBytes > 0 && s.usedBytes / s.totalBytes >= 0.9;
|
|
5930
|
+
var priceText = (s) => `${money(s.price.perMonth, s.price.currency)} a month ${color.dim("(estimated)")}`;
|
|
5931
|
+
var endpointText = (endpoint) => endpoint ?? color.yellow("no address yet (asked for again at the next bucket create or info)");
|
|
5932
|
+
function printRows(rows2) {
|
|
5933
|
+
const width2 = Math.max(...rows2.map(([label]) => label.length));
|
|
5934
|
+
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
5935
|
+
`);
|
|
5936
|
+
}
|
|
5937
|
+
|
|
5938
|
+
// src/commands/bucket/create.ts
|
|
5939
|
+
var createCommand4 = new Command62("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) => {
|
|
5940
|
+
const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
|
|
5941
|
+
const client = await bucketClient(cmd);
|
|
5942
|
+
try {
|
|
5943
|
+
const made = await spin(`making bucket ${name}\u2026`, client.createBucket({ name, ...sizeGib !== void 0 ? { sizeGib } : {}, ...opts.region !== void 0 ? { region: opts.region } : {}, ...opts.near !== void 0 ? { near: opts.near } : {} }));
|
|
5944
|
+
if (opts.json) {
|
|
5945
|
+
json(made);
|
|
5946
|
+
return;
|
|
5947
|
+
}
|
|
5948
|
+
const shown = shownName(made, client);
|
|
5949
|
+
info(`${color.green("\u2713")} bucket ${color.bold(shown)} made`);
|
|
5950
|
+
if (made.storageCreated) info(` object storage made for ${made.owner} in ${made.storage.region}: ${made.storage.sizeGib} GB for all its buckets, ${priceText(made.storage)}`);
|
|
5951
|
+
info(` endpoint: ${endpointText(made.endpoint)} ${color.dim(`region ${made.region}, path-style`)}`);
|
|
5952
|
+
info(color.dim(` next: kvbox bucket key create ${shown} (an access key for your app)`));
|
|
5953
|
+
} finally {
|
|
5954
|
+
await client.close();
|
|
5955
|
+
}
|
|
5956
|
+
});
|
|
5957
|
+
|
|
5958
|
+
// src/commands/bucket/grow.ts
|
|
5959
|
+
import { Command as Command63 } from "commander";
|
|
5960
|
+
var growCommand2 = new Command63("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) => {
|
|
5961
|
+
const sizeGib = parseGib2(size, "size");
|
|
5962
|
+
const client = await bucketClient(cmd);
|
|
5963
|
+
try {
|
|
5964
|
+
const s = await spin(`growing your object storage to ${sizeGib} GB\u2026`, client.growStorage(sizeGib));
|
|
5965
|
+
if (opts.json) json(s);
|
|
5966
|
+
else info(`${color.green("\u2713")} the object storage of ${s.owner} is ${s.sizeGib} GB, ${priceText(s)}`);
|
|
5967
|
+
} finally {
|
|
5968
|
+
await client.close();
|
|
5969
|
+
}
|
|
5970
|
+
});
|
|
5971
|
+
|
|
5972
|
+
// src/commands/bucket/info.ts
|
|
5973
|
+
import { Command as Command64 } from "commander";
|
|
5974
|
+
var infoCommand = new Command64("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) => {
|
|
5975
|
+
const client = await bucketClient(cmd);
|
|
5976
|
+
try {
|
|
5977
|
+
const b = await client.getBucket(name);
|
|
5978
|
+
if (opts.json) {
|
|
5979
|
+
json(b);
|
|
5980
|
+
return;
|
|
5981
|
+
}
|
|
5982
|
+
const shown = shownName(b, client);
|
|
5983
|
+
const s = b.storage;
|
|
5984
|
+
const rows2 = [
|
|
5985
|
+
["name", color.bold(shown)],
|
|
5986
|
+
["endpoint", endpointText(b.endpoint)],
|
|
5987
|
+
["region", `${b.region} ${color.dim("(path-style addressing)")}`],
|
|
5988
|
+
["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)}`],
|
|
5989
|
+
["keys", b.keys === 0 ? color.dim(`none (kvbox bucket key create ${shown})`) : `${b.keys} ${color.dim(`(kvbox bucket key ls ${shown})`)}`],
|
|
5990
|
+
["storage", `${fullness(s)}, ${s.buckets} ${s.buckets === 1 ? "bucket" : "buckets"}${nearlyFull(s) ? color.yellow(" almost full: kvbox bucket grow <GB>") : ""}`],
|
|
5991
|
+
["cost", `${priceText(s)} for the whole storage`],
|
|
5992
|
+
["created", `${age(b.createdAt)}${b.createdBy ? ` by ${b.createdBy}` : ""}`]
|
|
5993
|
+
];
|
|
5994
|
+
printRows(rows2);
|
|
5995
|
+
if (b.endpoint !== null) info(color.dim(`
|
|
5996
|
+
with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
|
|
5997
|
+
} finally {
|
|
5998
|
+
await client.close();
|
|
5999
|
+
}
|
|
6000
|
+
});
|
|
6001
|
+
|
|
6002
|
+
// src/commands/bucket/key/index.ts
|
|
6003
|
+
import { Command as Command68 } from "commander";
|
|
6004
|
+
|
|
6005
|
+
// src/commands/bucket/key/create.ts
|
|
6006
|
+
import { Command as Command65 } from "commander";
|
|
6007
|
+
var createCommand5 = new Command65("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) => {
|
|
6008
|
+
const client = await bucketClient(cmd);
|
|
6009
|
+
try {
|
|
6010
|
+
const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
|
|
6011
|
+
if (opts.json) {
|
|
6012
|
+
json(key);
|
|
6013
|
+
return;
|
|
6014
|
+
}
|
|
6015
|
+
info(`${color.green("\u2713")} key ${color.bold(key.name)} ${key.readOnly ? "reads" : "reads and writes"} bucket ${color.bold(key.bucket)}`);
|
|
6016
|
+
printRows([
|
|
6017
|
+
["endpoint", endpointText(key.endpoint)],
|
|
6018
|
+
["region", key.region],
|
|
6019
|
+
["bucket", key.bucket],
|
|
6020
|
+
["access key", key.id],
|
|
6021
|
+
["secret key", key.secret]
|
|
6022
|
+
]);
|
|
6023
|
+
info(color.dim("\nThe secret key is shown only now. Clients must use path-style addressing (AWS SDKs: forcePathStyle)."));
|
|
6024
|
+
} finally {
|
|
6025
|
+
await client.close();
|
|
6026
|
+
}
|
|
6027
|
+
});
|
|
6028
|
+
|
|
6029
|
+
// src/commands/bucket/key/ls.ts
|
|
6030
|
+
import { Command as Command66 } from "commander";
|
|
6031
|
+
var lsCommand9 = new Command66("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) => {
|
|
6032
|
+
const client = await bucketClient(cmd);
|
|
6033
|
+
try {
|
|
6034
|
+
const keys = await client.listBucketKeys(bucket);
|
|
6035
|
+
if (opts.json) {
|
|
6036
|
+
json(keys);
|
|
6037
|
+
return;
|
|
6038
|
+
}
|
|
6039
|
+
if (keys.length === 0) {
|
|
6040
|
+
info(`bucket ${bucket} has no keys yet; make one with: kvbox bucket key create ${bucket}`);
|
|
6041
|
+
return;
|
|
6042
|
+
}
|
|
6043
|
+
table(keys.map((k) => ({ "access key": k.id, name: k.name, access: k.readOnly ? "read only" : "read and write", "made by": k.createdBy ?? "-", created: age(k.createdAt) })));
|
|
6044
|
+
} finally {
|
|
6045
|
+
await client.close();
|
|
6046
|
+
}
|
|
6047
|
+
});
|
|
6048
|
+
|
|
6049
|
+
// src/commands/bucket/key/rm.ts
|
|
6050
|
+
import { Command as Command67 } from "commander";
|
|
6051
|
+
var rmCommand8 = new Command67("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) => {
|
|
6052
|
+
const client = await bucketClient(cmd);
|
|
6053
|
+
try {
|
|
6054
|
+
if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
|
|
6055
|
+
info("cancelled");
|
|
6056
|
+
process.exitCode = 1;
|
|
6057
|
+
return;
|
|
6058
|
+
}
|
|
6059
|
+
await client.deleteBucketKey(bucket, id);
|
|
6060
|
+
info(`${color.green("\u2713")} key ${id} deleted`);
|
|
6061
|
+
} finally {
|
|
6062
|
+
await client.close();
|
|
6063
|
+
}
|
|
6064
|
+
});
|
|
6065
|
+
|
|
6066
|
+
// src/commands/bucket/key/index.ts
|
|
6067
|
+
var keyCommand = new Command68("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand5).addCommand(lsCommand9).addCommand(rmCommand8);
|
|
6068
|
+
|
|
6069
|
+
// src/commands/bucket/ls.ts
|
|
6070
|
+
import { Command as Command69 } from "commander";
|
|
6071
|
+
var lsCommand10 = new Command69("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) => {
|
|
6072
|
+
const client = await bucketClient(cmd);
|
|
6073
|
+
try {
|
|
6074
|
+
const buckets = await client.listBuckets({ all: opts.all });
|
|
6075
|
+
if (opts.json) {
|
|
6076
|
+
json(buckets);
|
|
6077
|
+
return;
|
|
6078
|
+
}
|
|
6079
|
+
if (buckets.length === 0) {
|
|
6080
|
+
info("no buckets yet; make one with: kvbox bucket create <name>");
|
|
6081
|
+
return;
|
|
6082
|
+
}
|
|
6083
|
+
const me2 = client.target.kind === "cloud" ? client.target.user : void 0;
|
|
6084
|
+
table(
|
|
6085
|
+
buckets.map((b) => ({
|
|
6086
|
+
owner: b.owner === me2 ? "private" : b.owner,
|
|
6087
|
+
name: b.name,
|
|
6088
|
+
keys: b.keys,
|
|
6089
|
+
created: age(b.createdAt)
|
|
6090
|
+
}))
|
|
6091
|
+
);
|
|
6092
|
+
for (const s of await client.listStorage({ all: opts.all })) {
|
|
6093
|
+
info(`${color.dim(s.owner === me2 ? "your object storage:" : `object storage of ${s.owner}:`)} ${endpointText(s.endpoint)} ${s.sizeGib} GB ${priceText(s)}`);
|
|
6094
|
+
}
|
|
6095
|
+
} finally {
|
|
6096
|
+
await client.close();
|
|
6097
|
+
}
|
|
6098
|
+
});
|
|
6099
|
+
|
|
6100
|
+
// src/commands/bucket/rm.ts
|
|
6101
|
+
import { Command as Command70 } from "commander";
|
|
6102
|
+
var rmCommand9 = new Command70("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) => {
|
|
6103
|
+
const client = await bucketClient(cmd);
|
|
6104
|
+
try {
|
|
6105
|
+
const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
|
|
6106
|
+
if (!await confirm(question, opts.yes ?? false)) {
|
|
6107
|
+
info("cancelled");
|
|
6108
|
+
process.exitCode = 1;
|
|
6109
|
+
return;
|
|
6110
|
+
}
|
|
6111
|
+
const before = (await client.listStorage()).length;
|
|
6112
|
+
await spin(`deleting bucket ${name}\u2026`, client.deleteBucket(name, opts.force ?? false));
|
|
6113
|
+
const gone = (await client.listStorage()).length < before;
|
|
6114
|
+
info(`${color.green("\u2713")} bucket ${name} deleted${gone ? color.dim(" (it was the last one: the object storage is removed and no longer charged)") : ""}`);
|
|
6115
|
+
} finally {
|
|
6116
|
+
await client.close();
|
|
6117
|
+
}
|
|
6118
|
+
});
|
|
6119
|
+
|
|
6120
|
+
// src/commands/bucket/index.ts
|
|
6121
|
+
var bucketCommand = new Command71("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand4).addCommand(lsCommand10).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand9).addCommand(keyCommand);
|
|
6122
|
+
var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
|
|
6123
|
+
for (const cmd of bucketCommand.commands) {
|
|
6124
|
+
if (cmd === keyCommand) cmd.commands.forEach(withOrg);
|
|
6125
|
+
else withOrg(cmd);
|
|
6126
|
+
}
|
|
6127
|
+
|
|
5738
6128
|
// src/commands/managed/kind.ts
|
|
5739
|
-
import { Command as
|
|
6129
|
+
import { Command as Command84 } from "commander";
|
|
5740
6130
|
|
|
5741
6131
|
// src/commands/managed/create.ts
|
|
5742
|
-
import { Command as
|
|
6132
|
+
import { Command as Command73 } from "commander";
|
|
5743
6133
|
import { setTimeout as sleep3 } from "timers/promises";
|
|
5744
6134
|
|
|
5745
6135
|
// src/commands/managed/shared.ts
|
|
@@ -5772,9 +6162,9 @@ async function managedClient(cmd) {
|
|
|
5772
6162
|
}
|
|
5773
6163
|
return client;
|
|
5774
6164
|
}
|
|
5775
|
-
var
|
|
6165
|
+
var shownName2 = (m, user) => m.owner === user ? m.name : `${m.owner}/${m.name}`;
|
|
5776
6166
|
var storageText = (m) => m.health?.storageUsedBytes !== void 0 ? `${gb(m.health.storageUsedBytes)} of ${m.storageGib} GB used` : `${m.storageGib} GB`;
|
|
5777
|
-
var
|
|
6167
|
+
var nearlyFull2 = (m) => m.health?.storageUsedBytes !== void 0 && m.health.storageTotalBytes !== void 0 && m.health.storageTotalBytes > 0 && m.health.storageUsedBytes / m.health.storageTotalBytes >= 0.9;
|
|
5778
6168
|
function stateText(m) {
|
|
5779
6169
|
if (m.status === "stopped") return `${status(m.status)} ${color.dim("(only its storage is charged)")}`;
|
|
5780
6170
|
if (m.status !== "running" || m.health === void 0) return status(m.status);
|
|
@@ -5783,7 +6173,7 @@ function stateText(m) {
|
|
|
5783
6173
|
return `${status(m.status)}, ${m.health.accepting ? "accepting connections" : color.yellow("not accepting connections")}`;
|
|
5784
6174
|
}
|
|
5785
6175
|
function infoRows(spec, m, user) {
|
|
5786
|
-
const name =
|
|
6176
|
+
const name = shownName2(m, user);
|
|
5787
6177
|
const rows2 = [
|
|
5788
6178
|
["name", color.bold(name)],
|
|
5789
6179
|
["status", stateText(m)],
|
|
@@ -5791,7 +6181,7 @@ function infoRows(spec, m, user) {
|
|
|
5791
6181
|
];
|
|
5792
6182
|
if (user !== void 0 && m.owner !== user) rows2.push(["owner", m.owner]);
|
|
5793
6183
|
for (const fact of m.health?.facts ?? []) rows2.push([fact.title.toLowerCase(), fact.value]);
|
|
5794
|
-
rows2.push(["storage", `${storageText(m)}${
|
|
6184
|
+
rows2.push(["storage", `${storageText(m)}${nearlyFull2(m) ? color.yellow(` almost full: kvbox ${spec.command} grow ${name} <GB>`) : ""}`]);
|
|
5795
6185
|
rows2.push(...settingRows(spec, m.settings), ["password", color.dim(`kvbox ${spec.command} password ${name}`)]);
|
|
5796
6186
|
rows2.push(["private", `${m.urls.private} ${color.dim(m.links.length > 0 ? `(from ${m.links.join(", ")})` : `(no box is linked: kvbox ${spec.command} link ${name} <box>)`)}`]);
|
|
5797
6187
|
rows2.push(["public", m.urls.public ?? color.dim(`off (kvbox ${spec.command} public ${name} on)`)]);
|
|
@@ -5799,7 +6189,7 @@ function infoRows(spec, m, user) {
|
|
|
5799
6189
|
rows2.push(["created", `${age(m.createdAt)}${m.createdBy ? ` by ${m.createdBy}` : ""}`]);
|
|
5800
6190
|
return rows2;
|
|
5801
6191
|
}
|
|
5802
|
-
function
|
|
6192
|
+
function printRows2(rows2) {
|
|
5803
6193
|
const width2 = Math.max(...rows2.map(([label]) => label.length));
|
|
5804
6194
|
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
5805
6195
|
`);
|
|
@@ -5825,8 +6215,8 @@ function parseStorage(text2, flag) {
|
|
|
5825
6215
|
// src/commands/managed/create.ts
|
|
5826
6216
|
var READY_WAIT_MS = 9e4;
|
|
5827
6217
|
var READY_STEP_MS = 2e3;
|
|
5828
|
-
var
|
|
5829
|
-
const command = new
|
|
6218
|
+
var createCommand6 = (spec) => {
|
|
6219
|
+
const command = new Command73("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");
|
|
5830
6220
|
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
5831
6221
|
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("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
|
|
5832
6222
|
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
@@ -5840,7 +6230,7 @@ var createCommand4 = (spec) => {
|
|
|
5840
6230
|
const client = await managedClient(cmd);
|
|
5841
6231
|
try {
|
|
5842
6232
|
const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
|
|
5843
|
-
const shown =
|
|
6233
|
+
const shown = shownName2(made, me(client));
|
|
5844
6234
|
const ready = await spin(`starting ${spec.title}\u2026`, async () => {
|
|
5845
6235
|
for (const until = Date.now() + READY_WAIT_MS; Date.now() < until; await sleep3(READY_STEP_MS)) {
|
|
5846
6236
|
const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
|
|
@@ -5853,7 +6243,7 @@ var createCommand4 = (spec) => {
|
|
|
5853
6243
|
return;
|
|
5854
6244
|
}
|
|
5855
6245
|
info(`${color.green("\u2713")} database ${color.bold(shown)} ${ready ? "is ready" : "is created and still starting"} ${color.dim(`(${spec.title} ${made.version}, ${made.storageGib} GB of storage)`)}`);
|
|
5856
|
-
|
|
6246
|
+
printRows2([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
|
|
5857
6247
|
info("");
|
|
5858
6248
|
info("Nobody can reach it yet. To let something in:");
|
|
5859
6249
|
info(` a box on the same host kvbox ${spec.command} link ${shown} <box> ${color.dim(`(a new one: kvbox new <box> --near ${shown})`)}`);
|
|
@@ -5867,8 +6257,8 @@ var createCommand4 = (spec) => {
|
|
|
5867
6257
|
};
|
|
5868
6258
|
|
|
5869
6259
|
// src/commands/managed/grow.ts
|
|
5870
|
-
import { Command as
|
|
5871
|
-
var
|
|
6260
|
+
import { Command as Command74 } from "commander";
|
|
6261
|
+
var growCommand3 = (spec) => new Command74("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) => {
|
|
5872
6262
|
const storageGib = parseStorage(size, "size");
|
|
5873
6263
|
const client = await managedClient(cmd);
|
|
5874
6264
|
try {
|
|
@@ -5881,21 +6271,21 @@ var growCommand2 = (spec) => new Command64("grow").description("give a database
|
|
|
5881
6271
|
});
|
|
5882
6272
|
|
|
5883
6273
|
// src/commands/managed/info.ts
|
|
5884
|
-
import { Command as
|
|
5885
|
-
var
|
|
6274
|
+
import { Command as Command75 } from "commander";
|
|
6275
|
+
var infoCommand2 = (spec) => new Command75("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) => {
|
|
5886
6276
|
const client = await managedClient(cmd);
|
|
5887
6277
|
try {
|
|
5888
6278
|
const m = await client.getManaged(spec.kind, name);
|
|
5889
6279
|
if (opts.json) json(m);
|
|
5890
|
-
else
|
|
6280
|
+
else printRows2(infoRows(spec, m, me(client)));
|
|
5891
6281
|
} finally {
|
|
5892
6282
|
await client.close();
|
|
5893
6283
|
}
|
|
5894
6284
|
});
|
|
5895
6285
|
|
|
5896
6286
|
// src/commands/managed/link.ts
|
|
5897
|
-
import { Command as
|
|
5898
|
-
var linkCommand2 = (spec) => new
|
|
6287
|
+
import { Command as Command76 } from "commander";
|
|
6288
|
+
var linkCommand2 = (spec) => new Command76("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, box, opts, cmd) => {
|
|
5899
6289
|
const client = await managedClient(cmd);
|
|
5900
6290
|
try {
|
|
5901
6291
|
const m = await spin(`linking ${box} to ${name}\u2026`, client.linkManaged(spec.kind, name, box));
|
|
@@ -5911,7 +6301,7 @@ var linkCommand2 = (spec) => new Command66("link").description("let a box reach
|
|
|
5911
6301
|
});
|
|
5912
6302
|
|
|
5913
6303
|
// src/commands/managed/ls.ts
|
|
5914
|
-
import { Command as
|
|
6304
|
+
import { Command as Command77 } from "commander";
|
|
5915
6305
|
function listRows(items, user, kindColumn) {
|
|
5916
6306
|
return items.map((m) => ({
|
|
5917
6307
|
owner: m.owner === user ? "private" : m.owner,
|
|
@@ -5925,7 +6315,7 @@ function listRows(items, user, kindColumn) {
|
|
|
5925
6315
|
created: age(m.createdAt)
|
|
5926
6316
|
}));
|
|
5927
6317
|
}
|
|
5928
|
-
var
|
|
6318
|
+
var lsCommand11 = (spec) => new Command77("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) => {
|
|
5929
6319
|
const client = await managedClient(cmd);
|
|
5930
6320
|
try {
|
|
5931
6321
|
const items = await client.listManaged(spec?.kind, { all: opts.all });
|
|
@@ -5945,8 +6335,8 @@ var lsCommand9 = (spec) => new Command67("ls").alias("list").description(spec ?
|
|
|
5945
6335
|
});
|
|
5946
6336
|
|
|
5947
6337
|
// src/commands/managed/password.ts
|
|
5948
|
-
import { Command as
|
|
5949
|
-
var passwordCommand = (spec) => new
|
|
6338
|
+
import { Command as Command78 } from "commander";
|
|
6339
|
+
var passwordCommand = (spec) => new Command78("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) => {
|
|
5950
6340
|
const client = await managedClient(cmd);
|
|
5951
6341
|
try {
|
|
5952
6342
|
const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
|
|
@@ -5955,15 +6345,15 @@ var passwordCommand = (spec) => new Command68("password").description("show a da
|
|
|
5955
6345
|
return;
|
|
5956
6346
|
}
|
|
5957
6347
|
if (opts.reset) info(`${color.green("\u2713")} database ${name} has a new password; the old one no longer works`);
|
|
5958
|
-
|
|
6348
|
+
printRows2(secretRows(secret));
|
|
5959
6349
|
} finally {
|
|
5960
6350
|
await client.close();
|
|
5961
6351
|
}
|
|
5962
6352
|
});
|
|
5963
6353
|
|
|
5964
6354
|
// src/commands/managed/public.ts
|
|
5965
|
-
import { Command as
|
|
5966
|
-
var publicCommand = (spec) => new
|
|
6355
|
+
import { Command as Command79 } from "commander";
|
|
6356
|
+
var publicCommand = (spec) => new Command79("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) => {
|
|
5967
6357
|
if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
|
|
5968
6358
|
const client = await managedClient(cmd);
|
|
5969
6359
|
try {
|
|
@@ -5984,8 +6374,8 @@ var publicCommand = (spec) => new Command69("public").description("open a databa
|
|
|
5984
6374
|
});
|
|
5985
6375
|
|
|
5986
6376
|
// src/commands/managed/rm.ts
|
|
5987
|
-
import { Command as
|
|
5988
|
-
var
|
|
6377
|
+
import { Command as Command80 } from "commander";
|
|
6378
|
+
var rmCommand10 = (spec) => new Command80("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) => {
|
|
5989
6379
|
const client = await managedClient(cmd);
|
|
5990
6380
|
try {
|
|
5991
6381
|
if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
|
|
@@ -6001,8 +6391,8 @@ var rmCommand8 = (spec) => new Command70("rm").alias("remove").description("dele
|
|
|
6001
6391
|
});
|
|
6002
6392
|
|
|
6003
6393
|
// src/commands/managed/start.ts
|
|
6004
|
-
import { Command as
|
|
6005
|
-
var startCommand2 = (spec) => new
|
|
6394
|
+
import { Command as Command81 } from "commander";
|
|
6395
|
+
var startCommand2 = (spec) => new Command81("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
6006
6396
|
const client = await managedClient(cmd);
|
|
6007
6397
|
try {
|
|
6008
6398
|
const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
|
|
@@ -6014,8 +6404,8 @@ var startCommand2 = (spec) => new Command71("start").description("run a stopped
|
|
|
6014
6404
|
});
|
|
6015
6405
|
|
|
6016
6406
|
// src/commands/managed/stop.ts
|
|
6017
|
-
import { Command as
|
|
6018
|
-
var stopCommand2 = (spec) => new
|
|
6407
|
+
import { Command as Command82 } from "commander";
|
|
6408
|
+
var stopCommand2 = (spec) => new Command82("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) => {
|
|
6019
6409
|
const client = await managedClient(cmd);
|
|
6020
6410
|
try {
|
|
6021
6411
|
const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
|
|
@@ -6027,8 +6417,8 @@ var stopCommand2 = (spec) => new Command72("stop").description("shut a database
|
|
|
6027
6417
|
});
|
|
6028
6418
|
|
|
6029
6419
|
// src/commands/managed/unlink.ts
|
|
6030
|
-
import { Command as
|
|
6031
|
-
var unlinkCommand2 = (spec) => new
|
|
6420
|
+
import { Command as Command83 } from "commander";
|
|
6421
|
+
var unlinkCommand2 = (spec) => new Command83("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, box, opts, cmd) => {
|
|
6032
6422
|
const client = await managedClient(cmd);
|
|
6033
6423
|
try {
|
|
6034
6424
|
const m = await spin(`unlinking ${box} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box));
|
|
@@ -6041,8 +6431,8 @@ var unlinkCommand2 = (spec) => new Command73("unlink").description("stop a box f
|
|
|
6041
6431
|
|
|
6042
6432
|
// src/commands/managed/kind.ts
|
|
6043
6433
|
function kindCommand(spec, description) {
|
|
6044
|
-
const command = new
|
|
6045
|
-
for (const make of [
|
|
6434
|
+
const command = new Command84(spec.command).aliases(spec.aliases).description(description);
|
|
6435
|
+
for (const make of [createCommand6, lsCommand11, infoCommand2, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand10]) {
|
|
6046
6436
|
command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
6047
6437
|
}
|
|
6048
6438
|
return command;
|
|
@@ -6055,14 +6445,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
|
|
|
6055
6445
|
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
6056
6446
|
|
|
6057
6447
|
// src/commands/managed/index.ts
|
|
6058
|
-
import { Command as
|
|
6059
|
-
var managedCommand = new
|
|
6448
|
+
import { Command as Command85 } from "commander";
|
|
6449
|
+
var managedCommand = new Command85("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand11().option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
6060
6450
|
|
|
6061
6451
|
// src/commands/env/index.ts
|
|
6062
|
-
import { Command as
|
|
6452
|
+
import { Command as Command89 } from "commander";
|
|
6063
6453
|
|
|
6064
6454
|
// src/commands/env/ls.ts
|
|
6065
|
-
import { Command as
|
|
6455
|
+
import { Command as Command86 } from "commander";
|
|
6066
6456
|
|
|
6067
6457
|
// src/commands/env/shared.ts
|
|
6068
6458
|
function requireCloud4(client) {
|
|
@@ -6089,7 +6479,7 @@ function firstBootHint(box, name) {
|
|
|
6089
6479
|
}
|
|
6090
6480
|
|
|
6091
6481
|
// src/commands/env/ls.ts
|
|
6092
|
-
var
|
|
6482
|
+
var lsCommand12 = new Command86("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) => {
|
|
6093
6483
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6094
6484
|
try {
|
|
6095
6485
|
if (opts.box !== void 0) {
|
|
@@ -6128,8 +6518,8 @@ var lsCommand10 = new Command76("ls").alias("list").description("list the variab
|
|
|
6128
6518
|
});
|
|
6129
6519
|
|
|
6130
6520
|
// src/commands/env/rm.ts
|
|
6131
|
-
import { Command as
|
|
6132
|
-
var
|
|
6521
|
+
import { Command as Command87 } from "commander";
|
|
6522
|
+
var rmCommand11 = new Command87("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) => {
|
|
6133
6523
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6134
6524
|
try {
|
|
6135
6525
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -6166,8 +6556,8 @@ var rmCommand9 = new Command77("rm").alias("remove").description("remove variabl
|
|
|
6166
6556
|
});
|
|
6167
6557
|
|
|
6168
6558
|
// src/commands/env/set.ts
|
|
6169
|
-
import { Command as
|
|
6170
|
-
var setCommand2 = new
|
|
6559
|
+
import { Command as Command88 } from "commander";
|
|
6560
|
+
var setCommand2 = new Command88("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) => {
|
|
6171
6561
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6172
6562
|
try {
|
|
6173
6563
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -6204,14 +6594,14 @@ var setCommand2 = new Command78("set").description("add or change a variable; bo
|
|
|
6204
6594
|
});
|
|
6205
6595
|
|
|
6206
6596
|
// src/commands/env/index.ts
|
|
6207
|
-
var envCommand = new
|
|
6597
|
+
var envCommand = new Command89("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand12, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand11);
|
|
6208
6598
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
6209
6599
|
|
|
6210
6600
|
// src/commands/domain/index.ts
|
|
6211
|
-
import { Command as
|
|
6601
|
+
import { Command as Command93 } from "commander";
|
|
6212
6602
|
|
|
6213
6603
|
// src/commands/domain/add.ts
|
|
6214
|
-
import { Command as
|
|
6604
|
+
import { Command as Command90 } from "commander";
|
|
6215
6605
|
|
|
6216
6606
|
// src/commands/domain/shared.ts
|
|
6217
6607
|
function requireCloud5(client) {
|
|
@@ -6231,7 +6621,7 @@ function hostIn(name, zone) {
|
|
|
6231
6621
|
}
|
|
6232
6622
|
|
|
6233
6623
|
// src/commands/domain/add.ts
|
|
6234
|
-
var addCommand3 = new
|
|
6624
|
+
var addCommand3 = new Command90("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) => {
|
|
6235
6625
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
6236
6626
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
6237
6627
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -6267,8 +6657,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
6267
6657
|
});
|
|
6268
6658
|
|
|
6269
6659
|
// src/commands/domain/ls.ts
|
|
6270
|
-
import { Command as
|
|
6271
|
-
var
|
|
6660
|
+
import { Command as Command91 } from "commander";
|
|
6661
|
+
var lsCommand13 = new Command91("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
6272
6662
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
6273
6663
|
try {
|
|
6274
6664
|
requireCloud5(client);
|
|
@@ -6297,8 +6687,8 @@ var lsCommand11 = new Command81("ls").alias("list").description("list your custo
|
|
|
6297
6687
|
});
|
|
6298
6688
|
|
|
6299
6689
|
// src/commands/domain/rm.ts
|
|
6300
|
-
import { Command as
|
|
6301
|
-
var
|
|
6690
|
+
import { Command as Command92 } from "commander";
|
|
6691
|
+
var rmCommand12 = new Command92("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) => {
|
|
6302
6692
|
const domain = domainArg.trim().toLowerCase();
|
|
6303
6693
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
6304
6694
|
try {
|
|
@@ -6319,7 +6709,7 @@ var rmCommand10 = new Command82("rm").alias("remove").description("stop serving
|
|
|
6319
6709
|
});
|
|
6320
6710
|
|
|
6321
6711
|
// src/commands/domain/index.ts
|
|
6322
|
-
var domainCommand = new
|
|
6712
|
+
var domainCommand = new Command93("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand3).addCommand(lsCommand13).addCommand(rmCommand12);
|
|
6323
6713
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
6324
6714
|
|
|
6325
6715
|
// src/commands/update.ts
|
|
@@ -6327,7 +6717,7 @@ import { spawn as spawn6 } from "child_process";
|
|
|
6327
6717
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
6328
6718
|
import { tmpdir } from "os";
|
|
6329
6719
|
import { join as join9 } from "path";
|
|
6330
|
-
import { Command as
|
|
6720
|
+
import { Command as Command94 } from "commander";
|
|
6331
6721
|
|
|
6332
6722
|
// src/update.ts
|
|
6333
6723
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -6446,7 +6836,7 @@ function run2(cmd, args) {
|
|
|
6446
6836
|
child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
|
|
6447
6837
|
});
|
|
6448
6838
|
}
|
|
6449
|
-
var selfUpdateCommand = new
|
|
6839
|
+
var selfUpdateCommand = new Command94("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
|
|
6450
6840
|
suppressUpdateNotice();
|
|
6451
6841
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
6452
6842
|
let code;
|
|
@@ -6510,6 +6900,7 @@ var HELP_GROUPS = [
|
|
|
6510
6900
|
["vm", "everything about boxes: fork, rescale, ports, hooks, backups"],
|
|
6511
6901
|
["snapshots", "freeze a running box into a snapshot, start new boxes from it"],
|
|
6512
6902
|
["volume", "disks of their own that move between boxes"],
|
|
6903
|
+
["bucket", "object storage: S3 buckets for your files"],
|
|
6513
6904
|
["pg", "managed PostgreSQL: a database kvbox runs for you"],
|
|
6514
6905
|
["redis", "managed Redis (Valkey): a Redis kvbox runs for you"],
|
|
6515
6906
|
["managed", "every managed database, whatever its kind"],
|
|
@@ -6570,10 +6961,11 @@ function installRootHelp(program) {
|
|
|
6570
6961
|
|
|
6571
6962
|
// src/program.ts
|
|
6572
6963
|
function buildProgram() {
|
|
6573
|
-
const program = new
|
|
6964
|
+
const program = new Command95("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").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();
|
|
6574
6965
|
program.addCommand(vmCommand);
|
|
6575
6966
|
program.addCommand(snapshotsCommand);
|
|
6576
6967
|
program.addCommand(volumeCommand);
|
|
6968
|
+
program.addCommand(bucketCommand);
|
|
6577
6969
|
program.addCommand(pgCommand);
|
|
6578
6970
|
program.addCommand(redisCommand);
|
|
6579
6971
|
program.addCommand(managedCommand);
|