@kvbox/cli 0.6.21 → 0.6.23
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 +1785 -727
- 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 Command171 } 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.23" : void 0);
|
|
174
174
|
|
|
175
175
|
// src/commands/vm/index.ts
|
|
176
176
|
import { Command as Command44 } from "commander";
|
|
@@ -804,6 +804,14 @@ var MachineSchema = z2.object({
|
|
|
804
804
|
* each time it is needed. Absent: none. A host before integrations never sends it.
|
|
805
805
|
*/
|
|
806
806
|
integrations: z2.array(z2.string()).optional(),
|
|
807
|
+
/** The id of the cluster the box is a part of on its host (#215), as the host keeps it. Absent: none, or a host from before it said so. */
|
|
808
|
+
clusterId: z2.string().optional(),
|
|
809
|
+
/**
|
|
810
|
+
* The Kubernetes cluster the box is a node of, and its pool (#218). Only the control plane fills it in, on
|
|
811
|
+
* `GET /machines`. Such a box is opened like any other, but what would change it is its pool's to do
|
|
812
|
+
* (`kvbox k8s pool`): the control plane refuses it on the box.
|
|
813
|
+
*/
|
|
814
|
+
cluster: z2.object({ name: z2.string(), pool: z2.string() }).optional(),
|
|
807
815
|
/** How to reach what the box serves, its secrets masked (#87): `postgres://postgres:****@db.kvbox:5432/postgres`. */
|
|
808
816
|
url: z2.string().optional(),
|
|
809
817
|
/**
|
|
@@ -946,6 +954,7 @@ var HostEnvRequest = z2.object({
|
|
|
946
954
|
vars: z2.array(z2.object({ name: z2.string(), value: z2.string() }))
|
|
947
955
|
});
|
|
948
956
|
var HostEnvVersionsSchema = z2.array(z2.object({ owner: z2.string(), version: z2.number().int() }));
|
|
957
|
+
var CLUSTER_ID_RE = /^[a-z0-9][a-z0-9_-]{0,39}$/;
|
|
949
958
|
var CreateMachineRequest = z2.object({
|
|
950
959
|
name: z2.string().optional(),
|
|
951
960
|
/** Ignored over the local socket (the caller is the host owner); the control plane sets it over HTTPS. */
|
|
@@ -978,8 +987,11 @@ var CreateMachineRequest = z2.object({
|
|
|
978
987
|
host: z2.string().optional(),
|
|
979
988
|
/** The image to boot (#87, `kvbox new --base postgres`). Absent: the base image. */
|
|
980
989
|
image: z2.string().optional(),
|
|
981
|
-
/**
|
|
982
|
-
|
|
990
|
+
/**
|
|
991
|
+
* The box's own environment variables (#87, `kvbox new -e NAME=value`), over its owner's. `secret`: kept as a
|
|
992
|
+
* secret, whose value no route answers with (a cluster's join token, #216); a host from before it keeps it plain.
|
|
993
|
+
*/
|
|
994
|
+
env: z2.array(z2.object({ name: z2.string(), value: z2.string(), secret: z2.boolean().optional() })).optional(),
|
|
983
995
|
/**
|
|
984
996
|
* Start the box on this backup's disk (#141, `kvbox new --from-backup <id>`), a removed box's too: its image,
|
|
985
997
|
* version and variables come from the backup, its size too unless given. Only the control plane reads it.
|
|
@@ -989,7 +1001,13 @@ var CreateMachineRequest = z2.object({
|
|
|
989
1001
|
* The integrations turned on for the box (#205, `kvbox new --integration github`). Absent: none, or with
|
|
990
1002
|
* `from` / `fromBackup` the list the snapshot or the backup was taken with.
|
|
991
1003
|
*/
|
|
992
|
-
integrations: IntegrationListSchema.optional()
|
|
1004
|
+
integrations: IntegrationListSchema.optional(),
|
|
1005
|
+
/**
|
|
1006
|
+
* The cluster the box is a part of (kvbox k8s, #215): on its host, the boxes of one owner with the same id
|
|
1007
|
+
* reach each other on any port. An id the control plane makes, never a user's: the control plane refuses
|
|
1008
|
+
* it from anyone it did not make it for, and a host takes it only from a control plane.
|
|
1009
|
+
*/
|
|
1010
|
+
cluster: z2.string().regex(CLUSTER_ID_RE).optional()
|
|
993
1011
|
});
|
|
994
1012
|
var HostFromBackupRequest = CreateMachineRequest.omit({ from: true, fromBackup: true, image: true, env: true }).extend({ backup: HostRestoreRequest });
|
|
995
1013
|
var ForkMachineRequest = z2.object({
|
|
@@ -1086,6 +1104,8 @@ var CapacitySchema = z2.object({
|
|
|
1086
1104
|
integrations: z2.boolean().optional(),
|
|
1087
1105
|
/** True on a kvbox-server that carries a link to a box on another host (#207); the control plane links across hosts only between two such. */
|
|
1088
1106
|
farLinks: z2.boolean().optional(),
|
|
1107
|
+
/** True on a host whose network puts the boxes of one cluster in reach of each other (#215); the control plane places a cluster's box only on such a host. */
|
|
1108
|
+
clusters: z2.boolean().optional(),
|
|
1089
1109
|
/** The integrations this kvbox-server knows (`hostKnowsIntegrations`). Absent with `integrations`: the first one's, `github` alone. */
|
|
1090
1110
|
integrationIds: z2.array(z2.string()).optional()
|
|
1091
1111
|
});
|
|
@@ -1222,6 +1242,32 @@ var CronUsageSchema = z2.object({
|
|
|
1222
1242
|
/** When it was made. */
|
|
1223
1243
|
historyFrom: z2.string().nullable()
|
|
1224
1244
|
});
|
|
1245
|
+
var ClusterUsageSchema = z2.object({
|
|
1246
|
+
id: z2.string(),
|
|
1247
|
+
name: z2.string(),
|
|
1248
|
+
owner: z2.string(),
|
|
1249
|
+
ownerKind: z2.enum(["user", "org"]).optional(),
|
|
1250
|
+
/** `removed` once its master is. */
|
|
1251
|
+
status: z2.enum(["present", "removed"]),
|
|
1252
|
+
/** The hours its master existed in the window, running or not. */
|
|
1253
|
+
hours: z2.number(),
|
|
1254
|
+
master: z2.object({
|
|
1255
|
+
seconds: MachineUsageSchema.shape.seconds,
|
|
1256
|
+
vcpuHours: z2.number(),
|
|
1257
|
+
ramGibHours: z2.number(),
|
|
1258
|
+
diskGibHours: z2.number(),
|
|
1259
|
+
volumeHours: z2.number(),
|
|
1260
|
+
volumeGibHours: z2.number(),
|
|
1261
|
+
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional()
|
|
1262
|
+
}),
|
|
1263
|
+
nodes: z2.array(BoxUsageSchema.extend({
|
|
1264
|
+
/** The pool it is, or was, a node of. */
|
|
1265
|
+
pool: z2.string().optional()
|
|
1266
|
+
})),
|
|
1267
|
+
fee: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
|
|
1268
|
+
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional(),
|
|
1269
|
+
historyFrom: z2.string().nullable()
|
|
1270
|
+
});
|
|
1225
1271
|
var BackupUsageSchema = z2.object({
|
|
1226
1272
|
id: z2.string(),
|
|
1227
1273
|
kind: z2.string(),
|
|
@@ -1255,6 +1301,8 @@ var UsageDaySchema = z2.object({
|
|
|
1255
1301
|
storage: z2.array(UsageDayItemSchema).optional(),
|
|
1256
1302
|
/** Cron services that existed that day (#190); absent on a day without any. */
|
|
1257
1303
|
cron: z2.array(UsageDayItemSchema).optional(),
|
|
1304
|
+
/** Kubernetes clusters that existed that day (#222), each with its master and nodes together; absent on a day without any. */
|
|
1305
|
+
clusters: z2.array(UsageDayItemSchema).optional(),
|
|
1258
1306
|
/** Paid backups that turned ready that day, summed per thing backed up (`id` is `<owner>/<kind>:<name>`); absent on a day without any. */
|
|
1259
1307
|
backups: z2.array(UsageDayItemSchema).optional()
|
|
1260
1308
|
});
|
|
@@ -1271,6 +1319,11 @@ var UsageReportSchema = z2.object({
|
|
|
1271
1319
|
storage: z2.array(VolumeUsageSchema).optional(),
|
|
1272
1320
|
/** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
|
|
1273
1321
|
cron: z2.array(CronUsageSchema).optional(),
|
|
1322
|
+
/**
|
|
1323
|
+
* Kubernetes clusters (#222, control plane only): one row per cluster a slug has or had, with its master
|
|
1324
|
+
* and its nodes; those boxes are in no other list. Absent when there is none.
|
|
1325
|
+
*/
|
|
1326
|
+
clusters: z2.array(ClusterUsageSchema).optional(),
|
|
1274
1327
|
/** Paid backups (control plane only): one row per box, volume or service backed up by hand in the window. Absent when there is none. */
|
|
1275
1328
|
backups: z2.array(BackupUsageSchema).optional(),
|
|
1276
1329
|
/** With `?by=day` only, oldest day first. */
|
|
@@ -1282,7 +1335,7 @@ var UsageReportSchema = z2.object({
|
|
|
1282
1335
|
diskGibHours: z2.number(),
|
|
1283
1336
|
volumeHours: z2.number().optional(),
|
|
1284
1337
|
volumeGibHours: z2.number().optional(),
|
|
1285
|
-
/** Boxes, volumes, object storage, cron services and paid backups together. */
|
|
1338
|
+
/** Boxes, volumes, object storage, cron services, Kubernetes clusters and paid backups together; the hours above are those of `boxes` and `volumes` alone. */
|
|
1286
1339
|
cost: z2.object({ amount: z2.number(), currency: z2.string() }).optional()
|
|
1287
1340
|
})
|
|
1288
1341
|
});
|
|
@@ -1317,7 +1370,7 @@ var VolumeEventsResponseSchema = z2.object({
|
|
|
1317
1370
|
events: z2.array(VolumeEventRowSchema),
|
|
1318
1371
|
next: z2.number().int()
|
|
1319
1372
|
});
|
|
1320
|
-
var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit", "box-outdated", "storage-outdated", "object-exists", "storage-waking"];
|
|
1373
|
+
var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit", "box-outdated", "storage-outdated", "object-exists", "storage-waking", "cluster-busy", "node-has-data"];
|
|
1321
1374
|
var ApiErrorCodeSchema = z2.enum(API_ERROR_CODES);
|
|
1322
1375
|
var ApiErrorSchema = z2.object({
|
|
1323
1376
|
error: z2.string(),
|
|
@@ -1487,6 +1540,16 @@ var LoginResponseSchema = z2.object({
|
|
|
1487
1540
|
/** Whose boxes the certificate opens: `<slug>@<realm>` for the user and each org they are in (orgs phase 4). */
|
|
1488
1541
|
sshCertPrincipals: z2.array(z2.string()).optional()
|
|
1489
1542
|
});
|
|
1543
|
+
var PasswordResetRequestSchema = z2.object({
|
|
1544
|
+
email: z2.string().min(1).max(320)
|
|
1545
|
+
});
|
|
1546
|
+
var PasswordResetCheckSchema = z2.object({
|
|
1547
|
+
token: z2.string().min(1).max(200)
|
|
1548
|
+
});
|
|
1549
|
+
var PasswordResetConfirmSchema = z2.object({
|
|
1550
|
+
token: z2.string().min(1).max(200),
|
|
1551
|
+
password: z2.string().min(1)
|
|
1552
|
+
});
|
|
1490
1553
|
var DEVICE_LOGIN_PICKUP_SEC = 60;
|
|
1491
1554
|
var DeviceLoginRequestSchema = z2.object({
|
|
1492
1555
|
// Capped: anyone may open a login, and the key is stored until it expires (an RSA-16384 key is ~2.8 KB).
|
|
@@ -1780,6 +1843,353 @@ async function ensureCert(client, p = paths(), now = Date.now(), opts = {}) {
|
|
|
1780
1843
|
return "renewed";
|
|
1781
1844
|
}
|
|
1782
1845
|
|
|
1846
|
+
// ../shared/src/k8s.ts
|
|
1847
|
+
import { z as z6 } from "zod";
|
|
1848
|
+
|
|
1849
|
+
// ../shared/src/managed.ts
|
|
1850
|
+
import { z as z5 } from "zod";
|
|
1851
|
+
|
|
1852
|
+
// ../shared/src/usage.ts
|
|
1853
|
+
import { z as z4 } from "zod";
|
|
1854
|
+
var PricingSchema = z4.object({
|
|
1855
|
+
currency: z4.string().min(1),
|
|
1856
|
+
vcpuHour: z4.number().nonnegative(),
|
|
1857
|
+
ramGibHour: z4.number().nonnegative(),
|
|
1858
|
+
diskGibHour: z4.number().nonnegative(),
|
|
1859
|
+
volumeHour: z4.number().nonnegative().default(0),
|
|
1860
|
+
volumeGibHour: z4.number().nonnegative().default(0),
|
|
1861
|
+
diskIncludedGib: z4.number().int().nonnegative().default(0),
|
|
1862
|
+
/**
|
|
1863
|
+
* Object storage (#182): an hour of a slug's storage existing, whatever it holds, which covers its
|
|
1864
|
+
* hidden box and the first `storageIncludedGib` of its size; each GiB above that is `storageGibHour`.
|
|
1865
|
+
* A price list from before object storage charges nothing for it.
|
|
1866
|
+
*/
|
|
1867
|
+
storageHour: z4.number().nonnegative().default(0),
|
|
1868
|
+
storageGibHour: z4.number().nonnegative().default(0),
|
|
1869
|
+
storageIncludedGib: z4.number().int().nonnegative().default(0),
|
|
1870
|
+
/** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
|
|
1871
|
+
cronHour: z4.number().nonnegative().default(0),
|
|
1872
|
+
/**
|
|
1873
|
+
* One backup a person starts, of anything, charged once it is ready (decision "A backup taken by hand
|
|
1874
|
+
* costs a flat price…"); a failed one costs nothing. A price list from before it charges nothing.
|
|
1875
|
+
*/
|
|
1876
|
+
backup: z4.number().nonnegative().default(0),
|
|
1877
|
+
/**
|
|
1878
|
+
* One nightly backup of a box, a volume or the object storage, charged once it is ready (decision "A nightly
|
|
1879
|
+
* backup you switch on is charged…"): their switch is off until someone turns it on. A managed database's
|
|
1880
|
+
* nightly backup, on from its creation, is included in its price. A price list from before it charges nothing.
|
|
1881
|
+
*/
|
|
1882
|
+
scheduledBackup: z4.number().nonnegative().default(0),
|
|
1883
|
+
/**
|
|
1884
|
+
* A Kubernetes cluster (#222): an hour of one existing, on top of its boxes. A cluster is priced as the
|
|
1885
|
+
* boxes it is (its master and its nodes), so this is 0 until a flat fee is wanted.
|
|
1886
|
+
*/
|
|
1887
|
+
clusterHour: z4.number().nonnegative().default(0)
|
|
1888
|
+
});
|
|
1889
|
+
var PriceListSchema = PricingSchema.extend({ welcomeCredit: z4.number().nonnegative() });
|
|
1890
|
+
var HOUR_MS = 36e5;
|
|
1891
|
+
var round = (n2, places) => Math.round(n2 * 10 ** places) / 10 ** places;
|
|
1892
|
+
function costOf(t, pricing) {
|
|
1893
|
+
return t.vcpuHours * pricing.vcpuHour + t.ramGibHours * pricing.ramGibHour + t.diskGibHours * pricing.diskGibHour;
|
|
1894
|
+
}
|
|
1895
|
+
function sumUsage(items, pricing) {
|
|
1896
|
+
const sum = {
|
|
1897
|
+
seconds: { running: 0, standby: 0, hibernated: 0, stopped: 0 },
|
|
1898
|
+
vcpuHours: 0,
|
|
1899
|
+
ramGibHours: 0,
|
|
1900
|
+
diskGibHours: 0
|
|
1901
|
+
};
|
|
1902
|
+
for (const t of items) {
|
|
1903
|
+
for (const s of Object.keys(sum.seconds)) sum.seconds[s] += t.seconds[s];
|
|
1904
|
+
sum.vcpuHours += t.vcpuHours;
|
|
1905
|
+
sum.ramGibHours += t.ramGibHours;
|
|
1906
|
+
sum.diskGibHours += t.diskGibHours;
|
|
1907
|
+
}
|
|
1908
|
+
sum.vcpuHours = round(sum.vcpuHours, 3);
|
|
1909
|
+
sum.ramGibHours = round(sum.ramGibHours, 3);
|
|
1910
|
+
sum.diskGibHours = round(sum.diskGibHours, 3);
|
|
1911
|
+
if (pricing !== void 0) sum.cost = { amount: round(costOf(sum, pricing), 4), currency: pricing.currency };
|
|
1912
|
+
return sum;
|
|
1913
|
+
}
|
|
1914
|
+
var DAY_MS = 24 * HOUR_MS;
|
|
1915
|
+
|
|
1916
|
+
// ../shared/src/managed.ts
|
|
1917
|
+
var PriceSchema = z5.object({ perMonth: z5.number(), storagePerMonth: z5.number(), currency: z5.string() });
|
|
1918
|
+
var ManagedCatalogEntrySchema = z5.object({
|
|
1919
|
+
/** The kind, as in `/managed/<kind>`: `postgres`. */
|
|
1920
|
+
kind: z5.string(),
|
|
1921
|
+
/** The CLI command for it: `pg` (`kvbox pg create …`). */
|
|
1922
|
+
command: z5.string(),
|
|
1923
|
+
title: z5.string(),
|
|
1924
|
+
description: z5.string(),
|
|
1925
|
+
/** The version a new one runs, as shown: `18`. */
|
|
1926
|
+
version: z5.string(),
|
|
1927
|
+
/** The port a linked box reaches it on. */
|
|
1928
|
+
port: z5.number().int(),
|
|
1929
|
+
/** The port `public on` opens behind a host port: `port` again unless the kind serves TLS on another. */
|
|
1930
|
+
publicPort: z5.number().int(),
|
|
1931
|
+
/** Its guide, as a URL. */
|
|
1932
|
+
docs: z5.string().optional(),
|
|
1933
|
+
storage: z5.object({ defaultGib: z5.number().int(), minGib: z5.number().int(), maxGib: z5.number().int() }),
|
|
1934
|
+
/**
|
|
1935
|
+
* What create takes of this kind alone, beside what every kind takes (name, password, storage, near): a
|
|
1936
|
+
* flag and a form field each, all optional, `default` in words.
|
|
1937
|
+
*/
|
|
1938
|
+
options: z5.array(z5.object({ name: z5.string(), title: z5.string(), description: z5.string(), default: z5.string() })),
|
|
1939
|
+
/** A month of it running with the default storage, and each further GB of storage. */
|
|
1940
|
+
price: PriceSchema.extend({ storageGibPerMonth: z5.number() }),
|
|
1941
|
+
/** Whether a host answering now can run it. */
|
|
1942
|
+
available: z5.boolean()
|
|
1943
|
+
});
|
|
1944
|
+
var CreateManagedRequest = z5.object({
|
|
1945
|
+
name: z5.string(),
|
|
1946
|
+
/** The kind's own options by name (its catalog entry lists them); the kind checks them. */
|
|
1947
|
+
options: z5.record(z5.string(), z5.string()).optional(),
|
|
1948
|
+
password: z5.string().optional(),
|
|
1949
|
+
storageGib: z5.number().int().optional(),
|
|
1950
|
+
/** Place it on the host of this box, so the box can be linked to it. */
|
|
1951
|
+
near: z5.string().optional(),
|
|
1952
|
+
/**
|
|
1953
|
+
* A backup of a database of the same kind and major version, of the same account (#186): the new
|
|
1954
|
+
* service starts on its data, a removed service's included. Its settings (Postgres: database, user)
|
|
1955
|
+
* are the backup's; the password is the new one.
|
|
1956
|
+
*/
|
|
1957
|
+
fromBackup: z5.string().optional()
|
|
1958
|
+
});
|
|
1959
|
+
var ManagedHealthSchema = z5.object({
|
|
1960
|
+
/** Its first start has finished: it has set itself up on its storage. */
|
|
1961
|
+
ready: z5.boolean(),
|
|
1962
|
+
/** It accepts connections. */
|
|
1963
|
+
accepting: z5.boolean(),
|
|
1964
|
+
version: z5.string(),
|
|
1965
|
+
/** The storage volume: what is used of it and its size. */
|
|
1966
|
+
storageUsedBytes: z5.number().optional(),
|
|
1967
|
+
storageTotalBytes: z5.number().optional(),
|
|
1968
|
+
/** What else the kind reports, ready to show: `{title: "Connections", value: "3"}`. */
|
|
1969
|
+
facts: z5.array(z5.object({ title: z5.string(), value: z5.string() }))
|
|
1970
|
+
});
|
|
1971
|
+
var UrlsSchema = z5.object({ private: z5.string(), public: z5.string().optional() });
|
|
1972
|
+
var ManagedSchema = z5.object({
|
|
1973
|
+
kind: z5.string(),
|
|
1974
|
+
name: z5.string(),
|
|
1975
|
+
/** The owning slug, bare. */
|
|
1976
|
+
owner: z5.string(),
|
|
1977
|
+
ownerKind: z5.enum(["user", "org"]),
|
|
1978
|
+
/** `running`, `stopped` (storage only is charged), `hibernated` or `standby` (out of credit), `unknown` (its host does not answer). */
|
|
1979
|
+
status: BoxStatusSchema,
|
|
1980
|
+
/** The catalog version: `18`. */
|
|
1981
|
+
version: z5.string(),
|
|
1982
|
+
/** What the kind keeps of its create options, defaults filled in: `{database, user}` for Postgres, `{}` for a kind with none. */
|
|
1983
|
+
settings: z5.record(z5.string(), z5.string()),
|
|
1984
|
+
storageGib: z5.number().int(),
|
|
1985
|
+
/** Where a linked box reaches it: `<name>.<slug>.kvbox` (resolves from a box of any slug it is linked to) and the port. */
|
|
1986
|
+
private: z5.object({ host: z5.string(), port: z5.number().int() }),
|
|
1987
|
+
/** Where the internet reaches it, null while it is not public. The port is its own for its whole life. */
|
|
1988
|
+
public: z5.object({ host: z5.string(), port: z5.number().int() }).nullable(),
|
|
1989
|
+
/** The boxes linked to it, as the caller would name them. */
|
|
1990
|
+
links: z5.array(z5.string()),
|
|
1991
|
+
/** The name of the host it runs on, for `--near` and links. */
|
|
1992
|
+
host: z5.string(),
|
|
1993
|
+
country: z5.string().optional(),
|
|
1994
|
+
createdBy: z5.string().nullable(),
|
|
1995
|
+
createdAt: z5.string(),
|
|
1996
|
+
/** Connection strings with the password as `****`. */
|
|
1997
|
+
urls: UrlsSchema,
|
|
1998
|
+
price: PriceSchema,
|
|
1999
|
+
/** Its nightly backup (#186 slice 4): on from creation, `kvbox <kind> backup schedule` changes it. Null for a control plane from before schedules. */
|
|
2000
|
+
backupSchedule: BackupScheduleSchema.nullable().default(null),
|
|
2001
|
+
/** Only in `GET /managed/<kind>/<name>` (asked live): null when it is not running or did not answer. */
|
|
2002
|
+
health: ManagedHealthSchema.nullable().optional()
|
|
2003
|
+
});
|
|
2004
|
+
var ManagedSecretSchema = z5.object({ password: z5.string(), urls: UrlsSchema });
|
|
2005
|
+
var CreatedManagedSchema = ManagedSchema.extend({
|
|
2006
|
+
secret: ManagedSecretSchema,
|
|
2007
|
+
/** The backup it was made from (`fromBackup`), when it was. */
|
|
2008
|
+
fromBackup: z5.string().optional()
|
|
2009
|
+
});
|
|
2010
|
+
var ResetPasswordRequest = z5.object({ password: z5.string().optional() });
|
|
2011
|
+
var SetPublicRequest = z5.object({ on: z5.boolean() });
|
|
2012
|
+
var ManagedLinkRequest = z5.object({ box: z5.string() });
|
|
2013
|
+
var GrowManagedRequest = z5.object({ storageGib: z5.number().int() });
|
|
2014
|
+
var ManagedBackupSchema = z5.object({
|
|
2015
|
+
id: z5.string(),
|
|
2016
|
+
owner: z5.string(),
|
|
2017
|
+
kind: z5.string(),
|
|
2018
|
+
name: z5.string(),
|
|
2019
|
+
version: z5.string(),
|
|
2020
|
+
status: z5.enum(BACKUP_STATUSES),
|
|
2021
|
+
/** Why it failed; null otherwise. */
|
|
2022
|
+
error: z5.string().nullable(),
|
|
2023
|
+
/** The service's storage when taken. */
|
|
2024
|
+
diskBytes: z5.number().int().nullable(),
|
|
2025
|
+
/** What it holds: the slots that are not all zeros. */
|
|
2026
|
+
dataBytes: z5.number().int().nullable(),
|
|
2027
|
+
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
2028
|
+
uploadedBytes: z5.number().int().nullable(),
|
|
2029
|
+
/** Who asked for it; for a scheduled one, the database's creator. */
|
|
2030
|
+
createdBy: z5.string().nullable(),
|
|
2031
|
+
/** Started by the database's backup schedule, not by a person: it does not count toward the daily limit. */
|
|
2032
|
+
scheduled: z5.boolean().default(false),
|
|
2033
|
+
createdAt: z5.string(),
|
|
2034
|
+
finishedAt: z5.string().nullable()
|
|
2035
|
+
});
|
|
2036
|
+
|
|
2037
|
+
// ../shared/src/k8s.ts
|
|
2038
|
+
var ClaimClusterSubdomainRequest = z6.object({ name: z6.string() });
|
|
2039
|
+
var AddClusterDomainRequest = z6.object({ domain: z6.string() });
|
|
2040
|
+
var ClusterLinkRequest = z6.object({ to: z6.string().min(1), port: z6.number().int().min(1).max(65535).optional() });
|
|
2041
|
+
var ClusterLinkSchema = z6.object({
|
|
2042
|
+
/** The database's or the box's name, and its slug. */
|
|
2043
|
+
to: z6.string(),
|
|
2044
|
+
owner: z6.string(),
|
|
2045
|
+
/** `postgres`, `redis`, or `box`. */
|
|
2046
|
+
kind: z6.string(),
|
|
2047
|
+
port: z6.number().int(),
|
|
2048
|
+
/** Where a pod finds it: `<name>.<slug>.kvbox`. */
|
|
2049
|
+
host: z6.string(),
|
|
2050
|
+
/** The cluster's boxes that have the link now, by name (the master is the cluster's own name); only in the answer to a link or an unlink. */
|
|
2051
|
+
boxes: z6.array(z6.string()).optional()
|
|
2052
|
+
});
|
|
2053
|
+
var NODE_SIZES = ["s", "m", "l"];
|
|
2054
|
+
var DEFAULT_POOL_NODES = 2;
|
|
2055
|
+
var MAX_POOL_NODES = 9;
|
|
2056
|
+
var ClusterPriceSchema = z6.object({
|
|
2057
|
+
perMonth: z6.number(),
|
|
2058
|
+
/** Absent from a control plane older than #222. */
|
|
2059
|
+
nodesPerMonth: z6.number().optional(),
|
|
2060
|
+
totalPerMonth: z6.number().optional(),
|
|
2061
|
+
currency: z6.string()
|
|
2062
|
+
});
|
|
2063
|
+
var ClusterCatalogSchema = z6.object({
|
|
2064
|
+
/** The Kubernetes version a new cluster runs: `1.37`. */
|
|
2065
|
+
version: z6.string(),
|
|
2066
|
+
currency: z6.string(),
|
|
2067
|
+
/** Every cluster has one; its price is in every cluster's. */
|
|
2068
|
+
master: z6.object({ size: z6.string(), storageGib: z6.number().int(), perMonth: z6.number() }),
|
|
2069
|
+
/** What a node may be sized at, each with a month of one running. */
|
|
2070
|
+
nodes: z6.array(z6.object({ size: z6.enum(NODE_SIZES), vcpu: z6.number().int(), memMib: z6.number().int(), diskGib: z6.number().int(), perMonth: z6.number() })),
|
|
2071
|
+
/** The flat price per cluster a month, part of `master.perMonth`; 0 while there is none. */
|
|
2072
|
+
clusterPerMonth: z6.number(),
|
|
2073
|
+
/** The smallest cluster: its master and `defaultNodes` nodes of the smallest size. */
|
|
2074
|
+
fromPerMonth: z6.number(),
|
|
2075
|
+
limits: z6.object({ defaultNodes: z6.number().int(), maxPoolNodes: z6.number().int(), nameRule: z6.string() })
|
|
2076
|
+
});
|
|
2077
|
+
var CreateClusterRequest = z6.object({
|
|
2078
|
+
name: z6.string(),
|
|
2079
|
+
/** What each node of its first pool is sized at. */
|
|
2080
|
+
size: z6.enum(NODE_SIZES),
|
|
2081
|
+
/** How many nodes that pool starts with (`DEFAULT_POOL_NODES`). */
|
|
2082
|
+
nodes: z6.number().int().min(1).max(MAX_POOL_NODES).optional(),
|
|
2083
|
+
/** Place it on the host of this box. */
|
|
2084
|
+
near: z6.string().optional()
|
|
2085
|
+
});
|
|
2086
|
+
var AddPoolRequest = z6.object({
|
|
2087
|
+
/** Without one the pool is named after its size (`m`). */
|
|
2088
|
+
name: z6.string().optional(),
|
|
2089
|
+
size: z6.enum(NODE_SIZES),
|
|
2090
|
+
/** How many nodes it starts with (`DEFAULT_POOL_NODES`). */
|
|
2091
|
+
nodes: z6.number().int().min(1).max(MAX_POOL_NODES).optional()
|
|
2092
|
+
});
|
|
2093
|
+
var ResizePoolRequest = z6.object({
|
|
2094
|
+
nodes: z6.number().int().min(1).max(MAX_POOL_NODES),
|
|
2095
|
+
/** Fewer nodes only: they go at once, undrained, whatever they keep on their own disks. */
|
|
2096
|
+
force: z6.boolean().optional()
|
|
2097
|
+
});
|
|
2098
|
+
var ClusterNodeSchema = z6.object({
|
|
2099
|
+
name: z6.string(),
|
|
2100
|
+
ready: z6.boolean(),
|
|
2101
|
+
/** False for a cordoned node. */
|
|
2102
|
+
schedulable: z6.boolean(),
|
|
2103
|
+
/** `control-plane` on the master, none on a node. */
|
|
2104
|
+
roles: z6.array(z6.string()),
|
|
2105
|
+
version: z6.string().nullable().optional(),
|
|
2106
|
+
address: z6.string().optional(),
|
|
2107
|
+
/** Bound persistent volumes kept on this node's own disk: what removing the node would lose. */
|
|
2108
|
+
volumes: z6.number().int(),
|
|
2109
|
+
/** Those volumes by their claim, `namespace/name` (k3s image v0.1.2 and later). */
|
|
2110
|
+
claims: z6.array(z6.string()).optional()
|
|
2111
|
+
});
|
|
2112
|
+
var ClusterHealthSchema = z6.object({
|
|
2113
|
+
/** The master has set itself up and the API answers. */
|
|
2114
|
+
ready: z6.boolean(),
|
|
2115
|
+
/** Traefik runs: the cluster answers on ports 80 and 443. */
|
|
2116
|
+
ingress: z6.boolean(),
|
|
2117
|
+
/** k3s's own version: `v1.37.2+k3s1`. */
|
|
2118
|
+
version: z6.string().optional(),
|
|
2119
|
+
nodes: z6.array(ClusterNodeSchema)
|
|
2120
|
+
});
|
|
2121
|
+
var ClusterPoolSchema = z6.object({
|
|
2122
|
+
name: z6.string(),
|
|
2123
|
+
size: z6.enum(NODE_SIZES),
|
|
2124
|
+
/** How many nodes it is meant to have; 0 for a pool that is being removed. */
|
|
2125
|
+
nodes: z6.number().int(),
|
|
2126
|
+
/** The boxes that are its nodes, by name; a box's name is its node's name in the cluster. */
|
|
2127
|
+
boxes: z6.array(z6.string())
|
|
2128
|
+
});
|
|
2129
|
+
var ClusterSchema = z6.object({
|
|
2130
|
+
name: z6.string(),
|
|
2131
|
+
/** The owning slug, bare. */
|
|
2132
|
+
owner: z6.string(),
|
|
2133
|
+
ownerKind: z6.enum(["user", "org"]),
|
|
2134
|
+
/** The master's: `running`, `stopped`, `hibernated` or `standby` (out of credit), `unknown` (its host does not answer). */
|
|
2135
|
+
status: BoxStatusSchema,
|
|
2136
|
+
/** The Kubernetes version it was made with: `1.37`. */
|
|
2137
|
+
version: z6.string(),
|
|
2138
|
+
/** Where kubectl reaches the API, null when the port is not open. The port is the cluster's for its whole life. */
|
|
2139
|
+
api: z6.object({ host: z6.string(), port: z6.number().int() }).nullable(),
|
|
2140
|
+
/** The one host all of it runs on. */
|
|
2141
|
+
host: z6.string(),
|
|
2142
|
+
country: z6.string().optional(),
|
|
2143
|
+
createdBy: z6.string().nullable(),
|
|
2144
|
+
createdAt: z6.string(),
|
|
2145
|
+
/** Its node pools; none on a cluster from before pools, whose master runs nothing of its owner's. */
|
|
2146
|
+
pools: z6.array(ClusterPoolSchema).default([]),
|
|
2147
|
+
/** What a month of it costs: its master, its nodes as they are now, and both together. */
|
|
2148
|
+
price: ClusterPriceSchema,
|
|
2149
|
+
/**
|
|
2150
|
+
* Only in `GET /k8s/<name>`: how many more nodes of each size its host can take right now, as the host
|
|
2151
|
+
* last reported its room (nothing is reserved: another box may take it first); null when the host is not answering.
|
|
2152
|
+
*/
|
|
2153
|
+
room: z6.object({ s: z6.number().int(), m: z6.number().int(), l: z6.number().int() }).nullable().optional(),
|
|
2154
|
+
/**
|
|
2155
|
+
* What is changing it right now (one thing at a time); absent when nothing is. `since` is the lease's last
|
|
2156
|
+
* stamp, renewed while the change goes on: when it was last seen alive, not when it began.
|
|
2157
|
+
*/
|
|
2158
|
+
operation: z6.object({ what: z6.string(), since: z6.string() }).optional(),
|
|
2159
|
+
/**
|
|
2160
|
+
* What the last change could not do after its request was answered (a node that would not drain, a new
|
|
2161
|
+
* node that never joined), in words; gone when the next change starts.
|
|
2162
|
+
*/
|
|
2163
|
+
operationError: z6.string().optional(),
|
|
2164
|
+
/**
|
|
2165
|
+
* Only in `GET /k8s/<name>`: the HTTPS addresses that reach its Traefik (#219), the `kvbox.app` names it
|
|
2166
|
+
* claimed and its custom domains that are live. None until one is claimed or added.
|
|
2167
|
+
*/
|
|
2168
|
+
addresses: z6.array(z6.string()).optional(),
|
|
2169
|
+
/** Only in `GET /k8s/<name>` (asked live): null when the master is not running or did not answer. */
|
|
2170
|
+
health: ClusterHealthSchema.nullable().optional(),
|
|
2171
|
+
/**
|
|
2172
|
+
* When the cluster's state is backed up on its own (#221): nightly from its creation, included in its
|
|
2173
|
+
* price. Null for one whose create stopped before its schedule was written (the backup job gives it one).
|
|
2174
|
+
*/
|
|
2175
|
+
backupSchedule: BackupScheduleSchema.nullable().optional()
|
|
2176
|
+
});
|
|
2177
|
+
var ClusterRestoreSchema = z6.object({
|
|
2178
|
+
backup: z6.string(),
|
|
2179
|
+
cluster: ClusterSchema,
|
|
2180
|
+
nodes: z6.object({
|
|
2181
|
+
/** Nodes the backup knew whose boxes were removed since: taken out of the cluster's list again. */
|
|
2182
|
+
forgotten: z6.array(z6.string()),
|
|
2183
|
+
/** Nodes made since the backup, which it does not know: their boxes were restarted so they join again. */
|
|
2184
|
+
restarted: z6.array(z6.string())
|
|
2185
|
+
}),
|
|
2186
|
+
/** False when the master did not answer after the restore, so its nodes were not compared with the cluster's boxes. */
|
|
2187
|
+
checked: z6.boolean(),
|
|
2188
|
+
/** What could not be put right, in words. */
|
|
2189
|
+
warnings: z6.array(z6.string())
|
|
2190
|
+
});
|
|
2191
|
+
var KubeconfigSchema = z6.object({ kubeconfig: z6.string() });
|
|
2192
|
+
|
|
1783
2193
|
// src/client.ts
|
|
1784
2194
|
import { spawn } from "child_process";
|
|
1785
2195
|
import { openSync } from "fs";
|
|
@@ -1788,21 +2198,21 @@ import { setTimeout as sleep2 } from "timers/promises";
|
|
|
1788
2198
|
import { Agent, request } from "undici";
|
|
1789
2199
|
|
|
1790
2200
|
// ../sdk/src/machines.ts
|
|
1791
|
-
import { z as
|
|
2201
|
+
import { z as z9 } from "zod";
|
|
1792
2202
|
|
|
1793
2203
|
// ../shared/src/resources.ts
|
|
1794
|
-
import { z as
|
|
2204
|
+
import { z as z7 } from "zod";
|
|
1795
2205
|
var RESOURCE_SLOT_MS = 5 * 6e4;
|
|
1796
2206
|
var RESOURCE_KEEP_DAYS = 7;
|
|
1797
2207
|
var RESOURCE_KEEP_MS = RESOURCE_KEEP_DAYS * 864e5;
|
|
1798
|
-
var whole =
|
|
1799
|
-
var pct =
|
|
2208
|
+
var whole = z7.number().int().nonnegative();
|
|
2209
|
+
var pct = z7.number().min(0).max(100);
|
|
1800
2210
|
var small = whole.max(2 ** 31 - 1);
|
|
1801
|
-
var ResourceSlotRowSchema =
|
|
2211
|
+
var ResourceSlotRowSchema = z7.object({
|
|
1802
2212
|
/** The host's box id. */
|
|
1803
|
-
boxId:
|
|
1804
|
-
owner:
|
|
1805
|
-
name:
|
|
2213
|
+
boxId: z7.string(),
|
|
2214
|
+
owner: z7.string(),
|
|
2215
|
+
name: z7.string(),
|
|
1806
2216
|
/** The slot's start, ms since the epoch. */
|
|
1807
2217
|
slot: whole,
|
|
1808
2218
|
vcpu: small,
|
|
@@ -1818,11 +2228,11 @@ var ResourceSlotRowSchema = z4.object({
|
|
|
1818
2228
|
netInBytes: whole,
|
|
1819
2229
|
netOutBytes: whole
|
|
1820
2230
|
});
|
|
1821
|
-
var ResourceSlotsResponseSchema =
|
|
1822
|
-
slots:
|
|
2231
|
+
var ResourceSlotsResponseSchema = z7.object({
|
|
2232
|
+
slots: z7.array(ResourceSlotRowSchema),
|
|
1823
2233
|
next: whole
|
|
1824
2234
|
});
|
|
1825
|
-
var ResourceSlotsPageSchema =
|
|
2235
|
+
var ResourceSlotsPageSchema = z7.object({ slots: z7.array(z7.unknown()), next: whole });
|
|
1826
2236
|
var figures = {
|
|
1827
2237
|
/** Average and busiest minute, percent of the box's vCPUs; null when the CPU was not measured. */
|
|
1828
2238
|
cpuPct: pct.nullable(),
|
|
@@ -1837,27 +2247,27 @@ var figures = {
|
|
|
1837
2247
|
netInBytes: whole,
|
|
1838
2248
|
netOutBytes: whole
|
|
1839
2249
|
};
|
|
1840
|
-
var ResourcePointSchema =
|
|
1841
|
-
var ResourceReportSchema =
|
|
1842
|
-
box:
|
|
1843
|
-
owner:
|
|
1844
|
-
since:
|
|
1845
|
-
until:
|
|
1846
|
-
stepMin:
|
|
2250
|
+
var ResourcePointSchema = z7.object({ at: z7.string(), ...figures });
|
|
2251
|
+
var ResourceReportSchema = z7.object({
|
|
2252
|
+
box: z7.string(),
|
|
2253
|
+
owner: z7.string(),
|
|
2254
|
+
since: z7.string(),
|
|
2255
|
+
until: z7.string(),
|
|
2256
|
+
stepMin: z7.number().int().positive(),
|
|
1847
2257
|
/** The box's vCPUs as last measured; null without a row. */
|
|
1848
2258
|
vcpu: whole.nullable(),
|
|
1849
|
-
totals:
|
|
1850
|
-
points:
|
|
2259
|
+
totals: z7.object(figures),
|
|
2260
|
+
points: z7.array(ResourcePointSchema)
|
|
1851
2261
|
});
|
|
1852
2262
|
|
|
1853
2263
|
// ../shared/src/traffic.ts
|
|
1854
|
-
import { z as
|
|
2264
|
+
import { z as z8 } from "zod";
|
|
1855
2265
|
var TRAFFIC_SLOT_MS = 5 * 6e4;
|
|
1856
2266
|
var TRAFFIC_KEEP_DAYS = 7;
|
|
1857
2267
|
var TRAFFIC_KEEP_MS = TRAFFIC_KEEP_DAYS * 864e5;
|
|
1858
2268
|
var LATENCY_BUCKETS_MS = [5, 10, 25, 50, 100, 250, 500, 1e3, 2500, 5e3, 1e4, 3e4];
|
|
1859
2269
|
var LATENCY_BUCKET_COUNT = LATENCY_BUCKETS_MS.length + 1;
|
|
1860
|
-
var count =
|
|
2270
|
+
var count = z8.number().int().nonnegative();
|
|
1861
2271
|
var figures2 = {
|
|
1862
2272
|
requests: count,
|
|
1863
2273
|
s2xx: count,
|
|
@@ -1873,28 +2283,28 @@ var figures2 = {
|
|
|
1873
2283
|
p50Ms: count.nullable(),
|
|
1874
2284
|
p95Ms: count.nullable()
|
|
1875
2285
|
};
|
|
1876
|
-
var TrafficPointSchema =
|
|
1877
|
-
var TrafficReportSchema =
|
|
1878
|
-
box:
|
|
1879
|
-
owner:
|
|
1880
|
-
since:
|
|
1881
|
-
until:
|
|
1882
|
-
stepMin:
|
|
2286
|
+
var TrafficPointSchema = z8.object({ at: z8.string(), ...figures2 });
|
|
2287
|
+
var TrafficReportSchema = z8.object({
|
|
2288
|
+
box: z8.string(),
|
|
2289
|
+
owner: z8.string(),
|
|
2290
|
+
since: z8.string(),
|
|
2291
|
+
until: z8.string(),
|
|
2292
|
+
stepMin: z8.number().int().positive(),
|
|
1883
2293
|
/** The one host name asked for; null for all of the box's. */
|
|
1884
|
-
host:
|
|
2294
|
+
host: z8.string().nullable(),
|
|
1885
2295
|
/** Every host name of the box with traffic in the range, whatever `host` is: what a filter can offer. */
|
|
1886
|
-
hosts:
|
|
1887
|
-
totals:
|
|
1888
|
-
points:
|
|
2296
|
+
hosts: z8.array(z8.string()),
|
|
2297
|
+
totals: z8.object(figures2),
|
|
2298
|
+
points: z8.array(TrafficPointSchema)
|
|
1889
2299
|
});
|
|
1890
|
-
var BoxTrafficSchema =
|
|
1891
|
-
var TrafficOverviewSchema =
|
|
1892
|
-
since:
|
|
1893
|
-
until:
|
|
1894
|
-
stepMin:
|
|
1895
|
-
totals:
|
|
1896
|
-
points:
|
|
1897
|
-
boxes:
|
|
2300
|
+
var BoxTrafficSchema = z8.object({ box: z8.string(), owner: z8.string(), ...figures2 });
|
|
2301
|
+
var TrafficOverviewSchema = z8.object({
|
|
2302
|
+
since: z8.string(),
|
|
2303
|
+
until: z8.string(),
|
|
2304
|
+
stepMin: z8.number().int().positive(),
|
|
2305
|
+
totals: z8.object(figures2),
|
|
2306
|
+
points: z8.array(TrafficPointSchema),
|
|
2307
|
+
boxes: z8.array(BoxTrafficSchema)
|
|
1898
2308
|
});
|
|
1899
2309
|
|
|
1900
2310
|
// ../sdk/src/errors.ts
|
|
@@ -2007,7 +2417,7 @@ var Machines = class {
|
|
|
2007
2417
|
ports;
|
|
2008
2418
|
/** Every box the caller can read (their own and their orgs'), sorted by owner then name. */
|
|
2009
2419
|
list(opts = {}) {
|
|
2010
|
-
return this.transport.request("GET", `/machines${listQuery(opts)}`,
|
|
2420
|
+
return this.transport.request("GET", `/machines${listQuery(opts)}`, z9.array(MachineSchema), { org: opts.org });
|
|
2011
2421
|
}
|
|
2012
2422
|
/**
|
|
2013
2423
|
* One box, found in the listing (the API has no route for a single box). `slug/name` looks in that
|
|
@@ -2021,7 +2431,7 @@ var Machines = class {
|
|
|
2021
2431
|
async find(name, orgOpt, timeoutMs) {
|
|
2022
2432
|
const slash = name.indexOf("/");
|
|
2023
2433
|
const [org, bare] = slash === -1 ? [orgOpt, name] : [name.slice(0, slash), name.slice(slash + 1)];
|
|
2024
|
-
const listing = await this.transport.request("GET", "/machines",
|
|
2434
|
+
const listing = await this.transport.request("GET", "/machines", z9.array(MachineSchema), { org, timeoutMs });
|
|
2025
2435
|
const named = listing.filter((m) => m.name === bare && (slash === -1 || slugOf2(m.owner) === org));
|
|
2026
2436
|
if (named.length <= 1) {
|
|
2027
2437
|
if (named[0] !== void 0) return named[0];
|
|
@@ -2055,7 +2465,7 @@ var Machines = class {
|
|
|
2055
2465
|
}
|
|
2056
2466
|
/** Remove the box and its disk. */
|
|
2057
2467
|
async remove(name, opts = {}) {
|
|
2058
|
-
await this.transport.request("DELETE", box(name),
|
|
2468
|
+
await this.transport.request("DELETE", box(name), z9.undefined(), { org: opts.org });
|
|
2059
2469
|
}
|
|
2060
2470
|
/** Boot a stopped box. */
|
|
2061
2471
|
start(name, opts = {}) {
|
|
@@ -2240,7 +2650,7 @@ var slugOf2 = (owner) => {
|
|
|
2240
2650
|
};
|
|
2241
2651
|
|
|
2242
2652
|
// ../sdk/src/snapshots.ts
|
|
2243
|
-
import { z as
|
|
2653
|
+
import { z as z10 } from "zod";
|
|
2244
2654
|
var Snapshots = class {
|
|
2245
2655
|
constructor(transport) {
|
|
2246
2656
|
this.transport = transport;
|
|
@@ -2248,19 +2658,19 @@ var Snapshots = class {
|
|
|
2248
2658
|
transport;
|
|
2249
2659
|
/** Every snapshot the caller can read. */
|
|
2250
2660
|
list(opts = {}) {
|
|
2251
|
-
return this.transport.request("GET", `/snapshots${listQuery(opts)}`,
|
|
2661
|
+
return this.transport.request("GET", `/snapshots${listQuery(opts)}`, z10.array(SnapshotSchema), { org: opts.org });
|
|
2252
2662
|
}
|
|
2253
2663
|
/** Snapshot box `req.box` as `req.name` (`replace`: retake one that exists). The box is paused while it is taken. */
|
|
2254
2664
|
create(req, opts = {}) {
|
|
2255
2665
|
return this.transport.request("POST", "/snapshots", SnapshotSchema, { body: req, org: opts.org });
|
|
2256
2666
|
}
|
|
2257
2667
|
async remove(name, opts = {}) {
|
|
2258
|
-
await this.transport.request("DELETE", `/snapshots/${encodeURIComponent(name)}`,
|
|
2668
|
+
await this.transport.request("DELETE", `/snapshots/${encodeURIComponent(name)}`, z10.undefined(), { org: opts.org });
|
|
2259
2669
|
}
|
|
2260
2670
|
};
|
|
2261
2671
|
|
|
2262
2672
|
// ../sdk/src/transport.ts
|
|
2263
|
-
import { z as
|
|
2673
|
+
import { z as z11 } from "zod";
|
|
2264
2674
|
var Transport = class {
|
|
2265
2675
|
baseUrl;
|
|
2266
2676
|
org;
|
|
@@ -2334,7 +2744,7 @@ var Transport = class {
|
|
|
2334
2744
|
}
|
|
2335
2745
|
}
|
|
2336
2746
|
};
|
|
2337
|
-
var LooseApiErrorSchema =
|
|
2747
|
+
var LooseApiErrorSchema = z11.object({ error: z11.string(), code: z11.string().optional() });
|
|
2338
2748
|
function safeJson(text2) {
|
|
2339
2749
|
try {
|
|
2340
2750
|
return JSON.parse(text2);
|
|
@@ -2364,7 +2774,7 @@ var Hooks = class {
|
|
|
2364
2774
|
};
|
|
2365
2775
|
|
|
2366
2776
|
// ../sdk/src/integrations.ts
|
|
2367
|
-
import { z as
|
|
2777
|
+
import { z as z12 } from "zod";
|
|
2368
2778
|
var Integrations = class {
|
|
2369
2779
|
constructor(transport) {
|
|
2370
2780
|
this.transport = transport;
|
|
@@ -2372,12 +2782,12 @@ var Integrations = class {
|
|
|
2372
2782
|
transport;
|
|
2373
2783
|
/** Each readable slug's state for each integration (`org`: one org's), connected or not; never a credential. */
|
|
2374
2784
|
list(opts = {}) {
|
|
2375
|
-
return this.transport.request("GET", "/integrations",
|
|
2785
|
+
return this.transport.request("GET", "/integrations", z12.array(IntegrationSchema), { org: opts.org });
|
|
2376
2786
|
}
|
|
2377
2787
|
};
|
|
2378
2788
|
|
|
2379
2789
|
// ../sdk/src/volumes.ts
|
|
2380
|
-
import { z as
|
|
2790
|
+
import { z as z13 } from "zod";
|
|
2381
2791
|
var volume = (name, rest = "") => `/volumes/${encodeURIComponent(name)}${rest}`;
|
|
2382
2792
|
var Volumes = class {
|
|
2383
2793
|
constructor(transport) {
|
|
@@ -2385,7 +2795,7 @@ var Volumes = class {
|
|
|
2385
2795
|
}
|
|
2386
2796
|
transport;
|
|
2387
2797
|
list(opts = {}) {
|
|
2388
|
-
return this.transport.request("GET", `/volumes${listQuery(opts)}`,
|
|
2798
|
+
return this.transport.request("GET", `/volumes${listQuery(opts)}`, z13.array(VolumeSchema), { org: opts.org });
|
|
2389
2799
|
}
|
|
2390
2800
|
/**
|
|
2391
2801
|
* Make a volume of `sizeGib` GiB. Through the cloud `box` is required: the volume is made on that
|
|
@@ -2408,7 +2818,7 @@ var Volumes = class {
|
|
|
2408
2818
|
}
|
|
2409
2819
|
/** Remove the volume and its data; it must be detached first. */
|
|
2410
2820
|
async remove(name, opts = {}) {
|
|
2411
|
-
await this.transport.request("DELETE", volume(name),
|
|
2821
|
+
await this.transport.request("DELETE", volume(name), z13.undefined(), { org: opts.org });
|
|
2412
2822
|
}
|
|
2413
2823
|
};
|
|
2414
2824
|
|
|
@@ -2460,382 +2870,201 @@ var Kvbox = class {
|
|
|
2460
2870
|
};
|
|
2461
2871
|
|
|
2462
2872
|
// src/client.ts
|
|
2463
|
-
import { z as
|
|
2873
|
+
import { z as z16 } from "zod";
|
|
2464
2874
|
|
|
2465
|
-
// ../shared/src/
|
|
2466
|
-
import { z as
|
|
2467
|
-
var
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
/** The cron service (#190): an hour of one cron service existing, whatever it holds or fires. A price list from before it charges nothing. */
|
|
2484
|
-
cronHour: z11.number().nonnegative().default(0),
|
|
2485
|
-
/**
|
|
2486
|
-
* One backup a person starts, of anything, charged once it is ready (decision "A backup taken by hand
|
|
2487
|
-
* costs a flat price…"); a failed one costs nothing. A price list from before it charges nothing.
|
|
2488
|
-
*/
|
|
2489
|
-
backup: z11.number().nonnegative().default(0),
|
|
2490
|
-
/**
|
|
2491
|
-
* One nightly backup of a box, a volume or the object storage, charged once it is ready (decision "A nightly
|
|
2492
|
-
* backup you switch on is charged…"): their switch is off until someone turns it on. A managed database's
|
|
2493
|
-
* nightly backup, on from its creation, is included in its price. A price list from before it charges nothing.
|
|
2494
|
-
*/
|
|
2495
|
-
scheduledBackup: z11.number().nonnegative().default(0)
|
|
2875
|
+
// ../shared/src/cron.ts
|
|
2876
|
+
import { z as z14 } from "zod";
|
|
2877
|
+
var DEFAULT_CRON_COMMAND_TIMEOUT_SEC = 600;
|
|
2878
|
+
var MAX_CRON_COMMAND_TIMEOUT_SEC = 3600;
|
|
2879
|
+
var CRON_RUN_LOG_DIR = "/var/log/kvbox/runs";
|
|
2880
|
+
var CRON_METHODS = ["GET", "POST"];
|
|
2881
|
+
var CRON_OUTCOMES = ["running", "ok", "failed", "timeout", "no-credit", "box-stopped", "host-down", "host-outdated", "lost", "still-running", "box-outdated"];
|
|
2882
|
+
var CronServiceSchema = z14.object({
|
|
2883
|
+
owner: z14.string(),
|
|
2884
|
+
ownerKind: z14.enum(["user", "org"]),
|
|
2885
|
+
name: z14.string(),
|
|
2886
|
+
/** Runs kept per trigger. */
|
|
2887
|
+
keepRuns: z14.number().int(),
|
|
2888
|
+
triggers: z14.number().int(),
|
|
2889
|
+
createdBy: z14.string().nullable(),
|
|
2890
|
+
createdAt: z14.string(),
|
|
2891
|
+
/** What it costs while it exists; on the answer to `POST /cron` only. */
|
|
2892
|
+
price: z14.object({ perMonth: z14.number(), currency: z14.string() }).optional()
|
|
2496
2893
|
});
|
|
2497
|
-
var
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
// ../shared/src/managed.ts
|
|
2525
|
-
import { z as z12 } from "zod";
|
|
2526
|
-
var PriceSchema = z12.object({ perMonth: z12.number(), storagePerMonth: z12.number(), currency: z12.string() });
|
|
2527
|
-
var ManagedCatalogEntrySchema = z12.object({
|
|
2528
|
-
/** The kind, as in `/managed/<kind>`: `postgres`. */
|
|
2529
|
-
kind: z12.string(),
|
|
2530
|
-
/** The CLI command for it: `pg` (`kvbox pg create …`). */
|
|
2531
|
-
command: z12.string(),
|
|
2532
|
-
title: z12.string(),
|
|
2533
|
-
description: z12.string(),
|
|
2534
|
-
/** The version a new one runs, as shown: `18`. */
|
|
2535
|
-
version: z12.string(),
|
|
2536
|
-
/** The port a linked box reaches it on. */
|
|
2537
|
-
port: z12.number().int(),
|
|
2538
|
-
/** The port `public on` opens behind a host port: `port` again unless the kind serves TLS on another. */
|
|
2539
|
-
publicPort: z12.number().int(),
|
|
2540
|
-
/** Its guide, as a URL. */
|
|
2541
|
-
docs: z12.string().optional(),
|
|
2542
|
-
storage: z12.object({ defaultGib: z12.number().int(), minGib: z12.number().int(), maxGib: z12.number().int() }),
|
|
2543
|
-
/**
|
|
2544
|
-
* What create takes of this kind alone, beside what every kind takes (name, password, storage, near): a
|
|
2545
|
-
* flag and a form field each, all optional, `default` in words.
|
|
2546
|
-
*/
|
|
2547
|
-
options: z12.array(z12.object({ name: z12.string(), title: z12.string(), description: z12.string(), default: z12.string() })),
|
|
2548
|
-
/** A month of it running with the default storage, and each further GB of storage. */
|
|
2549
|
-
price: PriceSchema.extend({ storageGibPerMonth: z12.number() }),
|
|
2550
|
-
/** Whether a host answering now can run it. */
|
|
2551
|
-
available: z12.boolean()
|
|
2894
|
+
var triggerCommon = {
|
|
2895
|
+
id: z14.string(),
|
|
2896
|
+
service: z14.string(),
|
|
2897
|
+
owner: z14.string(),
|
|
2898
|
+
/** The box it acts on; a trigger is removed with its box. */
|
|
2899
|
+
box: z14.string(),
|
|
2900
|
+
/** Five fields, `minute hour day-of-month month day-of-week`. */
|
|
2901
|
+
expr: z14.string(),
|
|
2902
|
+
/** An IANA zone (`Europe/Bucharest`) the expression is read in; `UTC` unless said. */
|
|
2903
|
+
timezone: z14.string(),
|
|
2904
|
+
/** False: paused, it fires again when resumed. */
|
|
2905
|
+
enabled: z14.boolean(),
|
|
2906
|
+
/** When it fires next (ISO); null while paused. */
|
|
2907
|
+
nextRunAt: z14.string().nullable(),
|
|
2908
|
+
lastRunAt: z14.string().nullable(),
|
|
2909
|
+
lastOutcome: z14.enum(CRON_OUTCOMES).nullable(),
|
|
2910
|
+
createdBy: z14.string().nullable(),
|
|
2911
|
+
createdAt: z14.string()
|
|
2912
|
+
};
|
|
2913
|
+
var CronHttpTriggerSchema = z14.object({
|
|
2914
|
+
...triggerCommon,
|
|
2915
|
+
kind: z14.literal("http"),
|
|
2916
|
+
method: z14.enum(CRON_METHODS),
|
|
2917
|
+
port: z14.number().int(),
|
|
2918
|
+
/** Path and query, starting with `/`. */
|
|
2919
|
+
path: z14.string()
|
|
2552
2920
|
});
|
|
2553
|
-
var
|
|
2554
|
-
name: z12.string(),
|
|
2555
|
-
/** The kind's own options by name (its catalog entry lists them); the kind checks them. */
|
|
2556
|
-
options: z12.record(z12.string(), z12.string()).optional(),
|
|
2557
|
-
password: z12.string().optional(),
|
|
2558
|
-
storageGib: z12.number().int().optional(),
|
|
2559
|
-
/** Place it on the host of this box, so the box can be linked to it. */
|
|
2560
|
-
near: z12.string().optional(),
|
|
2561
|
-
/**
|
|
2562
|
-
* A backup of a database of the same kind and major version, of the same account (#186): the new
|
|
2563
|
-
* service starts on its data, a removed service's included. Its settings (Postgres: database, user)
|
|
2564
|
-
* are the backup's; the password is the new one.
|
|
2565
|
-
*/
|
|
2566
|
-
fromBackup: z12.string().optional()
|
|
2567
|
-
});
|
|
2568
|
-
var ManagedHealthSchema = z12.object({
|
|
2569
|
-
/** Its first start has finished: it has set itself up on its storage. */
|
|
2570
|
-
ready: z12.boolean(),
|
|
2571
|
-
/** It accepts connections. */
|
|
2572
|
-
accepting: z12.boolean(),
|
|
2573
|
-
version: z12.string(),
|
|
2574
|
-
/** The storage volume: what is used of it and its size. */
|
|
2575
|
-
storageUsedBytes: z12.number().optional(),
|
|
2576
|
-
storageTotalBytes: z12.number().optional(),
|
|
2577
|
-
/** What else the kind reports, ready to show: `{title: "Connections", value: "3"}`. */
|
|
2578
|
-
facts: z12.array(z12.object({ title: z12.string(), value: z12.string() }))
|
|
2579
|
-
});
|
|
2580
|
-
var UrlsSchema = z12.object({ private: z12.string(), public: z12.string().optional() });
|
|
2581
|
-
var ManagedSchema = z12.object({
|
|
2582
|
-
kind: z12.string(),
|
|
2583
|
-
name: z12.string(),
|
|
2584
|
-
/** The owning slug, bare. */
|
|
2585
|
-
owner: z12.string(),
|
|
2586
|
-
ownerKind: z12.enum(["user", "org"]),
|
|
2587
|
-
/** `running`, `stopped` (storage only is charged), `hibernated` or `standby` (out of credit), `unknown` (its host does not answer). */
|
|
2588
|
-
status: BoxStatusSchema,
|
|
2589
|
-
/** The catalog version: `18`. */
|
|
2590
|
-
version: z12.string(),
|
|
2591
|
-
/** What the kind keeps of its create options, defaults filled in: `{database, user}` for Postgres, `{}` for a kind with none. */
|
|
2592
|
-
settings: z12.record(z12.string(), z12.string()),
|
|
2593
|
-
storageGib: z12.number().int(),
|
|
2594
|
-
/** Where a linked box reaches it: `<name>.<slug>.kvbox` (resolves from a box of any slug it is linked to) and the port. */
|
|
2595
|
-
private: z12.object({ host: z12.string(), port: z12.number().int() }),
|
|
2596
|
-
/** Where the internet reaches it, null while it is not public. The port is its own for its whole life. */
|
|
2597
|
-
public: z12.object({ host: z12.string(), port: z12.number().int() }).nullable(),
|
|
2598
|
-
/** The boxes linked to it, as the caller would name them. */
|
|
2599
|
-
links: z12.array(z12.string()),
|
|
2600
|
-
/** The name of the host it runs on, for `--near` and links. */
|
|
2601
|
-
host: z12.string(),
|
|
2602
|
-
country: z12.string().optional(),
|
|
2603
|
-
createdBy: z12.string().nullable(),
|
|
2604
|
-
createdAt: z12.string(),
|
|
2605
|
-
/** Connection strings with the password as `****`. */
|
|
2606
|
-
urls: UrlsSchema,
|
|
2607
|
-
price: PriceSchema,
|
|
2608
|
-
/** Its nightly backup (#186 slice 4): on from creation, `kvbox <kind> backup schedule` changes it. Null for a control plane from before schedules. */
|
|
2609
|
-
backupSchedule: BackupScheduleSchema.nullable().default(null),
|
|
2610
|
-
/** Only in `GET /managed/<kind>/<name>` (asked live): null when it is not running or did not answer. */
|
|
2611
|
-
health: ManagedHealthSchema.nullable().optional()
|
|
2612
|
-
});
|
|
2613
|
-
var ManagedSecretSchema = z12.object({ password: z12.string(), urls: UrlsSchema });
|
|
2614
|
-
var CreatedManagedSchema = ManagedSchema.extend({
|
|
2615
|
-
secret: ManagedSecretSchema,
|
|
2616
|
-
/** The backup it was made from (`fromBackup`), when it was. */
|
|
2617
|
-
fromBackup: z12.string().optional()
|
|
2618
|
-
});
|
|
2619
|
-
var ResetPasswordRequest = z12.object({ password: z12.string().optional() });
|
|
2620
|
-
var SetPublicRequest = z12.object({ on: z12.boolean() });
|
|
2621
|
-
var ManagedLinkRequest = z12.object({ box: z12.string() });
|
|
2622
|
-
var GrowManagedRequest = z12.object({ storageGib: z12.number().int() });
|
|
2623
|
-
var ManagedBackupSchema = z12.object({
|
|
2624
|
-
id: z12.string(),
|
|
2625
|
-
owner: z12.string(),
|
|
2626
|
-
kind: z12.string(),
|
|
2627
|
-
name: z12.string(),
|
|
2628
|
-
version: z12.string(),
|
|
2629
|
-
status: z12.enum(BACKUP_STATUSES),
|
|
2630
|
-
/** Why it failed; null otherwise. */
|
|
2631
|
-
error: z12.string().nullable(),
|
|
2632
|
-
/** The service's storage when taken. */
|
|
2633
|
-
diskBytes: z12.number().int().nullable(),
|
|
2634
|
-
/** What it holds: the slots that are not all zeros. */
|
|
2635
|
-
dataBytes: z12.number().int().nullable(),
|
|
2636
|
-
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
2637
|
-
uploadedBytes: z12.number().int().nullable(),
|
|
2638
|
-
/** Who asked for it; for a scheduled one, the database's creator. */
|
|
2639
|
-
createdBy: z12.string().nullable(),
|
|
2640
|
-
/** Started by the database's backup schedule, not by a person: it does not count toward the daily limit. */
|
|
2641
|
-
scheduled: z12.boolean().default(false),
|
|
2642
|
-
createdAt: z12.string(),
|
|
2643
|
-
finishedAt: z12.string().nullable()
|
|
2644
|
-
});
|
|
2645
|
-
|
|
2646
|
-
// ../shared/src/cron.ts
|
|
2647
|
-
import { z as z13 } from "zod";
|
|
2648
|
-
var DEFAULT_CRON_COMMAND_TIMEOUT_SEC = 600;
|
|
2649
|
-
var MAX_CRON_COMMAND_TIMEOUT_SEC = 3600;
|
|
2650
|
-
var CRON_RUN_LOG_DIR = "/var/log/kvbox/runs";
|
|
2651
|
-
var CRON_METHODS = ["GET", "POST"];
|
|
2652
|
-
var CRON_OUTCOMES = ["running", "ok", "failed", "timeout", "no-credit", "box-stopped", "host-down", "host-outdated", "lost", "still-running", "box-outdated"];
|
|
2653
|
-
var CronServiceSchema = z13.object({
|
|
2654
|
-
owner: z13.string(),
|
|
2655
|
-
ownerKind: z13.enum(["user", "org"]),
|
|
2656
|
-
name: z13.string(),
|
|
2657
|
-
/** Runs kept per trigger. */
|
|
2658
|
-
keepRuns: z13.number().int(),
|
|
2659
|
-
triggers: z13.number().int(),
|
|
2660
|
-
createdBy: z13.string().nullable(),
|
|
2661
|
-
createdAt: z13.string(),
|
|
2662
|
-
/** What it costs while it exists; on the answer to `POST /cron` only. */
|
|
2663
|
-
price: z13.object({ perMonth: z13.number(), currency: z13.string() }).optional()
|
|
2664
|
-
});
|
|
2665
|
-
var triggerCommon = {
|
|
2666
|
-
id: z13.string(),
|
|
2667
|
-
service: z13.string(),
|
|
2668
|
-
owner: z13.string(),
|
|
2669
|
-
/** The box it acts on; a trigger is removed with its box. */
|
|
2670
|
-
box: z13.string(),
|
|
2671
|
-
/** Five fields, `minute hour day-of-month month day-of-week`. */
|
|
2672
|
-
expr: z13.string(),
|
|
2673
|
-
/** An IANA zone (`Europe/Bucharest`) the expression is read in; `UTC` unless said. */
|
|
2674
|
-
timezone: z13.string(),
|
|
2675
|
-
/** False: paused, it fires again when resumed. */
|
|
2676
|
-
enabled: z13.boolean(),
|
|
2677
|
-
/** When it fires next (ISO); null while paused. */
|
|
2678
|
-
nextRunAt: z13.string().nullable(),
|
|
2679
|
-
lastRunAt: z13.string().nullable(),
|
|
2680
|
-
lastOutcome: z13.enum(CRON_OUTCOMES).nullable(),
|
|
2681
|
-
createdBy: z13.string().nullable(),
|
|
2682
|
-
createdAt: z13.string()
|
|
2683
|
-
};
|
|
2684
|
-
var CronHttpTriggerSchema = z13.object({
|
|
2685
|
-
...triggerCommon,
|
|
2686
|
-
kind: z13.literal("http"),
|
|
2687
|
-
method: z13.enum(CRON_METHODS),
|
|
2688
|
-
port: z13.number().int(),
|
|
2689
|
-
/** Path and query, starting with `/`. */
|
|
2690
|
-
path: z13.string()
|
|
2691
|
-
});
|
|
2692
|
-
var CronCommandTriggerSchema = z13.object({
|
|
2921
|
+
var CronCommandTriggerSchema = z14.object({
|
|
2693
2922
|
...triggerCommon,
|
|
2694
|
-
kind:
|
|
2923
|
+
kind: z14.literal("command"),
|
|
2695
2924
|
/** Run by a login shell as the box's user, in its home. */
|
|
2696
|
-
command:
|
|
2925
|
+
command: z14.string(),
|
|
2697
2926
|
/** The command is stopped after this long. */
|
|
2698
|
-
timeoutSec:
|
|
2927
|
+
timeoutSec: z14.number().int()
|
|
2699
2928
|
});
|
|
2700
|
-
var CronTriggerSchema =
|
|
2701
|
-
var CronRunSchema =
|
|
2929
|
+
var CronTriggerSchema = z14.discriminatedUnion("kind", [CronHttpTriggerSchema, CronCommandTriggerSchema]);
|
|
2930
|
+
var CronRunSchema = z14.object({
|
|
2702
2931
|
/** The slot this run was for (ISO); a run asked for by hand has the moment it was asked. */
|
|
2703
|
-
scheduledFor:
|
|
2704
|
-
startedAt:
|
|
2932
|
+
scheduledFor: z14.string(),
|
|
2933
|
+
startedAt: z14.string(),
|
|
2705
2934
|
/** Null while `running`, and for a run that was never sent. */
|
|
2706
|
-
durationMs:
|
|
2935
|
+
durationMs: z14.number().int().nullable(),
|
|
2707
2936
|
/** The box's HTTP status; null when it never answered, and for a command. */
|
|
2708
|
-
status:
|
|
2937
|
+
status: z14.number().int().nullable(),
|
|
2709
2938
|
/** A command's exit code (128 + the signal when one ended it); null until it ends, and for a request. */
|
|
2710
|
-
exitCode:
|
|
2939
|
+
exitCode: z14.number().int().nullable(),
|
|
2711
2940
|
/** The files in the box that hold what a command printed (a shell pattern, `cron-<n>.*`); null for a request and for a command that never started. */
|
|
2712
|
-
output:
|
|
2713
|
-
outcome:
|
|
2941
|
+
output: z14.string().nullable(),
|
|
2942
|
+
outcome: z14.enum(CRON_OUTCOMES),
|
|
2714
2943
|
/** Why it did not end `ok`, in a line. */
|
|
2715
|
-
error:
|
|
2944
|
+
error: z14.string().nullable(),
|
|
2716
2945
|
/** The box was hibernated and this run woke it. */
|
|
2717
|
-
woke:
|
|
2946
|
+
woke: z14.boolean()
|
|
2718
2947
|
});
|
|
2719
|
-
var CronCatalogSchema =
|
|
2720
|
-
price:
|
|
2721
|
-
maxServices:
|
|
2722
|
-
maxTriggers:
|
|
2723
|
-
keepRuns:
|
|
2948
|
+
var CronCatalogSchema = z14.object({
|
|
2949
|
+
price: z14.object({ perMonth: z14.number(), currency: z14.string() }),
|
|
2950
|
+
maxServices: z14.number().int(),
|
|
2951
|
+
maxTriggers: z14.number().int(),
|
|
2952
|
+
keepRuns: z14.number().int(),
|
|
2724
2953
|
/** The shortest time between two runs of one trigger, in seconds. */
|
|
2725
|
-
minIntervalSeconds:
|
|
2954
|
+
minIntervalSeconds: z14.number().int(),
|
|
2726
2955
|
/** How long a box has to answer, in seconds. */
|
|
2727
|
-
timeoutSeconds:
|
|
2956
|
+
timeoutSeconds: z14.number().int(),
|
|
2728
2957
|
/** How long a command may run: unless the trigger says, and at most. */
|
|
2729
|
-
commandTimeoutSeconds:
|
|
2730
|
-
maxCommandTimeoutSeconds:
|
|
2731
|
-
docs:
|
|
2732
|
-
});
|
|
2733
|
-
var CreateCronServiceRequest =
|
|
2734
|
-
var CreateCronTriggerRequest =
|
|
2735
|
-
box:
|
|
2736
|
-
expr:
|
|
2737
|
-
timezone:
|
|
2958
|
+
commandTimeoutSeconds: z14.number().int(),
|
|
2959
|
+
maxCommandTimeoutSeconds: z14.number().int(),
|
|
2960
|
+
docs: z14.string().optional()
|
|
2961
|
+
});
|
|
2962
|
+
var CreateCronServiceRequest = z14.object({ name: z14.string() });
|
|
2963
|
+
var CreateCronTriggerRequest = z14.object({
|
|
2964
|
+
box: z14.string().min(1),
|
|
2965
|
+
expr: z14.string().min(1),
|
|
2966
|
+
timezone: z14.string().optional(),
|
|
2738
2967
|
/** A request: `port`, with `method` and `path`. */
|
|
2739
|
-
method:
|
|
2740
|
-
port:
|
|
2741
|
-
path:
|
|
2968
|
+
method: z14.enum(CRON_METHODS).optional(),
|
|
2969
|
+
port: z14.number().int().min(1).max(65535).optional(),
|
|
2970
|
+
path: z14.string().optional(),
|
|
2742
2971
|
/** Or a command, with `timeoutSec`; exactly one of `port` and `command`. */
|
|
2743
|
-
command:
|
|
2744
|
-
timeoutSec:
|
|
2972
|
+
command: z14.string().optional(),
|
|
2973
|
+
timeoutSec: z14.number().int().optional()
|
|
2745
2974
|
});
|
|
2746
|
-
var UpdateCronTriggerRequest =
|
|
2975
|
+
var UpdateCronTriggerRequest = z14.object({ enabled: z14.boolean() });
|
|
2747
2976
|
var cronTarget = (t) => t.kind === "command" ? `${t.box}$ ${t.command}` : `${t.method} ${t.box}:${t.port}${t.path}`;
|
|
2748
2977
|
|
|
2749
2978
|
// ../shared/src/storage.ts
|
|
2750
|
-
import { z as
|
|
2751
|
-
var RegionSchema =
|
|
2979
|
+
import { z as z15 } from "zod";
|
|
2980
|
+
var RegionSchema = z15.object({ name: z15.string(), country: z15.string().nullable() });
|
|
2752
2981
|
var MAX_PUBLIC_BUCKETS = 10;
|
|
2753
2982
|
var STORAGE_BOX_SUBDOMAINS = MAX_PUBLIC_BUCKETS + 2;
|
|
2754
|
-
var ObjectStorageSchema =
|
|
2755
|
-
owner:
|
|
2756
|
-
ownerKind:
|
|
2983
|
+
var ObjectStorageSchema = z15.object({
|
|
2984
|
+
owner: z15.string(),
|
|
2985
|
+
ownerKind: z15.enum(["user", "org"]),
|
|
2757
2986
|
/** `https://s3-<slug>.<domain>`: what an S3 client is given, with path-style addressing. Null while the address is not claimed. */
|
|
2758
|
-
endpoint:
|
|
2987
|
+
endpoint: z15.string().nullable(),
|
|
2759
2988
|
/** The S3 region every client of it signs with (`ro-west-1`): its host's when it was made. */
|
|
2760
|
-
region:
|
|
2989
|
+
region: z15.string(),
|
|
2761
2990
|
/** The most it may hold. */
|
|
2762
|
-
sizeGib:
|
|
2991
|
+
sizeGib: z15.number().int(),
|
|
2763
2992
|
/** `running` when it answers; `unknown` while its host is not heard from. */
|
|
2764
2993
|
status: BoxStatusSchema,
|
|
2765
2994
|
/** With `?live=1`, when the storage answered: what is on its disk, and the disk's real size. */
|
|
2766
|
-
usedBytes:
|
|
2767
|
-
totalBytes:
|
|
2995
|
+
usedBytes: z15.number().optional(),
|
|
2996
|
+
totalBytes: z15.number().optional(),
|
|
2768
2997
|
/** With `?live=1`, when the storage answered: what each bucket holds. */
|
|
2769
|
-
bucketUsage:
|
|
2770
|
-
host:
|
|
2771
|
-
country:
|
|
2772
|
-
buckets:
|
|
2773
|
-
price:
|
|
2774
|
-
createdAt:
|
|
2775
|
-
});
|
|
2776
|
-
var BucketSchema =
|
|
2777
|
-
name:
|
|
2778
|
-
owner:
|
|
2779
|
-
ownerKind:
|
|
2780
|
-
endpoint:
|
|
2781
|
-
publicUrl:
|
|
2782
|
-
region:
|
|
2783
|
-
keys:
|
|
2784
|
-
objects:
|
|
2785
|
-
bytes:
|
|
2786
|
-
createdBy:
|
|
2787
|
-
createdAt:
|
|
2788
|
-
});
|
|
2789
|
-
var CreateBucketRequest =
|
|
2790
|
-
name:
|
|
2791
|
-
sizeGib:
|
|
2792
|
-
near:
|
|
2793
|
-
region:
|
|
2794
|
-
});
|
|
2795
|
-
var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated:
|
|
2998
|
+
bucketUsage: z15.array(z15.object({ name: z15.string(), objects: z15.number(), bytes: z15.number() })).optional(),
|
|
2999
|
+
host: z15.string(),
|
|
3000
|
+
country: z15.string().optional(),
|
|
3001
|
+
buckets: z15.number().int(),
|
|
3002
|
+
price: z15.object({ perMonth: z15.number(), currency: z15.string() }),
|
|
3003
|
+
createdAt: z15.string()
|
|
3004
|
+
});
|
|
3005
|
+
var BucketSchema = z15.object({
|
|
3006
|
+
name: z15.string(),
|
|
3007
|
+
owner: z15.string(),
|
|
3008
|
+
ownerKind: z15.enum(["user", "org"]),
|
|
3009
|
+
endpoint: z15.string().nullable(),
|
|
3010
|
+
publicUrl: z15.string().optional(),
|
|
3011
|
+
region: z15.string(),
|
|
3012
|
+
keys: z15.number().int(),
|
|
3013
|
+
objects: z15.number().optional(),
|
|
3014
|
+
bytes: z15.number().optional(),
|
|
3015
|
+
createdBy: z15.string().nullable(),
|
|
3016
|
+
createdAt: z15.string()
|
|
3017
|
+
});
|
|
3018
|
+
var CreateBucketRequest = z15.object({
|
|
3019
|
+
name: z15.string(),
|
|
3020
|
+
sizeGib: z15.number().int().optional(),
|
|
3021
|
+
near: z15.string().optional(),
|
|
3022
|
+
region: z15.string().optional()
|
|
3023
|
+
});
|
|
3024
|
+
var CreatedBucketSchema = BucketSchema.extend({ storage: ObjectStorageSchema, storageCreated: z15.boolean() });
|
|
2796
3025
|
var BucketInfoSchema = BucketSchema.extend({ storage: ObjectStorageSchema });
|
|
2797
|
-
var SetBucketPublicRequest =
|
|
2798
|
-
var BucketKeySchema =
|
|
2799
|
-
id:
|
|
2800
|
-
name:
|
|
2801
|
-
bucket:
|
|
2802
|
-
owner:
|
|
2803
|
-
readOnly:
|
|
2804
|
-
createdBy:
|
|
2805
|
-
createdAt:
|
|
2806
|
-
});
|
|
2807
|
-
var CreateBucketKeyRequest =
|
|
2808
|
-
var CreatedBucketKeySchema = BucketKeySchema.extend({ secret:
|
|
2809
|
-
var GrowStorageRequest =
|
|
2810
|
-
var StorageBackupSchema =
|
|
2811
|
-
id:
|
|
2812
|
-
owner:
|
|
2813
|
-
status:
|
|
3026
|
+
var SetBucketPublicRequest = z15.object({ on: z15.boolean(), sub: z15.string().optional() });
|
|
3027
|
+
var BucketKeySchema = z15.object({
|
|
3028
|
+
id: z15.string(),
|
|
3029
|
+
name: z15.string(),
|
|
3030
|
+
bucket: z15.string(),
|
|
3031
|
+
owner: z15.string(),
|
|
3032
|
+
readOnly: z15.boolean(),
|
|
3033
|
+
createdBy: z15.string().nullable(),
|
|
3034
|
+
createdAt: z15.string()
|
|
3035
|
+
});
|
|
3036
|
+
var CreateBucketKeyRequest = z15.object({ name: z15.string().optional(), readOnly: z15.boolean().optional() });
|
|
3037
|
+
var CreatedBucketKeySchema = BucketKeySchema.extend({ secret: z15.string(), endpoint: z15.string().nullable(), region: z15.string() });
|
|
3038
|
+
var GrowStorageRequest = z15.object({ sizeGib: z15.number().int() });
|
|
3039
|
+
var StorageBackupSchema = z15.object({
|
|
3040
|
+
id: z15.string(),
|
|
3041
|
+
owner: z15.string(),
|
|
3042
|
+
status: z15.enum(BACKUP_STATUSES),
|
|
2814
3043
|
/** Why it failed; null otherwise. */
|
|
2815
|
-
error:
|
|
3044
|
+
error: z15.string().nullable(),
|
|
2816
3045
|
/** The storage's volume when taken. */
|
|
2817
|
-
diskBytes:
|
|
3046
|
+
diskBytes: z15.number().int().nullable(),
|
|
2818
3047
|
/** What it holds: the slots that are not all zeros. */
|
|
2819
|
-
dataBytes:
|
|
3048
|
+
dataBytes: z15.number().int().nullable(),
|
|
2820
3049
|
/** What this backup added to the backup store (encrypted, compressed). */
|
|
2821
|
-
uploadedBytes:
|
|
3050
|
+
uploadedBytes: z15.number().int().nullable(),
|
|
2822
3051
|
/** The buckets it holds, and how many access keys they had, as kvbox knew them when it was taken. */
|
|
2823
|
-
buckets:
|
|
2824
|
-
keys:
|
|
2825
|
-
createdBy:
|
|
3052
|
+
buckets: z15.array(z15.string()),
|
|
3053
|
+
keys: z15.number().int(),
|
|
3054
|
+
createdBy: z15.string().nullable(),
|
|
2826
3055
|
/** Taken by the storage's nightly schedule rather than by a person: free, and outside the daily limit. */
|
|
2827
|
-
scheduled:
|
|
2828
|
-
createdAt:
|
|
2829
|
-
finishedAt:
|
|
3056
|
+
scheduled: z15.boolean().default(false),
|
|
3057
|
+
createdAt: z15.string(),
|
|
3058
|
+
finishedAt: z15.string().nullable()
|
|
2830
3059
|
});
|
|
2831
|
-
var RestoredKeySchema =
|
|
2832
|
-
var StorageRestoreSchema =
|
|
2833
|
-
backup:
|
|
3060
|
+
var RestoredKeySchema = z15.object({ bucket: z15.string(), id: z15.string(), name: z15.string() });
|
|
3061
|
+
var StorageRestoreSchema = z15.object({
|
|
3062
|
+
backup: z15.string(),
|
|
2834
3063
|
storage: ObjectStorageSchema,
|
|
2835
|
-
buckets:
|
|
2836
|
-
keys:
|
|
2837
|
-
checked:
|
|
2838
|
-
warnings:
|
|
3064
|
+
buckets: z15.object({ kept: z15.array(z15.string()), returned: z15.array(z15.string()), removed: z15.array(z15.string()) }),
|
|
3065
|
+
keys: z15.object({ dropped: z15.array(RestoredKeySchema), revoked: z15.array(RestoredKeySchema) }),
|
|
3066
|
+
checked: z15.boolean(),
|
|
3067
|
+
warnings: z15.array(z15.string())
|
|
2839
3068
|
});
|
|
2840
3069
|
var OBJECT_LIST_MAX = 1e3;
|
|
2841
3070
|
var SHARE_LINK_MAX_SEC = 7 * 24 * 3600;
|
|
@@ -2845,56 +3074,56 @@ var MULTIPART_PART_BYTES = 16 * 1024 * 1024;
|
|
|
2845
3074
|
var UPLOAD_MAX_BYTES = 50 * 1024 * 1024 * 1024;
|
|
2846
3075
|
var MOVE_MAX_BYTES = 5 * 1024 * 1024 * 1024;
|
|
2847
3076
|
var DELETE_PREFIXES_MAX = 100;
|
|
2848
|
-
var StoredObjectSchema =
|
|
2849
|
-
key:
|
|
2850
|
-
size:
|
|
2851
|
-
etag:
|
|
3077
|
+
var StoredObjectSchema = z15.object({
|
|
3078
|
+
key: z15.string(),
|
|
3079
|
+
size: z15.number(),
|
|
3080
|
+
etag: z15.string(),
|
|
2852
3081
|
/** ISO 8601. */
|
|
2853
|
-
modified:
|
|
2854
|
-
});
|
|
2855
|
-
var ObjectListingSchema =
|
|
2856
|
-
prefix:
|
|
2857
|
-
folders:
|
|
2858
|
-
objects:
|
|
2859
|
-
next:
|
|
2860
|
-
canWrite:
|
|
2861
|
-
});
|
|
2862
|
-
var ObjectInfoSchema = StoredObjectSchema.extend({ contentType:
|
|
2863
|
-
var ObjectCountSchema =
|
|
2864
|
-
var ObjectLinkRequest =
|
|
2865
|
-
key:
|
|
2866
|
-
expiresSec:
|
|
3082
|
+
modified: z15.string()
|
|
3083
|
+
});
|
|
3084
|
+
var ObjectListingSchema = z15.object({
|
|
3085
|
+
prefix: z15.string(),
|
|
3086
|
+
folders: z15.array(z15.string()),
|
|
3087
|
+
objects: z15.array(StoredObjectSchema),
|
|
3088
|
+
next: z15.string().optional(),
|
|
3089
|
+
canWrite: z15.boolean()
|
|
3090
|
+
});
|
|
3091
|
+
var ObjectInfoSchema = StoredObjectSchema.extend({ contentType: z15.string() });
|
|
3092
|
+
var ObjectCountSchema = z15.object({ objects: z15.number(), bytes: z15.number(), more: z15.boolean() });
|
|
3093
|
+
var ObjectLinkRequest = z15.object({
|
|
3094
|
+
key: z15.string(),
|
|
3095
|
+
expiresSec: z15.number().int().positive(),
|
|
2867
3096
|
/** Answer as a download (`Content-Disposition: attachment`) instead of showing it. */
|
|
2868
|
-
download:
|
|
3097
|
+
download: z15.boolean().optional(),
|
|
2869
3098
|
/**
|
|
2870
3099
|
* Let the browser keep what the link answers until the link expires (`Cache-Control: private`, `Expires`),
|
|
2871
3100
|
* so the same link shown twice is fetched once. Asked again within the hour, for the same file as it
|
|
2872
3101
|
* is, it is the same URL, and it lasts up to an hour longer than `expiresSec`. For the app's own previews.
|
|
2873
3102
|
* Only a fetch of the whole file is kept so: the storage answers a part of one (`Range`) without the two headers.
|
|
2874
3103
|
*/
|
|
2875
|
-
cached:
|
|
3104
|
+
cached: z15.boolean().optional()
|
|
2876
3105
|
});
|
|
2877
|
-
var ObjectLinkSchema =
|
|
3106
|
+
var ObjectLinkSchema = z15.object({ url: z15.string(), expiresAt: z15.string() });
|
|
2878
3107
|
var MEDIA_TYPE_RE = /^[\w.+-]+\/[\w.+-]+(?:\s*;[\x20-\x7e]*)?$/;
|
|
2879
|
-
var StartUploadRequest =
|
|
2880
|
-
var UploadPlanSchema =
|
|
2881
|
-
|
|
2882
|
-
|
|
3108
|
+
var StartUploadRequest = z15.object({ key: z15.string(), size: z15.number().int().nonnegative(), contentType: z15.string().max(200).regex(MEDIA_TYPE_RE, "not a media type like image/png").optional(), overwrite: z15.boolean().optional() });
|
|
3109
|
+
var UploadPlanSchema = z15.discriminatedUnion("kind", [
|
|
3110
|
+
z15.object({ kind: z15.literal("single"), url: z15.string() }),
|
|
3111
|
+
z15.object({ kind: z15.literal("multipart"), uploadId: z15.string(), partSize: z15.number(), urls: z15.array(z15.string()) })
|
|
2883
3112
|
]);
|
|
2884
|
-
var CompleteUploadRequest =
|
|
2885
|
-
key:
|
|
2886
|
-
uploadId:
|
|
2887
|
-
parts:
|
|
3113
|
+
var CompleteUploadRequest = z15.object({
|
|
3114
|
+
key: z15.string(),
|
|
3115
|
+
uploadId: z15.string(),
|
|
3116
|
+
parts: z15.array(z15.object({ part: z15.number().int().positive(), etag: z15.string() })).min(1)
|
|
2888
3117
|
});
|
|
2889
|
-
var AbortUploadRequest =
|
|
2890
|
-
var DeleteObjectsRequest =
|
|
2891
|
-
var DeletedObjectsSchema =
|
|
2892
|
-
deleted:
|
|
2893
|
-
more:
|
|
2894
|
-
errors:
|
|
3118
|
+
var AbortUploadRequest = z15.object({ key: z15.string(), uploadId: z15.string() });
|
|
3119
|
+
var DeleteObjectsRequest = z15.object({ keys: z15.array(z15.string()).max(OBJECT_LIST_MAX).optional(), prefixes: z15.array(z15.string()).max(DELETE_PREFIXES_MAX).optional() });
|
|
3120
|
+
var DeletedObjectsSchema = z15.object({
|
|
3121
|
+
deleted: z15.number(),
|
|
3122
|
+
more: z15.boolean(),
|
|
3123
|
+
errors: z15.array(z15.object({ key: z15.string(), message: z15.string() }))
|
|
2895
3124
|
});
|
|
2896
|
-
var MoveObjectRequest =
|
|
2897
|
-
var CreateFolderRequest =
|
|
3125
|
+
var MoveObjectRequest = z15.object({ from: z15.string(), to: z15.string(), overwrite: z15.boolean().optional() });
|
|
3126
|
+
var CreateFolderRequest = z15.object({ prefix: z15.string() });
|
|
2898
3127
|
|
|
2899
3128
|
// src/kvm.ts
|
|
2900
3129
|
import { accessSync, constants, readFileSync, statSync } from "fs";
|
|
@@ -3064,7 +3293,7 @@ var ServerClient = class {
|
|
|
3064
3293
|
* `all`: every box on the platform (platform admins only, #78).
|
|
3065
3294
|
*/
|
|
3066
3295
|
listMachines(opts = {}) {
|
|
3067
|
-
return this.call("GET", `/machines${allQuery(opts)}`,
|
|
3296
|
+
return this.call("GET", `/machines${allQuery(opts)}`, z16.array(MachineSchema), void 0, opts.org);
|
|
3068
3297
|
}
|
|
3069
3298
|
createMachine(req) {
|
|
3070
3299
|
return this.call("POST", "/machines", MachineSchema, req, void 0, req.fromBackup !== void 0 ? 2 * 36e5 : void 0);
|
|
@@ -3122,10 +3351,10 @@ var ServerClient = class {
|
|
|
3122
3351
|
}
|
|
3123
3352
|
/** Backups, the control plane's only: a box's disk in object storage. Newest first. */
|
|
3124
3353
|
listBackups() {
|
|
3125
|
-
return this.call("GET", "/backups",
|
|
3354
|
+
return this.call("GET", "/backups", z16.array(BackupSchema));
|
|
3126
3355
|
}
|
|
3127
3356
|
boxBackups(name) {
|
|
3128
|
-
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`,
|
|
3357
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups`, z16.array(BackupSchema));
|
|
3129
3358
|
}
|
|
3130
3359
|
boxBackup(name, id) {
|
|
3131
3360
|
return this.call("GET", `/machines/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, BackupSchema);
|
|
@@ -3147,14 +3376,14 @@ var ServerClient = class {
|
|
|
3147
3376
|
* later. Works for a backup whose box, volume or database is gone too.
|
|
3148
3377
|
*/
|
|
3149
3378
|
removeBackup(id) {
|
|
3150
|
-
return this.call("DELETE", `/backups/${encodeURIComponent(id)}`,
|
|
3379
|
+
return this.call("DELETE", `/backups/${encodeURIComponent(id)}`, z16.undefined());
|
|
3151
3380
|
}
|
|
3152
3381
|
/** A volume's backups (#168): the same as a box's, of the volume's disk. Newest first. */
|
|
3153
3382
|
listVolumeBackups() {
|
|
3154
|
-
return this.call("GET", "/backups?kind=volume",
|
|
3383
|
+
return this.call("GET", "/backups?kind=volume", z16.array(VolumeBackupSchema));
|
|
3155
3384
|
}
|
|
3156
3385
|
volumeBackups(name) {
|
|
3157
|
-
return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`,
|
|
3386
|
+
return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups`, z16.array(VolumeBackupSchema));
|
|
3158
3387
|
}
|
|
3159
3388
|
volumeBackup(name, id) {
|
|
3160
3389
|
return this.call("GET", `/volumes/${encodeURIComponent(name)}/backups/${encodeURIComponent(id)}`, VolumeBackupSchema);
|
|
@@ -3180,7 +3409,7 @@ var ServerClient = class {
|
|
|
3180
3409
|
}
|
|
3181
3410
|
/** Wake hooks (#101), the control plane's only: a URL and a secret that wake the box. */
|
|
3182
3411
|
boxHooks(name) {
|
|
3183
|
-
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`,
|
|
3412
|
+
return this.call("GET", `/machines/${encodeURIComponent(name)}/hooks`, z16.array(WakeHookSchema));
|
|
3184
3413
|
}
|
|
3185
3414
|
createBoxHook(name) {
|
|
3186
3415
|
return this.call("POST", `/machines/${encodeURIComponent(name)}/hooks`, CreatedWakeHookSchema);
|
|
@@ -3208,7 +3437,7 @@ var ServerClient = class {
|
|
|
3208
3437
|
}
|
|
3209
3438
|
/** Every readable box's subdomains, one entry each. */
|
|
3210
3439
|
listSubdomains() {
|
|
3211
|
-
return this.call("GET", "/subdomains",
|
|
3440
|
+
return this.call("GET", "/subdomains", z16.array(SubdomainSchema));
|
|
3212
3441
|
}
|
|
3213
3442
|
/** Custom domains (#89), the control plane's only: serve the box at the user's own name. */
|
|
3214
3443
|
addDomain(name, req) {
|
|
@@ -3219,7 +3448,7 @@ var ServerClient = class {
|
|
|
3219
3448
|
}
|
|
3220
3449
|
/** Every readable box's custom domains. */
|
|
3221
3450
|
listDomains() {
|
|
3222
|
-
return this.call("GET", "/domains",
|
|
3451
|
+
return this.call("GET", "/domains", z16.array(DomainSchema));
|
|
3223
3452
|
}
|
|
3224
3453
|
/** A running box's own load, memory and disk, asked of its guest (#67). */
|
|
3225
3454
|
machineStats(name) {
|
|
@@ -3260,22 +3489,22 @@ var ServerClient = class {
|
|
|
3260
3489
|
return this.call("POST", "/billing/redeem", RedeemResponseSchema, { code });
|
|
3261
3490
|
}
|
|
3262
3491
|
deleteMachine(name) {
|
|
3263
|
-
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`,
|
|
3492
|
+
return this.call("DELETE", `/machines/${encodeURIComponent(name)}`, z16.undefined());
|
|
3264
3493
|
}
|
|
3265
3494
|
/** Like `listMachines`, for snapshots. */
|
|
3266
3495
|
listSnapshots(opts = {}) {
|
|
3267
|
-
return this.call("GET", `/snapshots${allQuery(opts)}`,
|
|
3496
|
+
return this.call("GET", `/snapshots${allQuery(opts)}`, z16.array(SnapshotSchema), void 0, opts.org);
|
|
3268
3497
|
}
|
|
3269
3498
|
createSnapshot(req) {
|
|
3270
3499
|
return this.call("POST", "/snapshots", SnapshotSchema, req);
|
|
3271
3500
|
}
|
|
3272
3501
|
deleteSnapshot(name) {
|
|
3273
|
-
return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`,
|
|
3502
|
+
return this.call("DELETE", `/snapshots/${encodeURIComponent(name)}`, z16.undefined());
|
|
3274
3503
|
}
|
|
3275
3504
|
// ---- environment variables (#88), a control plane only: the caller's slug, or `--org`'s ----
|
|
3276
3505
|
/** `org`: that org's list instead of `--org`'s (or the caller's own). */
|
|
3277
3506
|
listEnv(org) {
|
|
3278
|
-
return this.call("GET", "/vars",
|
|
3507
|
+
return this.call("GET", "/vars", z16.array(EnvVarSchema), void 0, org);
|
|
3279
3508
|
}
|
|
3280
3509
|
setEnv(name, req) {
|
|
3281
3510
|
return this.call("PUT", `/vars/${encodeURIComponent(name)}`, EnvChangeSchema, req);
|
|
@@ -3295,13 +3524,13 @@ var ServerClient = class {
|
|
|
3295
3524
|
}
|
|
3296
3525
|
// ---- volumes (#52) ----
|
|
3297
3526
|
listVolumes(opts = {}) {
|
|
3298
|
-
return this.call("GET", `/volumes${allQuery(opts)}`,
|
|
3527
|
+
return this.call("GET", `/volumes${allQuery(opts)}`, z16.array(VolumeSchema), void 0, opts.org);
|
|
3299
3528
|
}
|
|
3300
3529
|
createVolume(req) {
|
|
3301
3530
|
return this.call("POST", "/volumes", VolumeSchema, req);
|
|
3302
3531
|
}
|
|
3303
3532
|
deleteVolume(name) {
|
|
3304
|
-
return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`,
|
|
3533
|
+
return this.call("DELETE", `/volumes/${encodeURIComponent(name)}`, z16.undefined());
|
|
3305
3534
|
}
|
|
3306
3535
|
/** Both answer with the box as it is afterwards (restarted when it was running). */
|
|
3307
3536
|
attachVolume(name, req) {
|
|
@@ -3316,7 +3545,7 @@ var ServerClient = class {
|
|
|
3316
3545
|
}
|
|
3317
3546
|
// ---- cron service (#190): the control plane's alone ----
|
|
3318
3547
|
listCronServices(opts = {}) {
|
|
3319
|
-
return this.call("GET", `/cron${allQuery(opts)}`,
|
|
3548
|
+
return this.call("GET", `/cron${allQuery(opts)}`, z16.array(CronServiceSchema), void 0, opts.org);
|
|
3320
3549
|
}
|
|
3321
3550
|
createCronService(name) {
|
|
3322
3551
|
return this.call("POST", "/cron", CronServiceSchema, { name });
|
|
@@ -3325,10 +3554,10 @@ var ServerClient = class {
|
|
|
3325
3554
|
return this.call("GET", `/cron/${encodeURIComponent(name)}`, CronServiceSchema);
|
|
3326
3555
|
}
|
|
3327
3556
|
deleteCronService(name) {
|
|
3328
|
-
return this.call("DELETE", `/cron/${encodeURIComponent(name)}`,
|
|
3557
|
+
return this.call("DELETE", `/cron/${encodeURIComponent(name)}`, z16.undefined());
|
|
3329
3558
|
}
|
|
3330
3559
|
listCronTriggers(service) {
|
|
3331
|
-
return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers`,
|
|
3560
|
+
return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers`, z16.array(CronTriggerSchema));
|
|
3332
3561
|
}
|
|
3333
3562
|
addCronTrigger(service, req) {
|
|
3334
3563
|
return this.call("POST", `/cron/${encodeURIComponent(service)}/triggers`, CronTriggerSchema, req);
|
|
@@ -3338,18 +3567,111 @@ var ServerClient = class {
|
|
|
3338
3567
|
return this.call("PATCH", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`, CronTriggerSchema, { enabled: enabled2 });
|
|
3339
3568
|
}
|
|
3340
3569
|
deleteCronTrigger(service, id) {
|
|
3341
|
-
return this.call("DELETE", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`,
|
|
3570
|
+
return this.call("DELETE", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}`, z16.undefined());
|
|
3342
3571
|
}
|
|
3343
3572
|
/** Marks it due: kvbox-cron fires it within a few seconds. */
|
|
3344
3573
|
runCronTrigger(service, id) {
|
|
3345
3574
|
return this.call("POST", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/run`, CronTriggerSchema);
|
|
3346
3575
|
}
|
|
3347
3576
|
listCronRuns(service, id, limit) {
|
|
3348
|
-
return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/runs${limit === void 0 ? "" : `?limit=${limit}`}`,
|
|
3577
|
+
return this.call("GET", `/cron/${encodeURIComponent(service)}/triggers/${encodeURIComponent(id)}/runs${limit === void 0 ? "" : `?limit=${limit}`}`, z16.array(CronRunSchema));
|
|
3578
|
+
}
|
|
3579
|
+
// ---- Kubernetes clusters (#216): the control plane's alone ----
|
|
3580
|
+
listClusters(opts = {}) {
|
|
3581
|
+
return this.call("GET", `/k8s${allQuery(opts)}`, z16.array(ClusterSchema), void 0, opts.org);
|
|
3582
|
+
}
|
|
3583
|
+
/** The master boots twice (its volume is attached after it is made), so this may take a minute. */
|
|
3584
|
+
createCluster(req) {
|
|
3585
|
+
return this.call("POST", "/k8s", ClusterSchema, req);
|
|
3586
|
+
}
|
|
3587
|
+
getCluster(name) {
|
|
3588
|
+
return this.call("GET", `/k8s/${encodeURIComponent(name)}`, ClusterSchema);
|
|
3589
|
+
}
|
|
3590
|
+
getKubeconfig(name) {
|
|
3591
|
+
return this.call("GET", `/k8s/${encodeURIComponent(name)}/kubeconfig`, KubeconfigSchema);
|
|
3592
|
+
}
|
|
3593
|
+
/** Wakes, resumes or starts the master, whichever its host says it needs. */
|
|
3594
|
+
startCluster(name) {
|
|
3595
|
+
return this.call("POST", `/k8s/${encodeURIComponent(name)}/start`, ClusterSchema);
|
|
3596
|
+
}
|
|
3597
|
+
/** One more pool with its nodes (#217): each node is a box the host makes, so a few seconds a node. */
|
|
3598
|
+
addPool(cluster, req) {
|
|
3599
|
+
return this.call("POST", `/k8s/${encodeURIComponent(cluster)}/pools`, ClusterSchema, req);
|
|
3600
|
+
}
|
|
3601
|
+
/**
|
|
3602
|
+
* How many nodes a pool is meant to have; the missing ones are made. Fewer is only begun when this
|
|
3603
|
+
* answers (`operation`): the nodes are drained one by one; `force` removes them undrained.
|
|
3604
|
+
*/
|
|
3605
|
+
resizePool(cluster, pool, nodes, force = false) {
|
|
3606
|
+
return this.call("PUT", `/k8s/${encodeURIComponent(cluster)}/pools/${encodeURIComponent(pool)}`, ClusterSchema, { nodes, ...force ? { force } : {} });
|
|
3607
|
+
}
|
|
3608
|
+
/** A pool with its nodes, drained first like a shrink: begun when this answers, over when `operation` is gone. */
|
|
3609
|
+
removePool(cluster, pool, force = false) {
|
|
3610
|
+
return this.call("DELETE", `/k8s/${encodeURIComponent(cluster)}/pools/${encodeURIComponent(pool)}${force ? "?force=1" : ""}`, ClusterSchema);
|
|
3611
|
+
}
|
|
3612
|
+
/** A cluster's HTTPS addresses (#219): `kvbox.app` names and custom domains, all to its Traefik. */
|
|
3613
|
+
listClusterSubdomains(cluster) {
|
|
3614
|
+
return this.call("GET", `/k8s/${encodeURIComponent(cluster)}/subdomains`, z16.array(SubdomainSchema));
|
|
3615
|
+
}
|
|
3616
|
+
claimClusterSubdomain(cluster, name) {
|
|
3617
|
+
return this.call("POST", `/k8s/${encodeURIComponent(cluster)}/subdomains`, SubdomainSchema, { name });
|
|
3618
|
+
}
|
|
3619
|
+
releaseClusterSubdomain(cluster, name) {
|
|
3620
|
+
return this.call("DELETE", `/k8s/${encodeURIComponent(cluster)}/subdomains/${encodeURIComponent(name)}`, SubdomainSchema);
|
|
3621
|
+
}
|
|
3622
|
+
listClusterDomains(cluster) {
|
|
3623
|
+
return this.call("GET", `/k8s/${encodeURIComponent(cluster)}/domains`, z16.array(DomainSchema));
|
|
3624
|
+
}
|
|
3625
|
+
addClusterDomain(cluster, domain) {
|
|
3626
|
+
return this.call("POST", `/k8s/${encodeURIComponent(cluster)}/domains`, DomainSchema, { domain });
|
|
3627
|
+
}
|
|
3628
|
+
removeClusterDomain(cluster, domain) {
|
|
3629
|
+
return this.call("DELETE", `/k8s/${encodeURIComponent(cluster)}/domains/${encodeURIComponent(domain)}`, DomainSchema);
|
|
3630
|
+
}
|
|
3631
|
+
/** What a cluster reaches (#220): a database or a box, from every one of its boxes. */
|
|
3632
|
+
listClusterLinks(cluster) {
|
|
3633
|
+
return this.call("GET", `/k8s/${encodeURIComponent(cluster)}/links`, z16.array(ClusterLinkSchema));
|
|
3634
|
+
}
|
|
3635
|
+
linkCluster(cluster, req) {
|
|
3636
|
+
return this.call("POST", `/k8s/${encodeURIComponent(cluster)}/links`, ClusterLinkSchema, req);
|
|
3637
|
+
}
|
|
3638
|
+
unlinkCluster(cluster, req) {
|
|
3639
|
+
return this.call("DELETE", `/k8s/${encodeURIComponent(cluster)}/links`, ClusterLinkSchema, req);
|
|
3640
|
+
}
|
|
3641
|
+
/** A cluster's backups (#221): its master's state, by the engine a database's uses. Every cluster's, removed ones' too. */
|
|
3642
|
+
listClusterBackups() {
|
|
3643
|
+
return this.call("GET", "/backups?managed=k8s", z16.array(ManagedBackupSchema));
|
|
3644
|
+
}
|
|
3645
|
+
clusterBackups(cluster) {
|
|
3646
|
+
return this.call("GET", `/k8s/${encodeURIComponent(cluster)}/backups`, z16.array(ManagedBackupSchema));
|
|
3647
|
+
}
|
|
3648
|
+
clusterBackup(cluster, id) {
|
|
3649
|
+
return this.call("GET", `/k8s/${encodeURIComponent(cluster)}/backups/${encodeURIComponent(id)}`, ManagedBackupSchema);
|
|
3650
|
+
}
|
|
3651
|
+
/** Starts one; it runs in the background (`running`), `clusterBackup` says how it ended. */
|
|
3652
|
+
createClusterBackup(cluster) {
|
|
3653
|
+
return this.call("POST", `/k8s/${encodeURIComponent(cluster)}/backups`, ManagedBackupSchema);
|
|
3654
|
+
}
|
|
3655
|
+
/**
|
|
3656
|
+
* The cluster's state becomes the backup's; its master restarts. Waits for the whole download (the
|
|
3657
|
+
* control plane gives its host 2 h) and for the master to answer again (5 min more), so 2 h 10 min.
|
|
3658
|
+
*/
|
|
3659
|
+
restoreClusterBackup(cluster, id) {
|
|
3660
|
+
return this.call("POST", `/k8s/${encodeURIComponent(cluster)}/backups/${encodeURIComponent(id)}/restore`, ClusterRestoreSchema, {}, void 0, 2 * 36e5 + 10 * 6e4);
|
|
3661
|
+
}
|
|
3662
|
+
/** When the cluster's state is backed up on its own: nightly from its creation. */
|
|
3663
|
+
clusterBackupSchedule(cluster) {
|
|
3664
|
+
return this.call("GET", `/k8s/${encodeURIComponent(cluster)}/backup-schedule`, BackupScheduleSchema);
|
|
3665
|
+
}
|
|
3666
|
+
setClusterBackupSchedule(cluster, change) {
|
|
3667
|
+
return this.call("PUT", `/k8s/${encodeURIComponent(cluster)}/backup-schedule`, BackupScheduleSchema, change);
|
|
3668
|
+
}
|
|
3669
|
+
deleteCluster(name) {
|
|
3670
|
+
return this.call("DELETE", `/k8s/${encodeURIComponent(name)}`, z16.undefined());
|
|
3349
3671
|
}
|
|
3350
3672
|
// ---- object storage (#182): the control plane's alone ----
|
|
3351
3673
|
listBuckets(opts = {}) {
|
|
3352
|
-
return this.call("GET", `/buckets${allQuery(opts)}`,
|
|
3674
|
+
return this.call("GET", `/buckets${allQuery(opts)}`, z16.array(BucketSchema), void 0, opts.org);
|
|
3353
3675
|
}
|
|
3354
3676
|
/** The first bucket of a slug also makes its storage: a box boots twice, so this may take a couple of minutes. */
|
|
3355
3677
|
createBucket(req) {
|
|
@@ -3363,26 +3685,26 @@ var ServerClient = class {
|
|
|
3363
3685
|
return this.call("PUT", `/buckets/${encodeURIComponent(name)}/public`, BucketSchema, req);
|
|
3364
3686
|
}
|
|
3365
3687
|
deleteBucket(name, force = false) {
|
|
3366
|
-
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`,
|
|
3688
|
+
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}${force ? "?force=1" : ""}`, z16.undefined());
|
|
3367
3689
|
}
|
|
3368
3690
|
listBucketKeys(name) {
|
|
3369
|
-
return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`,
|
|
3691
|
+
return this.call("GET", `/buckets/${encodeURIComponent(name)}/keys`, z16.array(BucketKeySchema));
|
|
3370
3692
|
}
|
|
3371
3693
|
createBucketKey(name, req) {
|
|
3372
3694
|
return this.call("POST", `/buckets/${encodeURIComponent(name)}/keys`, CreatedBucketKeySchema, req);
|
|
3373
3695
|
}
|
|
3374
3696
|
deleteBucketKey(name, id) {
|
|
3375
|
-
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`,
|
|
3697
|
+
return this.call("DELETE", `/buckets/${encodeURIComponent(name)}/keys/${encodeURIComponent(id)}`, z16.undefined());
|
|
3376
3698
|
}
|
|
3377
3699
|
listStorage(opts = {}) {
|
|
3378
|
-
return this.call("GET", `/storage${allQuery(opts)}`,
|
|
3700
|
+
return this.call("GET", `/storage${allQuery(opts)}`, z16.array(ObjectStorageSchema), void 0, opts.org);
|
|
3379
3701
|
}
|
|
3380
3702
|
growStorage(sizeGib) {
|
|
3381
3703
|
return this.call("POST", "/storage/grow", ObjectStorageSchema, { sizeGib });
|
|
3382
3704
|
}
|
|
3383
3705
|
/** Backups of the slug's whole object storage (#186 slice 3), newest first. */
|
|
3384
3706
|
storageBackups() {
|
|
3385
|
-
return this.call("GET", "/storage/backups",
|
|
3707
|
+
return this.call("GET", "/storage/backups", z16.array(StorageBackupSchema));
|
|
3386
3708
|
}
|
|
3387
3709
|
storageBackup(id) {
|
|
3388
3710
|
return this.call("GET", `/storage/backups/${encodeURIComponent(id)}`, StorageBackupSchema);
|
|
@@ -3410,11 +3732,11 @@ var ServerClient = class {
|
|
|
3410
3732
|
return `/managed/${encodeURIComponent(kind)}${name === void 0 ? "" : `/${encodeURIComponent(name)}`}${rest}`;
|
|
3411
3733
|
}
|
|
3412
3734
|
managedCatalog() {
|
|
3413
|
-
return this.call("GET", "/managed/catalog",
|
|
3735
|
+
return this.call("GET", "/managed/catalog", z16.array(ManagedCatalogEntrySchema));
|
|
3414
3736
|
}
|
|
3415
3737
|
/** One kind's services, or every kind's when `kind` is left out. */
|
|
3416
3738
|
listManaged(kind, opts = {}) {
|
|
3417
|
-
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`,
|
|
3739
|
+
return this.call("GET", `${kind === void 0 ? "/managed" : this.managedPath(kind)}${allQuery(opts)}`, z16.array(ManagedSchema), void 0, opts.org);
|
|
3418
3740
|
}
|
|
3419
3741
|
/** From a backup (`fromBackup`) it waits for the restore too: the control plane gives its host 2 h for the download. */
|
|
3420
3742
|
createManaged(kind, req) {
|
|
@@ -3425,7 +3747,7 @@ var ServerClient = class {
|
|
|
3425
3747
|
return this.call("GET", this.managedPath(kind, name), ManagedSchema);
|
|
3426
3748
|
}
|
|
3427
3749
|
deleteManaged(kind, name) {
|
|
3428
|
-
return this.call("DELETE", this.managedPath(kind, name),
|
|
3750
|
+
return this.call("DELETE", this.managedPath(kind, name), z16.undefined());
|
|
3429
3751
|
}
|
|
3430
3752
|
managedPassword(kind, name) {
|
|
3431
3753
|
return this.call("GET", this.managedPath(kind, name, "/password"), ManagedSecretSchema);
|
|
@@ -3447,10 +3769,10 @@ var ServerClient = class {
|
|
|
3447
3769
|
}
|
|
3448
3770
|
/** A managed service's backups (#186): its storage's, by the volume backup engine. Every one of a kind, those of removed services too. */
|
|
3449
3771
|
listManagedBackups(kind) {
|
|
3450
|
-
return this.call("GET", `/backups?managed=${encodeURIComponent(kind)}`,
|
|
3772
|
+
return this.call("GET", `/backups?managed=${encodeURIComponent(kind)}`, z16.array(ManagedBackupSchema));
|
|
3451
3773
|
}
|
|
3452
3774
|
managedBackups(kind, name) {
|
|
3453
|
-
return this.call("GET", this.managedPath(kind, name, "/backups"),
|
|
3775
|
+
return this.call("GET", this.managedPath(kind, name, "/backups"), z16.array(ManagedBackupSchema));
|
|
3454
3776
|
}
|
|
3455
3777
|
managedBackup(kind, name, id) {
|
|
3456
3778
|
return this.call("GET", this.managedPath(kind, name, `/backups/${encodeURIComponent(id)}`), ManagedBackupSchema);
|
|
@@ -3492,7 +3814,7 @@ var ServerClient = class {
|
|
|
3492
3814
|
return this.call("POST", "/login/device/token", DeviceLoginPollSchema, { deviceCode });
|
|
3493
3815
|
}
|
|
3494
3816
|
logout() {
|
|
3495
|
-
return this.call("POST", "/logout",
|
|
3817
|
+
return this.call("POST", "/logout", z16.unknown()).then(() => void 0);
|
|
3496
3818
|
}
|
|
3497
3819
|
me() {
|
|
3498
3820
|
return this.call("GET", "/me", MeResponseSchema);
|
|
@@ -3503,25 +3825,25 @@ var ServerClient = class {
|
|
|
3503
3825
|
* credential. Null: each readable slug whatever `--org` says, which is how the caller's own slug is read.
|
|
3504
3826
|
*/
|
|
3505
3827
|
listIntegrations(org) {
|
|
3506
|
-
return this.call("GET", "/integrations",
|
|
3828
|
+
return this.call("GET", "/integrations", z16.array(IntegrationSchema), void 0, org);
|
|
3507
3829
|
}
|
|
3508
3830
|
/** What can be connected on this control plane, and by which kind of slug. */
|
|
3509
3831
|
integrationCatalog() {
|
|
3510
|
-
return this.call("GET", "/integrations/catalog",
|
|
3832
|
+
return this.call("GET", "/integrations/catalog", z16.array(IntegrationCatalogEntrySchema), void 0, null);
|
|
3511
3833
|
}
|
|
3512
3834
|
// ---- API keys (`kvbox key …`, #189) ----
|
|
3513
3835
|
listApiKeys() {
|
|
3514
|
-
return this.call("GET", "/keys",
|
|
3836
|
+
return this.call("GET", "/keys", z16.array(ApiKeySchema));
|
|
3515
3837
|
}
|
|
3516
3838
|
createApiKey(req) {
|
|
3517
3839
|
return this.call("POST", "/keys", CreatedApiKeySchema, req);
|
|
3518
3840
|
}
|
|
3519
3841
|
deleteApiKey(name) {
|
|
3520
|
-
return this.call("DELETE", `/keys/${encodeURIComponent(name)}`,
|
|
3842
|
+
return this.call("DELETE", `/keys/${encodeURIComponent(name)}`, z16.unknown()).then(() => void 0);
|
|
3521
3843
|
}
|
|
3522
3844
|
// ---- orgs (`kvbox org …`) ----
|
|
3523
3845
|
listOrgs() {
|
|
3524
|
-
return this.call("GET", "/orgs",
|
|
3846
|
+
return this.call("GET", "/orgs", z16.array(OrgMembershipSchema));
|
|
3525
3847
|
}
|
|
3526
3848
|
createOrg(req) {
|
|
3527
3849
|
return this.call("POST", "/orgs", CloudOrgSchema, req);
|
|
@@ -3530,16 +3852,16 @@ var ServerClient = class {
|
|
|
3530
3852
|
return this.call("GET", `/orgs/${encodeURIComponent(slug)}`, OrgDetailSchema);
|
|
3531
3853
|
}
|
|
3532
3854
|
deleteOrg(slug) {
|
|
3533
|
-
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`,
|
|
3855
|
+
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}`, z16.undefined());
|
|
3534
3856
|
}
|
|
3535
3857
|
addMember(slug, req) {
|
|
3536
|
-
return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`,
|
|
3858
|
+
return this.call("POST", `/orgs/${encodeURIComponent(slug)}/members`, z16.undefined(), req);
|
|
3537
3859
|
}
|
|
3538
3860
|
setRole(slug, username, role) {
|
|
3539
|
-
return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`,
|
|
3861
|
+
return this.call("PATCH", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z16.unknown(), { role }).then(() => void 0);
|
|
3540
3862
|
}
|
|
3541
3863
|
removeMember(slug, username) {
|
|
3542
|
-
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`,
|
|
3864
|
+
return this.call("DELETE", `/orgs/${encodeURIComponent(slug)}/members/${encodeURIComponent(username)}`, z16.undefined());
|
|
3543
3865
|
}
|
|
3544
3866
|
/** Sign this machine's key again (#51); the key must be one the user logged in with. */
|
|
3545
3867
|
sshCert(req) {
|
|
@@ -4304,16 +4626,16 @@ function scpArgs(ep, from, to, recursive) {
|
|
|
4304
4626
|
}
|
|
4305
4627
|
async function runScp(args) {
|
|
4306
4628
|
const child = spawn3("scp", args, { stdio: ["inherit", "inherit", "pipe"] });
|
|
4307
|
-
let
|
|
4629
|
+
let refused2 = false;
|
|
4308
4630
|
child.stderr?.on("data", (c2) => {
|
|
4309
4631
|
process.stderr.write(c2);
|
|
4310
|
-
if (c2.toString("utf8").includes("Permission denied"))
|
|
4632
|
+
if (c2.toString("utf8").includes("Permission denied")) refused2 = true;
|
|
4311
4633
|
});
|
|
4312
4634
|
const status2 = await new Promise((resolve4, reject) => {
|
|
4313
4635
|
child.once("error", (err) => reject(new KvboxError(`could not run scp: ${err.message}`)));
|
|
4314
4636
|
child.once("close", (code, signal) => resolve4(code ?? (signal === "SIGINT" ? 130 : 1)));
|
|
4315
4637
|
});
|
|
4316
|
-
return { status: status2, refused };
|
|
4638
|
+
return { status: status2, refused: refused2 };
|
|
4317
4639
|
}
|
|
4318
4640
|
var cpCommand = new Command4("cp").description("copy files between this machine and a box (kvbox cp ./f <box>:f, kvbox cp <box>:f .)").argument("<src>", "a local path, or <box>:<path>").argument("<dest>", "a local path, or <box>:<path>").option("-r, --recursive", "copy directories").option("--direct", "on the box's host: ssh to the box's private ip, not through the public address or relay").action(async (src, dest, opts, cmd) => {
|
|
4319
4641
|
const { box: box2, from, to } = parseCopy(src, dest);
|
|
@@ -4391,7 +4713,7 @@ var lsCommand = new Command6("ls").description("list boxes with status and addre
|
|
|
4391
4713
|
}
|
|
4392
4714
|
if (org !== void 0) info(`boxes of ${org}`);
|
|
4393
4715
|
table(lsRows(boxes, cloud ? { me: me(client), showHost: admin } : void 0));
|
|
4394
|
-
const behind = boxes.filter((b) => b.latestBase !== void 0 && b.managed === void 0);
|
|
4716
|
+
const behind = boxes.filter((b) => b.latestBase !== void 0 && b.managed === void 0 && b.cluster === void 0);
|
|
4395
4717
|
const asleep = behind.some((b) => b.status === "hibernated");
|
|
4396
4718
|
if (behind.length > 0) info(color.dim(`${behind.length === 1 ? "1 box runs" : `${behind.length} boxes run`} an older image (\u2192 in BASE): kvbox vm update <box> moves it onto the newer one, its files stay${asleep ? " (a hibernated box first: kvbox wake <box>)" : ""}`));
|
|
4397
4719
|
} finally {
|
|
@@ -4402,16 +4724,17 @@ var hostCell = (b) => b.host === void 0 ? "-" : b.country === void 0 ? b.host :
|
|
|
4402
4724
|
function lsRows(boxes, cloud) {
|
|
4403
4725
|
return boxes.map((b) => ({
|
|
4404
4726
|
...cloud ? { owner: ownerCell(b, cloud.me) } : {},
|
|
4405
|
-
// a managed service's or storage's box, which only a platform admin's --all lists: `s3-1a2b3c (storage)
|
|
4406
|
-
|
|
4727
|
+
// a managed service's or storage's box, which only a platform admin's --all lists: `s3-1a2b3c (storage)`;
|
|
4728
|
+
// a cluster's node (#218): `prod-a3f (node of prod)`
|
|
4729
|
+
name: `${boxName(b.name)}${b.managed !== void 0 ? ` ${color.dim(`(${b.managed})`)}` : b.cluster !== void 0 ? ` ${color.dim(`(node of ${b.cluster.name})`)}` : ""}`,
|
|
4407
4730
|
status: status(b.status),
|
|
4408
4731
|
...cloud?.showHost ? { host: hostCell(b) } : {},
|
|
4409
4732
|
address: addressOf(b),
|
|
4410
4733
|
size: b.status === "unknown" ? "-" : `${shape(b.vcpu, b.memMib, b.diskBytes)} ${color.dim(`(${gbShort(b.diskUsedBytes)} used)`)}`,
|
|
4411
4734
|
created: age(b.createdAt),
|
|
4412
4735
|
// An image other than the base one (#87) is named: `postgres v0.1.0`; a newer one on the host follows in yellow: `v0.12.0 → v0.16.0`
|
|
4413
|
-
// (not on a managed service's box, which `vm update` cannot reach).
|
|
4414
|
-
base: b.status === "unknown" || b.base === "" ? "-" : `${b.image !== void 0 ? `${b.image} ${b.base}` : b.base}${b.latestBase === void 0 || b.managed !== void 0 ? "" : color.yellow(` \u2192 ${b.latestBase}`)}`
|
|
4736
|
+
// (not on a managed service's box or a cluster's node, which `vm update` cannot reach).
|
|
4737
|
+
base: b.status === "unknown" || b.base === "" ? "-" : `${b.image !== void 0 ? `${b.image} ${b.base}` : b.base}${b.latestBase === void 0 || b.managed !== void 0 || b.cluster !== void 0 ? "" : color.yellow(` \u2192 ${b.latestBase}`)}`
|
|
4415
4738
|
}));
|
|
4416
4739
|
}
|
|
4417
4740
|
|
|
@@ -4480,6 +4803,7 @@ function getRows(box2, subs, user) {
|
|
|
4480
4803
|
["status", status(box2.status)]
|
|
4481
4804
|
];
|
|
4482
4805
|
if (user !== void 0) rows2.push(["owner", ownerCell(box2, user)]);
|
|
4806
|
+
if (box2.cluster !== void 0) rows2.push(["cluster", `node of ${box2.cluster.name}, pool ${box2.cluster.pool} ${color.dim(`(more or fewer nodes, the newest going first: kvbox k8s pool resize ${box2.cluster.name} ${box2.cluster.pool} --nodes <n>)`)}`]);
|
|
4483
4807
|
if (box2.status !== "unknown") {
|
|
4484
4808
|
rows2.push(["size", `${shape(box2.vcpu, box2.memMib, box2.diskBytes)} ${color.dim(`(${gb(box2.diskUsedBytes)} used)`)}`]);
|
|
4485
4809
|
rows2.push(["address", box2.ssh?.host ?? (box2.ip === "" ? "-" : box2.ip)]);
|
|
@@ -4496,7 +4820,7 @@ function getRows(box2, subs, user) {
|
|
|
4496
4820
|
if (!box2.autoHibernateSec && box2.idleCheck !== void 0) rows2.push(["idle check", `${box2.idleCheck} ${color.dim("(used once auto-hibernate is on)")}`]);
|
|
4497
4821
|
rows2.push(["integrations", box2.integrations?.length ? box2.integrations.join(", ") : "-"]);
|
|
4498
4822
|
rows2.push(["source", box2.source]);
|
|
4499
|
-
const update = box2.latestBase === void 0 ? "" : ` ${color.yellow(`(${box2.latestBase} available: ${box2.status === "hibernated" ? `kvbox wake ${displayName(box2, user)}, then ` : ""}kvbox vm update ${displayName(box2, user)})`)}`;
|
|
4823
|
+
const update = box2.latestBase === void 0 || box2.cluster !== void 0 ? "" : ` ${color.yellow(`(${box2.latestBase} available: ${box2.status === "hibernated" ? `kvbox wake ${displayName(box2, user)}, then ` : ""}kvbox vm update ${displayName(box2, user)})`)}`;
|
|
4500
4824
|
rows2.push(["base", `${box2.image === void 0 ? box2.base : `${box2.image} ${box2.base}`}${update}`]);
|
|
4501
4825
|
rows2.push(["created", `${age(box2.createdAt)} ${color.dim(`(${box2.createdAt})`)}`]);
|
|
4502
4826
|
if (box2.bootedAt !== void 0) rows2.push(["booted", `${age(box2.bootedAt)} ${color.dim(`(${box2.bootedAt})`)}`]);
|
|
@@ -6332,8 +6656,9 @@ var usageCommand2 = new Command64("usage").description("what your boxes and volu
|
|
|
6332
6656
|
const volumes = report.volumes ?? [];
|
|
6333
6657
|
const storage = report.storage ?? [];
|
|
6334
6658
|
const cron = report.cron ?? [];
|
|
6659
|
+
const clusters = report.clusters ?? [];
|
|
6335
6660
|
const backups = report.backups ?? [];
|
|
6336
|
-
if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0 && backups.length === 0) info("no usage in this window");
|
|
6661
|
+
if (report.boxes.length === 0 && volumes.length === 0 && storage.length === 0 && cron.length === 0 && clusters.length === 0 && backups.length === 0) info("no usage in this window");
|
|
6337
6662
|
else if (report.boxes.length > 0) table(perUser ? userRows(perUser) : usageRows(report, cloud));
|
|
6338
6663
|
if (volumes.length > 0) {
|
|
6339
6664
|
info(volumes.length === 1 ? "1 volume" : `${volumes.length} volumes`);
|
|
@@ -6347,13 +6672,17 @@ var usageCommand2 = new Command64("usage").description("what your boxes and volu
|
|
|
6347
6672
|
info(cron.length === 1 ? "1 cron service" : `${cron.length} cron services`);
|
|
6348
6673
|
table(cronRows(report, cloud));
|
|
6349
6674
|
}
|
|
6675
|
+
if (clusters.length > 0) {
|
|
6676
|
+
info(clusters.length === 1 ? "1 Kubernetes cluster" : `${clusters.length} Kubernetes clusters`);
|
|
6677
|
+
table(clusterRows(report, cloud));
|
|
6678
|
+
}
|
|
6350
6679
|
if (backups.length > 0) {
|
|
6351
6680
|
const taken = backups.reduce((n2, b) => n2 + b.count, 0);
|
|
6352
6681
|
info(taken === 1 ? "1 paid backup" : `${taken} paid backups`);
|
|
6353
6682
|
table(backupRows(report, cloud));
|
|
6354
6683
|
}
|
|
6355
|
-
if ((volumes.length > 0 || storage.length > 0 || cron.length > 0 || backups.length > 0) && report.totals.cost !== void 0) {
|
|
6356
|
-
const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : [], ...backups.length > 0 ? ["backups"] : []];
|
|
6684
|
+
if ((volumes.length > 0 || storage.length > 0 || cron.length > 0 || clusters.length > 0 || backups.length > 0) && report.totals.cost !== void 0) {
|
|
6685
|
+
const what = ["boxes", ...volumes.length > 0 ? ["volumes"] : [], ...storage.length > 0 ? ["object storage"] : [], ...cron.length > 0 ? ["cron services"] : [], ...clusters.length > 0 ? ["Kubernetes clusters"] : [], ...backups.length > 0 ? ["backups"] : []];
|
|
6357
6686
|
info(`total: ${money(report.totals.cost.amount, report.totals.cost.currency)} ${color.dim(`(${what.slice(0, -1).join(", ")} and ${what.at(-1)}, estimated)`)}`);
|
|
6358
6687
|
}
|
|
6359
6688
|
if (cloud) {
|
|
@@ -6456,6 +6785,38 @@ function cronRows(report, cloud) {
|
|
|
6456
6785
|
...priced ? { cost: money(s.cost?.amount ?? 0, currency) } : {}
|
|
6457
6786
|
}));
|
|
6458
6787
|
}
|
|
6788
|
+
function clusterRows(report, cloud) {
|
|
6789
|
+
const priced = report.totals.cost !== void 0;
|
|
6790
|
+
const currency = report.totals.cost?.currency ?? "";
|
|
6791
|
+
const cells = (t) => ({
|
|
6792
|
+
running: duration(t.seconds.running),
|
|
6793
|
+
"vcpu-h": hours(t.vcpuHours),
|
|
6794
|
+
"ram GiB-h": hours(t.ramGibHours),
|
|
6795
|
+
"disk GiB-h": hours(t.diskGibHours)
|
|
6796
|
+
});
|
|
6797
|
+
const blank = { running: "", "vcpu-h": "", "ram GiB-h": "", "disk GiB-h": "" };
|
|
6798
|
+
const gone = (removed, live) => removed ? color.dim("removed") : live;
|
|
6799
|
+
return (report.clusters ?? []).flatMap((c2) => [
|
|
6800
|
+
{
|
|
6801
|
+
...cloud ? { owner: ownerCell2(c2, cloud.me) } : {},
|
|
6802
|
+
cluster: boxName(c2.name),
|
|
6803
|
+
part: "master",
|
|
6804
|
+
status: gone(c2.status === "removed", "present"),
|
|
6805
|
+
...cells(c2.master),
|
|
6806
|
+
...priced ? { cost: money(c2.master.cost?.amount ?? 0, currency) } : {}
|
|
6807
|
+
},
|
|
6808
|
+
...c2.nodes.map((n2) => ({
|
|
6809
|
+
...cloud ? { owner: "" } : {},
|
|
6810
|
+
cluster: "",
|
|
6811
|
+
part: `${n2.name}${n2.pool === void 0 ? "" : color.dim(` (${n2.pool})`)}`,
|
|
6812
|
+
status: gone(n2.status === "removed", status(n2.status)),
|
|
6813
|
+
...cells(n2),
|
|
6814
|
+
...priced ? { cost: money(n2.cost?.amount ?? 0, currency) } : {}
|
|
6815
|
+
})),
|
|
6816
|
+
...c2.fee === void 0 ? [] : [{ ...cloud ? { owner: "" } : {}, cluster: "", part: "cluster price", status: "", ...blank, ...priced ? { cost: money(c2.fee.amount, currency) } : {} }],
|
|
6817
|
+
{ ...cloud ? { owner: "" } : {}, cluster: "", part: color.bold("total"), status: "", ...blank, ...priced ? { cost: money(c2.cost?.amount ?? 0, currency) } : {} }
|
|
6818
|
+
]);
|
|
6819
|
+
}
|
|
6459
6820
|
function backupRows(report, cloud) {
|
|
6460
6821
|
return (report.backups ?? []).map((b) => ({
|
|
6461
6822
|
name: b.kind === "storage" ? "object storage" : b.name,
|
|
@@ -6481,7 +6842,7 @@ function byUser(report) {
|
|
|
6481
6842
|
return u;
|
|
6482
6843
|
});
|
|
6483
6844
|
users.sort((a, b) => a.user === null ? 1 : b.user === null ? -1 : a.user.localeCompare(b.user));
|
|
6484
|
-
return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, ...report.cron === void 0 ? {} : { cron: report.cron }, ...report.backups === void 0 ? {} : { backups: report.backups }, totals: report.totals };
|
|
6845
|
+
return { window: report.window, users, ...report.volumes === void 0 ? {} : { volumes: report.volumes }, ...report.storage === void 0 ? {} : { storage: report.storage }, ...report.cron === void 0 ? {} : { cron: report.cron }, ...report.clusters === void 0 ? {} : { clusters: report.clusters }, ...report.backups === void 0 ? {} : { backups: report.backups }, totals: report.totals };
|
|
6485
6846
|
}
|
|
6486
6847
|
function userRows(r) {
|
|
6487
6848
|
const priced = r.totals.cost !== void 0;
|
|
@@ -6572,7 +6933,7 @@ import { Command as Command67, InvalidArgumentError as InvalidArgumentError2, Op
|
|
|
6572
6933
|
// src/commands/deploy/config.ts
|
|
6573
6934
|
import { readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
|
|
6574
6935
|
import { isAbsolute, join as join6, normalize, relative as relative2 } from "path";
|
|
6575
|
-
import { z as
|
|
6936
|
+
import { z as z17 } from "zod";
|
|
6576
6937
|
|
|
6577
6938
|
// src/commands/deploy/templates/docker.ts
|
|
6578
6939
|
import { readFile as readFile4 } from "fs/promises";
|
|
@@ -6996,21 +7357,21 @@ function detectTemplates(pkg, dir = NO_FACTS) {
|
|
|
6996
7357
|
var DEPLOY_AUTO_HIBERNATE_SEC = 3600;
|
|
6997
7358
|
var CONFIG_FILE = "kvbox.json";
|
|
6998
7359
|
var BOX_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
|
|
6999
|
-
var DeployConfigSchema =
|
|
7000
|
-
template:
|
|
7001
|
-
name:
|
|
7360
|
+
var DeployConfigSchema = z17.object({
|
|
7361
|
+
template: z17.enum(TEMPLATE_IDS),
|
|
7362
|
+
name: z17.string().regex(BOX_NAME_RE, "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit"),
|
|
7002
7363
|
/** The org whose box it is; absent for the user's own. */
|
|
7003
|
-
org:
|
|
7364
|
+
org: z17.string().regex(ORG_SLUG_RE, "not an org slug").optional(),
|
|
7004
7365
|
/** The HTTPS name (`<subdomain>.kvbox.app`); absent when deploying to this machine's own host. */
|
|
7005
|
-
subdomain:
|
|
7366
|
+
subdomain: z17.string().check((ctx) => {
|
|
7006
7367
|
const problem = subdomainProblem(ctx.value);
|
|
7007
7368
|
if (problem) ctx.issues.push({ code: "custom", message: problem, input: ctx.value });
|
|
7008
7369
|
}).optional(),
|
|
7009
|
-
size:
|
|
7370
|
+
size: z17.enum(SIZE_NAMES).optional(),
|
|
7010
7371
|
/** The build output directory, relative to the app; the template's default when absent. */
|
|
7011
|
-
dist:
|
|
7372
|
+
dist: z17.string().optional(),
|
|
7012
7373
|
/** The port a Next.js app or Node server serves; the template's (3000) when absent. */
|
|
7013
|
-
port:
|
|
7374
|
+
port: z17.number().int().min(1).max(65535).optional()
|
|
7014
7375
|
});
|
|
7015
7376
|
var SERVICE_KEY_RE = /^[a-z][a-z0-9-]{0,19}$/;
|
|
7016
7377
|
var RESERVED_SERVICE_KEYS = ["app", "agent", "init", "volumes"];
|
|
@@ -7022,38 +7383,38 @@ var POSTGRES_PORT = 5432;
|
|
|
7022
7383
|
var POSTGRES_IMAGE = "postgres:17";
|
|
7023
7384
|
var POSTGRES_ENV = "DATABASE_URL";
|
|
7024
7385
|
var IMAGE_RE = /^[a-z0-9][a-z0-9._/:@-]*$/;
|
|
7025
|
-
var ServiceSchema =
|
|
7026
|
-
template:
|
|
7386
|
+
var ServiceSchema = z17.strictObject({
|
|
7387
|
+
template: z17.enum([...TEMPLATE_IDS, POSTGRES]),
|
|
7027
7388
|
/** The service's directory, relative to the one holding kvbox.json; every template but postgres has one. */
|
|
7028
|
-
dir:
|
|
7389
|
+
dir: z17.string().min(1).optional(),
|
|
7029
7390
|
/** A postgres service's image, `postgres:17` when absent (`pgvector/pgvector:pg17` for vectors). */
|
|
7030
|
-
image:
|
|
7391
|
+
image: z17.string().regex(IMAGE_RE, "an image name like postgres:17").optional(),
|
|
7031
7392
|
/** The volume (a key of `volumes`) a postgres service keeps its data on. */
|
|
7032
|
-
volume:
|
|
7393
|
+
volume: z17.string().optional(),
|
|
7033
7394
|
/** The box variable a postgres service's URL is written to, `DATABASE_URL` when absent. */
|
|
7034
|
-
env:
|
|
7395
|
+
env: z17.string().optional(),
|
|
7035
7396
|
/** 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`. */
|
|
7036
|
-
context:
|
|
7037
|
-
dist:
|
|
7397
|
+
context: z17.string().min(1).optional(),
|
|
7398
|
+
dist: z17.string().optional(),
|
|
7038
7399
|
/**
|
|
7039
7400
|
* A command run once per deploy in the service's new version (a docker service: in a container of
|
|
7040
7401
|
* the new image; node, nextjs: in the new source, installed and built), with the box's variables,
|
|
7041
7402
|
* before it replaces the running one. Migrations, mostly. A failing one stops that service's deploy.
|
|
7042
7403
|
*/
|
|
7043
|
-
release:
|
|
7404
|
+
release: z17.string().optional(),
|
|
7044
7405
|
/** The box port of a service with its own server; the template's (3000) when absent. */
|
|
7045
|
-
port:
|
|
7406
|
+
port: z17.number().int().min(1).max(65535).optional(),
|
|
7046
7407
|
/** The URL paths that go to this service, each with everything under it; the prefix is kept. */
|
|
7047
|
-
paths:
|
|
7408
|
+
paths: z17.array(z17.string().regex(ROUTE_RE, "a path like / or /api, no trailing slash")).min(1).optional()
|
|
7048
7409
|
});
|
|
7049
|
-
var StackConfigSchema =
|
|
7410
|
+
var StackConfigSchema = z17.strictObject({
|
|
7050
7411
|
name: DeployConfigSchema.shape.name.optional(),
|
|
7051
7412
|
org: DeployConfigSchema.shape.org,
|
|
7052
7413
|
subdomain: DeployConfigSchema.shape.subdomain,
|
|
7053
7414
|
size: DeployConfigSchema.shape.size,
|
|
7054
7415
|
/** The stack's volumes, name to size ("10GB"): made for its box and attached to it on the first deploy that needs one. */
|
|
7055
|
-
volumes:
|
|
7056
|
-
services:
|
|
7416
|
+
volumes: z17.record(z17.string(), z17.string()).optional(),
|
|
7417
|
+
services: z17.record(z17.string(), ServiceSchema)
|
|
7057
7418
|
});
|
|
7058
7419
|
function volumeGib(text2) {
|
|
7059
7420
|
const mib2 = parseMib(text2);
|
|
@@ -8667,155 +9028,869 @@ for (const cmd of bucketCommand.commands) {
|
|
|
8667
9028
|
else withOrg2(cmd);
|
|
8668
9029
|
}
|
|
8669
9030
|
|
|
8670
|
-
// src/commands/
|
|
8671
|
-
import { Command as
|
|
9031
|
+
// src/commands/k8s/index.ts
|
|
9032
|
+
import { Command as Command126 } from "commander";
|
|
8672
9033
|
|
|
8673
|
-
// src/commands/
|
|
9034
|
+
// src/commands/k8s/backup/index.ts
|
|
9035
|
+
import { Command as Command103 } from "commander";
|
|
9036
|
+
|
|
9037
|
+
// src/commands/k8s/backup/create.ts
|
|
8674
9038
|
import { Command as Command98 } from "commander";
|
|
8675
9039
|
|
|
8676
|
-
// src/commands/
|
|
8677
|
-
async function
|
|
9040
|
+
// src/commands/k8s/shared.ts
|
|
9041
|
+
async function k8sClient(cmd) {
|
|
8678
9042
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
8679
9043
|
if (client.target.kind !== "cloud") {
|
|
8680
9044
|
await client.close();
|
|
8681
|
-
throw new KvboxError("
|
|
9045
|
+
throw new KvboxError("Kubernetes clusters run on the kvbox cloud: kvbox login first (this host's own socket has none)");
|
|
8682
9046
|
}
|
|
8683
9047
|
return client;
|
|
8684
9048
|
}
|
|
8685
|
-
function shownName2(
|
|
9049
|
+
function shownName2(c2, client) {
|
|
8686
9050
|
const context = client.target.kind === "cloud" ? client.target.org ?? client.target.user : void 0;
|
|
8687
|
-
return
|
|
8688
|
-
}
|
|
8689
|
-
function refFor(name, client) {
|
|
8690
|
-
if (client.target.kind !== "cloud" || name.includes("/")) return name;
|
|
8691
|
-
const { org, user } = client.target;
|
|
8692
|
-
return org && org !== user ? `${org}/${name}` : name;
|
|
8693
|
-
}
|
|
8694
|
-
var scheduleText = (t) => t.timezone === "UTC" ? t.expr : `${t.expr} (${t.timezone})`;
|
|
8695
|
-
function until(iso2, now = Date.now()) {
|
|
8696
|
-
const sec = Math.round((Date.parse(iso2) - now) / 1e3);
|
|
8697
|
-
return sec <= 0 ? "now" : `in ${duration(sec)}`;
|
|
8698
|
-
}
|
|
8699
|
-
function outcomeText(outcome) {
|
|
8700
|
-
const words = {
|
|
8701
|
-
running: "running",
|
|
8702
|
-
ok: "ok",
|
|
8703
|
-
failed: "failed",
|
|
8704
|
-
timeout: "timed out",
|
|
8705
|
-
"no-credit": "skipped: no credit",
|
|
8706
|
-
"box-stopped": "skipped: box stopped",
|
|
8707
|
-
"host-down": "host unreachable",
|
|
8708
|
-
"host-outdated": "host needs an update",
|
|
8709
|
-
lost: "lost",
|
|
8710
|
-
"still-running": "skipped: still running",
|
|
8711
|
-
"box-outdated": "box image too old"
|
|
8712
|
-
};
|
|
8713
|
-
const text2 = words[outcome];
|
|
8714
|
-
return outcome === "ok" ? color.green(text2) : outcome === "running" ? color.dim(text2) : color.red(text2);
|
|
9051
|
+
return c2.owner === context ? c2.name : `${c2.owner}/${c2.name}`;
|
|
8715
9052
|
}
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
|
|
8722
|
-
next: t.enabled ? t.nextRunAt ? until(t.nextRunAt) : "never" : color.yellow("paused"),
|
|
8723
|
-
"last run": t.lastRunAt && t.lastOutcome ? `${outcomeText(t.lastOutcome)} ${color.dim(age(t.lastRunAt))}` : "-"
|
|
8724
|
-
}))
|
|
8725
|
-
);
|
|
9053
|
+
var apiText = (c2) => c2.api === null ? color.yellow("not reachable from outside (its port is closed)") : `https://${c2.api.host.includes(":") ? `[${c2.api.host}]` : c2.api.host}:${c2.api.port}`;
|
|
9054
|
+
function priceText2(c2) {
|
|
9055
|
+
const { perMonth, nodesPerMonth, totalPerMonth, currency } = c2.price;
|
|
9056
|
+
if (nodesPerMonth === void 0 || totalPerMonth === void 0) return `${money(perMonth, currency)} a month for the cluster itself ${color.dim("(estimated)")}, plus its nodes, each at a box's price`;
|
|
9057
|
+
const nodes = c2.pools.reduce((n2, p) => n2 + p.boxes.length, 0);
|
|
9058
|
+
return `${money(totalPerMonth, currency)} a month ${color.dim(`(estimated: ${money(perMonth, currency)} the cluster itself, ${money(nodesPerMonth, currency)} its ${nodes === 1 ? "node" : `${nodes} nodes`})`)}`;
|
|
8726
9059
|
}
|
|
9060
|
+
var poolsText = (c2) => c2.pools.length === 0 ? color.dim("none") : c2.pools.map((p) => `${p.boxes.length} \xD7 ${p.size}${p.boxes.length > 0 ? color.dim(` (${p.boxes.join(", ")})`) : ""}`).join(", ");
|
|
8727
9061
|
function printRows2(rows2) {
|
|
8728
9062
|
const width2 = Math.max(...rows2.map(([label]) => label.length));
|
|
8729
9063
|
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
8730
9064
|
`);
|
|
8731
9065
|
}
|
|
8732
|
-
var
|
|
9066
|
+
var READY_WAIT_MS = 5 * 6e4;
|
|
9067
|
+
var READY_EVERY_MS = 3e3;
|
|
9068
|
+
var readyWait = () => Number(process.env["KVBOX_K8S_WAIT_MS"] ?? READY_WAIT_MS);
|
|
9069
|
+
function allReady(c2) {
|
|
9070
|
+
if (c2.health?.ready !== true) return false;
|
|
9071
|
+
const joined = new Set(c2.health.nodes.filter((n2) => n2.ready).map((n2) => n2.name));
|
|
9072
|
+
return c2.pools.every((p) => p.boxes.length >= p.nodes && p.boxes.every((name) => joined.has(name)));
|
|
9073
|
+
}
|
|
9074
|
+
async function untilReady(client, name, made, waitMs, everyMs = Math.min(READY_EVERY_MS, waitMs), done = allReady, fatal = () => false) {
|
|
9075
|
+
const deadline = Date.now() + waitMs;
|
|
9076
|
+
let last = made;
|
|
9077
|
+
for (; ; ) {
|
|
9078
|
+
const now = await client.getCluster(name).catch((err) => {
|
|
9079
|
+
if (fatal(err)) throw err;
|
|
9080
|
+
return void 0;
|
|
9081
|
+
});
|
|
9082
|
+
if (now !== void 0) last = now;
|
|
9083
|
+
if (done(last) || Date.now() + everyMs > deadline) return last;
|
|
9084
|
+
await new Promise((done2) => setTimeout(done2, everyMs));
|
|
9085
|
+
}
|
|
9086
|
+
}
|
|
9087
|
+
function nodeCount(text2) {
|
|
9088
|
+
const nodes = Number(text2);
|
|
9089
|
+
if (!Number.isInteger(nodes) || nodes < 1 || nodes > MAX_POOL_NODES) throw new KvboxError(`--nodes ${text2}: a whole number from 1 to ${MAX_POOL_NODES}`);
|
|
9090
|
+
return nodes;
|
|
9091
|
+
}
|
|
9092
|
+
var roomText = (room) => room.s === 0 ? color.yellow("its host is full: no node of any size fits") : `${NODE_SIZES.filter((size) => room[size] > 0).map((size) => `${room[size]} \xD7 ${size}`).join(", ").replace(/, ([^,]*)$/, " or $1")} more ${color.dim("(as its host has room now; nothing is reserved)")}`;
|
|
8733
9093
|
|
|
8734
|
-
// src/commands/
|
|
8735
|
-
var createCommand9 = new Command98("create").description("
|
|
8736
|
-
const client = await
|
|
9094
|
+
// src/commands/k8s/backup/create.ts
|
|
9095
|
+
var createCommand9 = new Command98("create").description("back up what a cluster knows to the kvbox cloud (encrypted)").argument("<cluster>", "cluster 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) => {
|
|
9096
|
+
const client = await k8sClient(cmd);
|
|
9097
|
+
const ls = `kvbox k8s backup ls ${name}`;
|
|
8737
9098
|
try {
|
|
8738
|
-
const
|
|
8739
|
-
if (opts.
|
|
8740
|
-
json(
|
|
9099
|
+
const started = await client.createClusterBackup(name);
|
|
9100
|
+
if (!opts.wait) {
|
|
9101
|
+
if (opts.json) json(started);
|
|
9102
|
+
else {
|
|
9103
|
+
info(`${color.green("\u2713")} backup ${started.id} of cluster ${color.bold(name)} started; it runs in the background`);
|
|
9104
|
+
info(color.dim(` status: ${ls}`));
|
|
9105
|
+
await printCost(client, false, true);
|
|
9106
|
+
}
|
|
8741
9107
|
return;
|
|
8742
9108
|
}
|
|
8743
|
-
const
|
|
8744
|
-
|
|
8745
|
-
|
|
9109
|
+
const done = await spin(`backing up cluster ${name}\u2026`, untilSettled(() => client.clusterBackup(name, started.id), `cluster ${name}`, started.id, ls));
|
|
9110
|
+
if (opts.json) json(done);
|
|
9111
|
+
if (done.status === "failed") throw new KvboxError(`backup ${done.id} of cluster ${name} failed: ${done.error ?? "no reason given"}`);
|
|
9112
|
+
if (opts.json) return;
|
|
9113
|
+
info(`${color.green("\u2713")} backup ${done.id} of cluster ${color.bold(name)}: ${sizeLine(done)}`);
|
|
9114
|
+
info(color.dim(` restore with: kvbox k8s backup restore ${name} ${done.id}`));
|
|
9115
|
+
await printCost(client, true, true);
|
|
8746
9116
|
} finally {
|
|
8747
9117
|
await client.close();
|
|
8748
9118
|
}
|
|
8749
9119
|
});
|
|
8750
9120
|
|
|
8751
|
-
// src/commands/
|
|
9121
|
+
// src/commands/k8s/backup/ls.ts
|
|
8752
9122
|
import { Command as Command99 } from "commander";
|
|
8753
|
-
var
|
|
8754
|
-
const client = await
|
|
9123
|
+
var lsCommand15 = new Command99("ls").alias("list").description("list backups: every cluster's, or one cluster's").argument("[cluster]", "cluster name (default: every cluster)").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
9124
|
+
const client = await k8sClient(cmd);
|
|
9125
|
+
const removedOnes = async (err, name2) => {
|
|
9126
|
+
if (!(err instanceof CallError && err.status === 404)) throw err;
|
|
9127
|
+
const gone = (await client.listClusterBackups()).filter((b) => b.name === name2 || `${b.owner}/${b.name}` === name2);
|
|
9128
|
+
if (gone.length === 0) throw err;
|
|
9129
|
+
const own = name2.includes("/") ? [] : gone.filter((b) => b.owner === me(client));
|
|
9130
|
+
return own.length > 0 ? own : gone;
|
|
9131
|
+
};
|
|
8755
9132
|
try {
|
|
8756
|
-
const
|
|
8757
|
-
const triggers = await client.listCronTriggers(name);
|
|
9133
|
+
const list = name === void 0 ? await client.listClusterBackups() : await client.clusterBackups(name).catch((err) => removedOnes(err, name));
|
|
8758
9134
|
if (opts.json) {
|
|
8759
|
-
json(
|
|
9135
|
+
json(list);
|
|
8760
9136
|
return;
|
|
8761
9137
|
}
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
9138
|
+
const schedule = name === void 0 ? null : await client.clusterBackupSchedule(name).catch(() => null);
|
|
9139
|
+
const footer = () => {
|
|
9140
|
+
if (schedule !== null) info(`${color.dim("on its own:")} ${scheduleLine(`kvbox k8s backup schedule ${name}`, schedule)}`);
|
|
9141
|
+
};
|
|
9142
|
+
if (list.length === 0) {
|
|
9143
|
+
info(name === void 0 ? "no backups yet; make one with: kvbox k8s backup create <cluster>" : `cluster ${name} has no backups; make one with: kvbox k8s backup create ${name}`);
|
|
9144
|
+
footer();
|
|
9145
|
+
return;
|
|
9146
|
+
}
|
|
9147
|
+
const anyError = list.some((b) => b.error !== null);
|
|
9148
|
+
const others = list.some((b) => b.owner !== me(client));
|
|
9149
|
+
table(
|
|
9150
|
+
list.map((b) => ({
|
|
9151
|
+
id: b.id,
|
|
9152
|
+
...name === void 0 || others ? { cluster: b.owner === me(client) ? b.name : `${b.owner}/${b.name}` } : {},
|
|
9153
|
+
status: b.status === "ready" ? color.green(b.status) : b.status === "failed" ? color.red(b.status) : color.yellow(b.status),
|
|
9154
|
+
version: b.version,
|
|
9155
|
+
data: b.dataBytes === null ? "-" : gbShort(b.dataBytes),
|
|
9156
|
+
uploaded: b.uploadedBytes === null ? "-" : gbShort(b.uploadedBytes),
|
|
9157
|
+
by: b.scheduled ? color.dim("schedule") : b.createdBy ?? "-",
|
|
9158
|
+
taken: age(b.createdAt),
|
|
9159
|
+
...anyError ? { error: b.error ?? "" } : {}
|
|
9160
|
+
}))
|
|
9161
|
+
);
|
|
9162
|
+
footer();
|
|
8771
9163
|
} finally {
|
|
8772
9164
|
await client.close();
|
|
8773
9165
|
}
|
|
8774
9166
|
});
|
|
8775
9167
|
|
|
8776
|
-
// src/commands/
|
|
9168
|
+
// src/commands/k8s/backup/restore.ts
|
|
8777
9169
|
import { Command as Command100 } from "commander";
|
|
8778
|
-
var
|
|
8779
|
-
const client = await
|
|
9170
|
+
var restoreCommand4 = new Command100("restore").description("put a backup back: what the cluster knows becomes the backup's (its master restarts)").argument("<cluster>", "cluster name").argument("<id>", "the backup's id (kvbox k8s backup ls <cluster>)").option("-y, --yes", "do not ask for confirmation").option("--no-wait", "do not wait for the nodes to be Ready again").option("--json", "print what changed as JSON").action(async (name, id, opts, cmd) => {
|
|
9171
|
+
const client = await k8sClient(cmd);
|
|
8780
9172
|
try {
|
|
8781
|
-
const
|
|
8782
|
-
|
|
8783
|
-
|
|
9173
|
+
const backup = await client.clusterBackup(name, id);
|
|
9174
|
+
const question = `Restore cluster ${name} from backup ${backup.id} (${age(backup.createdAt)} ago, ${sizeLine(backup)})? Everything applied to it since is lost, and its master restarts.`;
|
|
9175
|
+
if (!await confirm(question, opts.yes ?? false)) {
|
|
9176
|
+
info("cancelled");
|
|
9177
|
+
process.exitCode = 1;
|
|
8784
9178
|
return;
|
|
8785
9179
|
}
|
|
8786
|
-
|
|
8787
|
-
|
|
9180
|
+
const done = await spin(`restoring cluster ${name} from ${backup.id}\u2026`, client.restoreClusterBackup(name, id));
|
|
9181
|
+
if (opts.json) {
|
|
9182
|
+
const cluster = opts.wait ? await spin("waiting for its nodes to be Ready again\u2026", untilReady(client, name, done.cluster, readyWait())) : done.cluster;
|
|
9183
|
+
json({ ...done, cluster });
|
|
8788
9184
|
return;
|
|
8789
9185
|
}
|
|
8790
|
-
|
|
8791
|
-
|
|
9186
|
+
info(`${color.green("\u2713")} cluster ${color.bold(name)} restored from backup ${backup.id}`);
|
|
9187
|
+
const list = (names2) => names2.join(", ");
|
|
9188
|
+
if (done.nodes.forgotten.length > 0) info(` nodes removed since the backup, taken out of its list again: ${list(done.nodes.forgotten)}`);
|
|
9189
|
+
if (done.nodes.restarted.length > 0) info(` nodes added since the backup, restarted to join again: ${list(done.nodes.restarted)}`);
|
|
9190
|
+
for (const w of done.warnings) warn(` ${w}`);
|
|
9191
|
+
if (!opts.wait) return;
|
|
9192
|
+
const now = await spin("waiting for its nodes to be Ready again\u2026", untilReady(client, name, done.cluster, readyWait()));
|
|
9193
|
+
if (allReady(now)) info(`${color.green("\u2713")} every node is Ready`);
|
|
9194
|
+
else warn(`it is restored, but not every node is Ready yet; look again with: kvbox k8s info ${name}`);
|
|
8792
9195
|
} finally {
|
|
8793
9196
|
await client.close();
|
|
8794
9197
|
}
|
|
8795
9198
|
});
|
|
8796
9199
|
|
|
8797
|
-
// src/commands/
|
|
9200
|
+
// src/commands/k8s/backup/rm.ts
|
|
8798
9201
|
import { Command as Command101 } from "commander";
|
|
8799
|
-
var rmCommand14 = new Command101("rm").alias("remove").description("
|
|
8800
|
-
const client = await
|
|
9202
|
+
var rmCommand14 = new Command101("rm").alias("remove").description("remove a backup for good (a cluster's that is gone too)").argument("<cluster>", "cluster name").argument("<id>", "the backup's id (kvbox k8s backup ls <cluster>)").option("-y, --yes", "do not ask for confirmation").action(async (name, id, opts, cmd) => {
|
|
9203
|
+
const client = await k8sClient(cmd);
|
|
8801
9204
|
try {
|
|
8802
|
-
|
|
8803
|
-
info("cancelled");
|
|
8804
|
-
process.exitCode = 1;
|
|
8805
|
-
return;
|
|
8806
|
-
}
|
|
8807
|
-
await client.deleteCronService(name);
|
|
8808
|
-
info(`${color.green("\u2713")} cron service ${name} deleted`);
|
|
9205
|
+
await removeListed(client, await client.listClusterBackups(), (b) => b.name, name, id, `cluster ${name}`, opts.yes ?? false);
|
|
8809
9206
|
} finally {
|
|
8810
9207
|
await client.close();
|
|
8811
9208
|
}
|
|
8812
9209
|
});
|
|
8813
9210
|
|
|
8814
|
-
// src/commands/
|
|
8815
|
-
import { Command as Command109 } from "commander";
|
|
8816
|
-
|
|
8817
|
-
// src/commands/cron/trigger/add.ts
|
|
9211
|
+
// src/commands/k8s/backup/schedule.ts
|
|
8818
9212
|
import { Command as Command102 } from "commander";
|
|
9213
|
+
var scheduleCommand4 = scheduleFlags(new Command102("schedule").description("show or change when a cluster is backed up on its own (daily, UTC)").argument("<cluster>", "cluster name")).action(
|
|
9214
|
+
async (name, flags, cmd) => {
|
|
9215
|
+
const change = changeOf(flags);
|
|
9216
|
+
const client = await k8sClient(cmd);
|
|
9217
|
+
try {
|
|
9218
|
+
const changed = Object.keys(change).length > 0;
|
|
9219
|
+
const schedule = changed ? await client.setClusterBackupSchedule(name, change) : await client.clusterBackupSchedule(name);
|
|
9220
|
+
printSchedule(`cluster ${name}`, `kvbox k8s backup schedule ${name}`, schedule, flags, changed);
|
|
9221
|
+
} finally {
|
|
9222
|
+
await client.close();
|
|
9223
|
+
}
|
|
9224
|
+
}
|
|
9225
|
+
);
|
|
9226
|
+
|
|
9227
|
+
// src/commands/k8s/backup/index.ts
|
|
9228
|
+
var backupCommand4 = new Command103("backup").description("back up what a cluster knows, list backups, restore or remove one, or change its nightly schedule").addCommand(createCommand9).addCommand(lsCommand15).addCommand(restoreCommand4).addCommand(rmCommand14).addCommand(scheduleCommand4);
|
|
9229
|
+
|
|
9230
|
+
// src/commands/k8s/create.ts
|
|
9231
|
+
import { Command as Command104 } from "commander";
|
|
9232
|
+
var createCommand10 = new Command104("create").description("make a Kubernetes cluster with its first nodes (a few minutes)").argument("<name>", "cluster name: 1-8 lowercase letters, digits and '-' (not at either end)").requiredOption("--size <size>", `what each node is sized at: ${NODE_SIZES.join(", ")}`).option("--nodes <n>", `how many nodes (1-${MAX_POOL_NODES})`, String(DEFAULT_POOL_NODES)).option("--near <box>", "put it on the host of this box").option("--no-wait", "do not wait for the cluster to be ready").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
9233
|
+
if (!NODE_SIZES.includes(opts.size)) throw new KvboxError(`--size ${opts.size}: a node is one of ${NODE_SIZES.join(", ")}`);
|
|
9234
|
+
const nodes = nodeCount(opts.nodes);
|
|
9235
|
+
const client = await k8sClient(cmd);
|
|
9236
|
+
try {
|
|
9237
|
+
const made = await spin(`making cluster ${name} and its ${nodes} node${nodes === 1 ? "" : "s"}\u2026`, client.createCluster({ name, size: opts.size, nodes, ...opts.near !== void 0 ? { near: opts.near } : {} }));
|
|
9238
|
+
const cluster = opts.wait ? await spin("waiting for its API and its nodes\u2026", untilReady(client, name, made, readyWait())) : made;
|
|
9239
|
+
if (opts.json) {
|
|
9240
|
+
json(cluster);
|
|
9241
|
+
return;
|
|
9242
|
+
}
|
|
9243
|
+
const shown = shownName2(cluster, client);
|
|
9244
|
+
info(`${color.green("\u2713")} cluster ${color.bold(shown)} made on ${cluster.host}: Kubernetes ${cluster.version}, ${priceText2(cluster)}`);
|
|
9245
|
+
info(` API: ${apiText(cluster)}`);
|
|
9246
|
+
info(` nodes: ${poolsText(cluster)}`);
|
|
9247
|
+
if (opts.wait && !allReady(cluster)) warn(`it is not all ready yet; look again with: kvbox k8s info ${shown}`);
|
|
9248
|
+
info(color.dim(` next: kvbox k8s kubeconfig ${shown} > ${cluster.name}.yaml (then: kubectl --kubeconfig ${cluster.name}.yaml get nodes)`));
|
|
9249
|
+
} finally {
|
|
9250
|
+
await client.close();
|
|
9251
|
+
}
|
|
9252
|
+
});
|
|
9253
|
+
|
|
9254
|
+
// src/commands/k8s/domain/index.ts
|
|
9255
|
+
import { Command as Command108 } from "commander";
|
|
9256
|
+
|
|
9257
|
+
// src/commands/k8s/domain/add.ts
|
|
9258
|
+
import { Command as Command105 } from "commander";
|
|
9259
|
+
|
|
9260
|
+
// src/commands/domain/shared.ts
|
|
9261
|
+
function requireCloud4(client) {
|
|
9262
|
+
if (client.target.kind !== "cloud") throw new KvboxError("custom domains need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
9263
|
+
}
|
|
9264
|
+
var boxOf2 = (d, user) => user !== void 0 && d.owner !== user ? `${d.owner}/${d.box}` : d.box;
|
|
9265
|
+
function domainJson(d, user) {
|
|
9266
|
+
return { domain: d.domain, box: boxOf2(d, user), port: d.port, status: d.status, www: d.www, url: d.url, error: d.error, records: d.records, createdAt: d.createdAt };
|
|
9267
|
+
}
|
|
9268
|
+
function zoneOf(domain) {
|
|
9269
|
+
const labels = domain.split(".");
|
|
9270
|
+
const n2 = labels.length > 2 && labels.at(-1).length === 2 && labels.at(-2).length <= 3 ? 3 : 2;
|
|
9271
|
+
return labels.slice(-n2).join(".");
|
|
9272
|
+
}
|
|
9273
|
+
function hostIn(name, zone) {
|
|
9274
|
+
return name === zone ? "@" : name.endsWith(`.${zone}`) ? name.slice(0, -(zone.length + 1)) : name;
|
|
9275
|
+
}
|
|
9276
|
+
|
|
9277
|
+
// src/commands/k8s/domain/add.ts
|
|
9278
|
+
var clusterDomainJson = (d, cluster) => ({ domain: d.domain, cluster, status: d.status, www: d.www, url: d.url, error: d.error, records: d.records, createdAt: d.createdAt });
|
|
9279
|
+
var addCommand3 = new Command105("add").description("serve a cluster at a domain of your own, https://<domain>, with its certificate made for you; an Ingress for that host picks the app").argument("<cluster>", "cluster name").argument("<domain>", "a domain you control, like example.com or app.example.com").option("--json", "print the domain as JSON").action(async (cluster, domainArg, opts, cmd) => {
|
|
9280
|
+
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
9281
|
+
const client = await k8sClient(cmd);
|
|
9282
|
+
try {
|
|
9283
|
+
const d = await spin(`adding ${domain}\u2026`, client.addClusterDomain(cluster, domain));
|
|
9284
|
+
if (opts.json) {
|
|
9285
|
+
json(clusterDomainJson(d, cluster));
|
|
9286
|
+
return;
|
|
9287
|
+
}
|
|
9288
|
+
const apex = d.records.some((r) => r.type === "CNAME");
|
|
9289
|
+
const hosts = apex ? `the hosts ${domain} and www.${domain}` : `the host ${domain}`;
|
|
9290
|
+
const ingress = `it answers once an Ingress in the cluster has ${hosts} (ingress class traefik, plain HTTP inside: kvbox ends TLS)`;
|
|
9291
|
+
if (d.status === "live") {
|
|
9292
|
+
info(`${color.green("\u2713")} ${color.bold(d.url)} \u2192 cluster ${color.bold(cluster)}`);
|
|
9293
|
+
info(" the certificate is made on the first visit, which can take a few seconds");
|
|
9294
|
+
info(` ${ingress}`);
|
|
9295
|
+
return;
|
|
9296
|
+
}
|
|
9297
|
+
info(`${color.green("\u2713")} ${domain} added for cluster ${color.bold(cluster)}, waiting for its DNS`);
|
|
9298
|
+
const zone = zoneOf(domain);
|
|
9299
|
+
info(`
|
|
9300
|
+
At the company that runs the DNS of ${zone}, add:
|
|
9301
|
+
`);
|
|
9302
|
+
table(d.records.map((r) => ({ type: r.type, host: hostIn(r.name, zone), value: r.value })));
|
|
9303
|
+
info(`
|
|
9304
|
+
(the TXT record shows ${domain} is yours; keep it, it is checked again if the domain ever goes back to pending)`);
|
|
9305
|
+
if (apex) info(` (the www record is optional: with it, www.${domain} reaches the cluster too, and an Ingress must name that host as well)`);
|
|
9306
|
+
info(`
|
|
9307
|
+
kvbox checks every minute; ${domain} is served at ${d.url} once its records are set (kvbox k8s domain ls ${cluster}).`);
|
|
9308
|
+
info(` ${ingress}`);
|
|
9309
|
+
if (d.error) info(color.dim(` now: ${d.error}`));
|
|
9310
|
+
} finally {
|
|
9311
|
+
await client.close();
|
|
9312
|
+
}
|
|
9313
|
+
});
|
|
9314
|
+
|
|
9315
|
+
// src/commands/k8s/domain/ls.ts
|
|
9316
|
+
import { Command as Command106 } from "commander";
|
|
9317
|
+
var lsCommand16 = new Command106("ls").alias("list").description("list a cluster's custom domains and whether they are live").argument("<cluster>", "cluster name").option("--json", "print as JSON").action(async (cluster, opts, cmd) => {
|
|
9318
|
+
const client = await k8sClient(cmd);
|
|
9319
|
+
try {
|
|
9320
|
+
const domains = await client.listClusterDomains(cluster);
|
|
9321
|
+
if (opts.json) {
|
|
9322
|
+
json(domains.map((d) => clusterDomainJson(d, cluster)));
|
|
9323
|
+
return;
|
|
9324
|
+
}
|
|
9325
|
+
if (domains.length === 0) {
|
|
9326
|
+
info(`cluster ${cluster} has no custom domain (kvbox k8s domain add ${cluster} <domain>)`);
|
|
9327
|
+
return;
|
|
9328
|
+
}
|
|
9329
|
+
table(domains.map((d) => ({ domain: d.www ? `${d.domain} (+www)` : d.domain, status: d.status === "live" ? "live" : "pending dns", note: d.status === "live" ? d.url : d.error ?? "" })));
|
|
9330
|
+
} finally {
|
|
9331
|
+
await client.close();
|
|
9332
|
+
}
|
|
9333
|
+
});
|
|
9334
|
+
|
|
9335
|
+
// src/commands/k8s/domain/rm.ts
|
|
9336
|
+
import { Command as Command107 } from "commander";
|
|
9337
|
+
var rmCommand15 = new Command107("rm").alias("remove").description("stop serving a cluster at a custom domain").argument("<cluster>", "cluster name").argument("<domain>", "the domain").option("-y, --yes", "do not ask for confirmation").action(async (cluster, domainArg, opts, cmd) => {
|
|
9338
|
+
const domain = domainArg.trim().toLowerCase();
|
|
9339
|
+
const client = await k8sClient(cmd);
|
|
9340
|
+
try {
|
|
9341
|
+
if (!await confirm(`Stop serving cluster ${cluster} at ${domain}?`, opts.yes ?? false)) {
|
|
9342
|
+
info("cancelled");
|
|
9343
|
+
process.exitCode = 1;
|
|
9344
|
+
return;
|
|
9345
|
+
}
|
|
9346
|
+
await spin(`removing ${domain}\u2026`, client.removeClusterDomain(cluster, domain));
|
|
9347
|
+
info(`${color.green("\u2713")} ${domain} no longer reaches cluster ${cluster} (you can remove its DNS record)`);
|
|
9348
|
+
} finally {
|
|
9349
|
+
await client.close();
|
|
9350
|
+
}
|
|
9351
|
+
});
|
|
9352
|
+
|
|
9353
|
+
// src/commands/k8s/domain/index.ts
|
|
9354
|
+
var domainCommand = new Command108("domain").description("serve a cluster at domains of your own: add one, list them, remove one").addCommand(addCommand3).addCommand(lsCommand16).addCommand(rmCommand15);
|
|
9355
|
+
|
|
9356
|
+
// src/commands/k8s/info.ts
|
|
9357
|
+
import { Command as Command109 } from "commander";
|
|
9358
|
+
var infoCommand2 = new Command109("info").description("one cluster: its API address, whether it is ready, its nodes").argument("<name>", "cluster name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
9359
|
+
const client = await k8sClient(cmd);
|
|
9360
|
+
try {
|
|
9361
|
+
const c2 = await client.getCluster(name);
|
|
9362
|
+
if (opts.json) {
|
|
9363
|
+
json(c2);
|
|
9364
|
+
return;
|
|
9365
|
+
}
|
|
9366
|
+
const shown = shownName2(c2, client);
|
|
9367
|
+
const h = c2.health ?? null;
|
|
9368
|
+
const said = new Map((h?.nodes ?? []).map((n2) => [n2.name, n2]));
|
|
9369
|
+
const node = (name2) => {
|
|
9370
|
+
const n2 = said.get(name2);
|
|
9371
|
+
if (h === null) return name2;
|
|
9372
|
+
return `${name2}${n2 === void 0 ? color.yellow(" (not joined)") : `${n2.ready ? "" : color.yellow(" (not ready)")}${n2.schedulable ? "" : color.dim(" (cordoned)")}`}`;
|
|
9373
|
+
};
|
|
9374
|
+
const rows2 = [
|
|
9375
|
+
["name", color.bold(shown)],
|
|
9376
|
+
["status", h === null ? `${status(c2.status)}${c2.status === "running" ? color.dim(" (not answering yet)") : ""}` : h.ready ? color.green("ready") : color.yellow("starting")],
|
|
9377
|
+
["version", h?.version ?? c2.version],
|
|
9378
|
+
["API", apiText(c2)],
|
|
9379
|
+
["ingress", h === null ? color.dim("unknown") : h.ingress ? "Traefik, ports 80 and 443" : color.dim("not up yet")],
|
|
9380
|
+
["addresses", (c2.addresses ?? []).length === 0 ? color.dim(`none (kvbox k8s proxy claim ${shown} <name>, kvbox k8s domain add ${shown} <domain>)`) : c2.addresses.join(", ")],
|
|
9381
|
+
...c2.pools.length === 0 ? [["nodes", color.dim("none")]] : c2.pools.map((p) => [`pool ${p.name}`, `${p.nodes === 0 ? "being removed" : `${p.nodes} \xD7 ${p.size}`}: ${p.boxes.length === 0 ? color.dim("no node") : p.boxes.map(node).join(", ")}`]),
|
|
9382
|
+
...c2.operation ? [["changing", color.yellow(c2.operation.what)]] : c2.operationError ? [["last change", color.yellow(`did not finish: ${c2.operationError}`)]] : [],
|
|
9383
|
+
...c2.backupSchedule ? [["backups", scheduleLine(`kvbox k8s backup schedule ${shown}`, c2.backupSchedule)]] : [],
|
|
9384
|
+
["host", `${c2.host}${c2.country ? ` (${c2.country})` : ""}`],
|
|
9385
|
+
...c2.room ? [["room", roomText(c2.room)]] : [],
|
|
9386
|
+
["cost", priceText2(c2)],
|
|
9387
|
+
["created", `${age(c2.createdAt)}${c2.createdBy ? ` by ${c2.createdBy}` : ""}`]
|
|
9388
|
+
];
|
|
9389
|
+
printRows2(rows2);
|
|
9390
|
+
} finally {
|
|
9391
|
+
await client.close();
|
|
9392
|
+
}
|
|
9393
|
+
});
|
|
9394
|
+
|
|
9395
|
+
// src/commands/k8s/kubeconfig.ts
|
|
9396
|
+
import { Command as Command110 } from "commander";
|
|
9397
|
+
var kubeconfigCommand = new Command110("kubeconfig").description("print the cluster's kubeconfig (it is the cluster's admin: keep it like a password)").argument("<name>", "cluster name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
9398
|
+
const client = await k8sClient(cmd);
|
|
9399
|
+
try {
|
|
9400
|
+
const made = await client.getKubeconfig(name);
|
|
9401
|
+
if (opts.json) json(made);
|
|
9402
|
+
else process.stdout.write(made.kubeconfig.endsWith("\n") ? made.kubeconfig : `${made.kubeconfig}
|
|
9403
|
+
`);
|
|
9404
|
+
} finally {
|
|
9405
|
+
await client.close();
|
|
9406
|
+
}
|
|
9407
|
+
});
|
|
9408
|
+
|
|
9409
|
+
// src/commands/k8s/link.ts
|
|
9410
|
+
import { Command as Command111 } from "commander";
|
|
9411
|
+
var reachedText = (l) => `${l.kind} ${l.to}`;
|
|
9412
|
+
var linkJson = (l, cluster) => ({ cluster, to: l.to, owner: l.owner, kind: l.kind, port: l.port, host: l.host, ...l.boxes ? { boxes: l.boxes } : {} });
|
|
9413
|
+
var linkCommand2 = new Command111("link").description("let every pod of a cluster reach a database or a box's port (private; never public)").argument("<cluster>", "cluster name").argument("<target>", "a database (kvbox pg, kvbox redis) or a box; <slug>/<name> for another account's").option("-p, --port <port>", "the port, for a box (a database has its own)").option("--json", "print the link as JSON").action(async (cluster, target, opts, cmd) => {
|
|
9414
|
+
const port = opts.port === void 0 ? void 0 : parseLinkPort(opts.port);
|
|
9415
|
+
const client = await k8sClient(cmd);
|
|
9416
|
+
try {
|
|
9417
|
+
const link2 = await spin(`linking ${cluster} to ${target}\u2026`, client.linkCluster(cluster, { to: target, ...port !== void 0 ? { port } : {} }));
|
|
9418
|
+
if (opts.json) {
|
|
9419
|
+
json(linkJson(link2, cluster));
|
|
9420
|
+
return;
|
|
9421
|
+
}
|
|
9422
|
+
info(`${color.green("\u2713")} cluster ${color.bold(cluster)} reaches ${reachedText(link2)} at ${color.bold(`${link2.host}:${link2.port}`)}`);
|
|
9423
|
+
info(` from its ${link2.boxes?.length ?? 0} boxes (the master and every node); a node added later gets it too`);
|
|
9424
|
+
info(" in a pod, connect to that name: it resolves inside the cluster");
|
|
9425
|
+
} finally {
|
|
9426
|
+
await client.close();
|
|
9427
|
+
}
|
|
9428
|
+
});
|
|
9429
|
+
|
|
9430
|
+
// src/commands/k8s/links.ts
|
|
9431
|
+
import { Command as Command112 } from "commander";
|
|
9432
|
+
var linksCommand2 = new Command112("links").description("list what a cluster reaches (kvbox k8s link)").argument("<cluster>", "cluster name").option("--json", "print as JSON").action(async (cluster, opts, cmd) => {
|
|
9433
|
+
const client = await k8sClient(cmd);
|
|
9434
|
+
try {
|
|
9435
|
+
const links = await client.listClusterLinks(cluster);
|
|
9436
|
+
if (opts.json) {
|
|
9437
|
+
json(links.map((l) => linkJson(l, cluster)));
|
|
9438
|
+
return;
|
|
9439
|
+
}
|
|
9440
|
+
if (links.length === 0) info(`cluster ${cluster} reaches nothing (kvbox k8s link ${cluster} <database or box>)`);
|
|
9441
|
+
else table(links.map((l) => ({ reaches: reachedText(l), address: `${l.host}:${l.port}` })));
|
|
9442
|
+
} finally {
|
|
9443
|
+
await client.close();
|
|
9444
|
+
}
|
|
9445
|
+
});
|
|
9446
|
+
|
|
9447
|
+
// src/commands/k8s/ls.ts
|
|
9448
|
+
import { Command as Command113 } from "commander";
|
|
9449
|
+
var lsCommand17 = new Command113("ls").alias("list").description("list Kubernetes clusters").option("-a, --all", "every cluster on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
9450
|
+
const client = await k8sClient(cmd);
|
|
9451
|
+
try {
|
|
9452
|
+
const clusters = await client.listClusters({ all: opts.all });
|
|
9453
|
+
if (opts.json) {
|
|
9454
|
+
json(clusters);
|
|
9455
|
+
return;
|
|
9456
|
+
}
|
|
9457
|
+
if (clusters.length === 0) {
|
|
9458
|
+
info("no clusters yet; make one with: kvbox k8s create <name> --size m");
|
|
9459
|
+
return;
|
|
9460
|
+
}
|
|
9461
|
+
const me2 = client.target.kind === "cloud" ? client.target.user : void 0;
|
|
9462
|
+
table(
|
|
9463
|
+
clusters.map((c2) => ({
|
|
9464
|
+
owner: c2.owner === me2 ? "private" : c2.owner,
|
|
9465
|
+
name: c2.name,
|
|
9466
|
+
status: status(c2.status),
|
|
9467
|
+
version: c2.version,
|
|
9468
|
+
nodes: c2.pools.length === 0 ? "-" : c2.pools.map((p) => `${p.boxes.length} \xD7 ${p.size}`).join(", "),
|
|
9469
|
+
host: c2.host,
|
|
9470
|
+
api: c2.api === null ? "-" : apiText(c2),
|
|
9471
|
+
created: age(c2.createdAt)
|
|
9472
|
+
}))
|
|
9473
|
+
);
|
|
9474
|
+
} finally {
|
|
9475
|
+
await client.close();
|
|
9476
|
+
}
|
|
9477
|
+
});
|
|
9478
|
+
|
|
9479
|
+
// src/commands/k8s/pool/index.ts
|
|
9480
|
+
import { Command as Command118 } from "commander";
|
|
9481
|
+
|
|
9482
|
+
// src/commands/k8s/pool/add.ts
|
|
9483
|
+
import { Command as Command114 } from "commander";
|
|
9484
|
+
|
|
9485
|
+
// src/commands/k8s/pool/shared.ts
|
|
9486
|
+
function poolReady(c2, pool) {
|
|
9487
|
+
const p = c2.pools.find((x) => x.name === pool);
|
|
9488
|
+
if (c2.health?.ready !== true || p === void 0) return false;
|
|
9489
|
+
const joined = new Set(c2.health.nodes.filter((n2) => n2.ready).map((n2) => n2.name));
|
|
9490
|
+
return p.boxes.length >= p.nodes && p.boxes.every((name) => joined.has(name));
|
|
9491
|
+
}
|
|
9492
|
+
function untilJoined(client, named, changed, pool) {
|
|
9493
|
+
const watched = changed.operation !== void 0;
|
|
9494
|
+
return spin("waiting for the new nodes to join\u2026", untilReady(client, named, changed, readyWait() + (watched ? SLACK_MS : 0), void 0, (c2) => poolReady(c2, pool) || watched && c2.operation === void 0));
|
|
9495
|
+
}
|
|
9496
|
+
var SLACK_MS = 9e4;
|
|
9497
|
+
var DRAIN_WAIT_MS = 13 * 6e4;
|
|
9498
|
+
var leaving = (c2, pool) => {
|
|
9499
|
+
const p = c2.pools.find((x) => x.name === pool);
|
|
9500
|
+
return p === void 0 ? 0 : Math.max(0, p.boxes.length - p.nodes);
|
|
9501
|
+
};
|
|
9502
|
+
function untilDrained(client, named, changed, pool) {
|
|
9503
|
+
if (changed.operation === void 0) return Promise.resolve(changed);
|
|
9504
|
+
const count2 = Math.max(1, leaving(changed, pool));
|
|
9505
|
+
const waitMs = process.env["KVBOX_K8S_WAIT_MS"] !== void 0 ? readyWait() : count2 * DRAIN_WAIT_MS;
|
|
9506
|
+
const ours = changed.operation.since;
|
|
9507
|
+
return spin(
|
|
9508
|
+
`moving pods off ${count2 === 1 ? "the node" : `${count2} nodes`} and removing ${count2 === 1 ? "it" : "them"}\u2026`,
|
|
9509
|
+
untilReady(client, named, changed, waitMs, void 0, (c2) => c2.operation === void 0 || c2.operation.since !== ours, refused)
|
|
9510
|
+
);
|
|
9511
|
+
}
|
|
9512
|
+
var refused = (err) => !(err instanceof CallError) || err.status >= 400 && err.status < 500;
|
|
9513
|
+
function failIfNot(c2, again, ours) {
|
|
9514
|
+
if (c2.operation !== void 0) {
|
|
9515
|
+
if (ours !== void 0 && c2.operation.since !== ours.since) {
|
|
9516
|
+
throw new KvboxError(`another change (${c2.operation.what}) began before this one was seen to end, so how it ended is not known; look again with: kvbox k8s info ${c2.name}`);
|
|
9517
|
+
}
|
|
9518
|
+
return;
|
|
9519
|
+
}
|
|
9520
|
+
if (c2.operationError !== void 0) throw new KvboxError(c2.operationError);
|
|
9521
|
+
if (again !== void 0) throw new KvboxError(`the change stopped before it was done (the control plane was restarted meanwhile); ${again} goes on with it`);
|
|
9522
|
+
}
|
|
9523
|
+
var fails = (c2, again, ours) => c2.operation === void 0 ? c2.operationError !== void 0 || again !== void 0 : ours !== void 0 && c2.operation.since !== ours.since;
|
|
9524
|
+
var poolText = (p) => `${p.nodes} \xD7 ${p.size}${p.boxes.length > 0 ? color.dim(` (${p.boxes.join(", ")})`) : ""}`;
|
|
9525
|
+
var nodesText = (p) => p.nodes === 0 ? color.yellow(`being removed (${p.boxes.length} left)`) : p.boxes.length === p.nodes ? String(p.nodes) : color.yellow(`${p.boxes.length} of ${p.nodes}`);
|
|
9526
|
+
function printPool(client, c2, pool, done, waited) {
|
|
9527
|
+
const p = c2.pools.find((x) => x.name === pool);
|
|
9528
|
+
const shown = shownName2(c2, client);
|
|
9529
|
+
info(`${color.green("\u2713")} ${done}${p ? `: ${poolText(p)}` : ""}`);
|
|
9530
|
+
if (c2.operation !== void 0 && leaving(c2, pool) > 0) info(`${leaving(c2, pool) === 1 ? "a node is" : `${leaving(c2, pool)} nodes are`} still being drained and removed; look again with: kvbox k8s info ${shown}`);
|
|
9531
|
+
else if (waited && !poolReady(c2, pool)) warn(`its nodes have not all joined yet; look again with: kvbox k8s info ${shown}`);
|
|
9532
|
+
}
|
|
9533
|
+
|
|
9534
|
+
// src/commands/k8s/pool/add.ts
|
|
9535
|
+
var addCommand4 = new Command114("add").description("add a pool of nodes to a cluster").argument("<cluster>", "cluster name").requiredOption("--size <size>", `what each node is sized at: ${NODE_SIZES.join(", ")}`).option("--nodes <n>", `how many nodes (1-${MAX_POOL_NODES})`, String(DEFAULT_POOL_NODES)).option("--name <pool>", "the pool's name (default: its size)").option("--no-wait", "do not wait for the nodes to join").option("--json", "print as JSON").action(async (cluster, opts, cmd) => {
|
|
9536
|
+
if (!NODE_SIZES.includes(opts.size)) throw new KvboxError(`--size ${opts.size}: a node is one of ${NODE_SIZES.join(", ")}`);
|
|
9537
|
+
const nodes = nodeCount(opts.nodes);
|
|
9538
|
+
const pool = opts.name ?? opts.size;
|
|
9539
|
+
const client = await k8sClient(cmd);
|
|
9540
|
+
try {
|
|
9541
|
+
const made = await spin(`adding pool ${pool} to ${cluster}: ${nodes} ${opts.size} node${nodes === 1 ? "" : "s"}\u2026`, client.addPool(cluster, { size: opts.size, nodes, ...opts.name !== void 0 ? { name: opts.name } : {} }));
|
|
9542
|
+
const now = opts.wait ? await untilJoined(client, cluster, made, pool) : made;
|
|
9543
|
+
if (opts.json) json(now);
|
|
9544
|
+
else printPool(client, now, pool, `pool ${pool} added to cluster ${shownName2(now, client)}`, opts.wait);
|
|
9545
|
+
failIfNot(now);
|
|
9546
|
+
} finally {
|
|
9547
|
+
await client.close();
|
|
9548
|
+
}
|
|
9549
|
+
});
|
|
9550
|
+
|
|
9551
|
+
// src/commands/k8s/pool/ls.ts
|
|
9552
|
+
import { Command as Command115 } from "commander";
|
|
9553
|
+
var lsCommand18 = new Command115("ls").alias("list").description("list a cluster's pools").argument("<cluster>", "cluster name").option("--json", "print as JSON").action(async (cluster, opts, cmd) => {
|
|
9554
|
+
const client = await k8sClient(cmd);
|
|
9555
|
+
try {
|
|
9556
|
+
const c2 = await client.getCluster(cluster);
|
|
9557
|
+
if (opts.json) {
|
|
9558
|
+
json(c2.pools);
|
|
9559
|
+
return;
|
|
9560
|
+
}
|
|
9561
|
+
if (c2.pools.length === 0) info(`no pools yet; add one with: kvbox k8s pool add ${cluster} --size m`);
|
|
9562
|
+
else table(c2.pools.map((p) => ({ pool: p.name, size: p.size, nodes: nodesText(p), boxes: p.boxes.join(", ") || "-" })));
|
|
9563
|
+
if (c2.operation) info(color.yellow(`${c2.operation.what}, since ${age(c2.operation.since)}`));
|
|
9564
|
+
else if (c2.operationError) warn(`the last change did not finish: ${c2.operationError}`);
|
|
9565
|
+
if (c2.room) info(`room for ${roomText(c2.room)}`);
|
|
9566
|
+
} finally {
|
|
9567
|
+
await client.close();
|
|
9568
|
+
}
|
|
9569
|
+
});
|
|
9570
|
+
|
|
9571
|
+
// src/commands/k8s/pool/resize.ts
|
|
9572
|
+
import { Command as Command116 } from "commander";
|
|
9573
|
+
var resizeCommand = new Command116("resize").description("change how many nodes a pool has").argument("<cluster>", "cluster name").argument("<pool>", "pool name (kvbox k8s pool ls <cluster>)").requiredOption("--nodes <n>", "how many nodes the pool should have").option("--force", "fewer nodes: remove them at once, undrained, with what they keep on their disks").option("-y, --yes", "do not ask for confirmation (fewer nodes)").option("--no-wait", "do not wait for new nodes to join, or for removed ones to drain").option("--json", "print as JSON").action(async (cluster, pool, opts, cmd) => {
|
|
9574
|
+
const nodes = nodeCount(opts.nodes);
|
|
9575
|
+
const client = await k8sClient(cmd);
|
|
9576
|
+
try {
|
|
9577
|
+
const before = opts.yes ? void 0 : (await client.getCluster(cluster)).pools.find((p) => p.name === pool);
|
|
9578
|
+
const going = before === void 0 ? [] : before.boxes.slice(nodes).reverse();
|
|
9579
|
+
const shrinks = opts.force || going.length > 0;
|
|
9580
|
+
const what = going.length > 0 ? `${going.length === 1 ? "node" : "nodes"} ${going.join(", ")} of pool ${pool}` : `the nodes pool ${pool} of ${cluster} has beyond ${nodes}`;
|
|
9581
|
+
const question = opts.force ? `Remove ${what} without draining, with whatever they keep on their disks?` : `Drain and remove ${what} (cluster ${cluster})?`;
|
|
9582
|
+
if (shrinks && !await confirm(question, opts.yes ?? false)) {
|
|
9583
|
+
info("cancelled");
|
|
9584
|
+
process.exitCode = 1;
|
|
9585
|
+
return;
|
|
9586
|
+
}
|
|
9587
|
+
const changed = await spin(`resizing pool ${pool} of ${cluster} to ${nodes} node${nodes === 1 ? "" : "s"}\u2026`, client.resizePool(cluster, pool, nodes, opts.force ?? false));
|
|
9588
|
+
const now = !opts.wait ? changed : leaving(changed, pool) > 0 ? await untilDrained(client, cluster, changed, pool) : await untilJoined(client, cluster, changed, pool);
|
|
9589
|
+
const again = opts.wait && leaving(now, pool) > 0 ? `kvbox k8s pool resize ${cluster} ${pool} --nodes ${nodes}${opts.force ? " --force -y" : ""}` : void 0;
|
|
9590
|
+
const ours = opts.wait && leaving(changed, pool) > 0 ? changed.operation : void 0;
|
|
9591
|
+
if (opts.json) json(now);
|
|
9592
|
+
else if (!fails(now, again, ours)) printPool(client, now, pool, `pool ${pool} of cluster ${shownName2(now, client)}`, opts.wait);
|
|
9593
|
+
failIfNot(now, again, ours);
|
|
9594
|
+
} finally {
|
|
9595
|
+
await client.close();
|
|
9596
|
+
}
|
|
9597
|
+
});
|
|
9598
|
+
|
|
9599
|
+
// src/commands/k8s/pool/rm.ts
|
|
9600
|
+
import { Command as Command117 } from "commander";
|
|
9601
|
+
var rmCommand16 = new Command117("rm").alias("remove").description("remove a pool and its nodes from a cluster").argument("<cluster>", "cluster name").argument("<pool>", "pool name (kvbox k8s pool ls <cluster>)").option("--force", "remove the nodes at once, undrained, with what they keep on their disks").option("-y, --yes", "do not ask for confirmation").option("--no-wait", "do not wait for the nodes to drain").option("--json", "print as JSON").action(async (cluster, pool, opts, cmd) => {
|
|
9602
|
+
const client = await k8sClient(cmd);
|
|
9603
|
+
try {
|
|
9604
|
+
if (!await confirm(`Remove pool ${pool} of cluster ${cluster} and its nodes${opts.force ? " without draining them, with whatever they keep on their disks" : ""}?`, opts.yes ?? false)) {
|
|
9605
|
+
info("cancelled");
|
|
9606
|
+
process.exitCode = 1;
|
|
9607
|
+
return;
|
|
9608
|
+
}
|
|
9609
|
+
const changed = await spin(`removing pool ${pool} of ${cluster}\u2026`, client.removePool(cluster, pool, opts.force ?? false));
|
|
9610
|
+
const now = opts.wait ? await untilDrained(client, cluster, changed, pool) : changed;
|
|
9611
|
+
const again = opts.wait && now.pools.some((p) => p.name === pool) ? `kvbox k8s pool rm ${cluster} ${pool}${opts.force ? " --force" : ""} -y` : void 0;
|
|
9612
|
+
if (opts.json) json(now);
|
|
9613
|
+
failIfNot(now, again, opts.wait ? changed.operation : void 0);
|
|
9614
|
+
if (opts.json) return;
|
|
9615
|
+
const shown = shownName2(now, client);
|
|
9616
|
+
if (now.pools.some((p) => p.name === pool)) info(`pool ${pool} is being removed: its nodes are drained first; look again with: kvbox k8s pool ls ${shown}`);
|
|
9617
|
+
else info(`${color.green("\u2713")} pool ${pool} removed from cluster ${shown}`);
|
|
9618
|
+
} finally {
|
|
9619
|
+
await client.close();
|
|
9620
|
+
}
|
|
9621
|
+
});
|
|
9622
|
+
|
|
9623
|
+
// src/commands/k8s/pool/index.ts
|
|
9624
|
+
var poolCommand = new Command118("pool").description("a cluster's node pools: add one, list them, change how many nodes one has, remove one").addCommand(addCommand4).addCommand(lsCommand18).addCommand(resizeCommand).addCommand(rmCommand16);
|
|
9625
|
+
|
|
9626
|
+
// src/commands/k8s/proxy/index.ts
|
|
9627
|
+
import { Command as Command122 } from "commander";
|
|
9628
|
+
|
|
9629
|
+
// src/commands/k8s/proxy/claim.ts
|
|
9630
|
+
import { Command as Command119 } from "commander";
|
|
9631
|
+
var claimCommand2 = new Command119("claim").description(`give a cluster an HTTPS address, https://<subdomain>.kvbox.app (up to ${MAX_BOX_SUBDOMAINS} per cluster); an Ingress for that host picks the app`).argument("<cluster>", "cluster name").argument("<subdomain>", "3-63 lowercase letters, digits and '-'; must be free").option("--json", "print the address as JSON").action(async (cluster, subArg, opts, cmd) => {
|
|
9632
|
+
const subdomain = assertSubdomain(subArg);
|
|
9633
|
+
const client = await k8sClient(cmd);
|
|
9634
|
+
try {
|
|
9635
|
+
const sub = await spin(`claiming ${subdomain}\u2026`, client.claimClusterSubdomain(cluster, subdomain));
|
|
9636
|
+
if (opts.json) {
|
|
9637
|
+
json({ cluster, subdomain: sub.subdomain, url: sub.url });
|
|
9638
|
+
return;
|
|
9639
|
+
}
|
|
9640
|
+
const host = sub.url.replace(/^https:\/\//, "");
|
|
9641
|
+
info(`${color.green("\u2713")} ${color.bold(sub.url)} \u2192 cluster ${color.bold(cluster)}`);
|
|
9642
|
+
info(` it answers once an Ingress in the cluster has the host ${host} (ingress class traefik, plain HTTP inside: kvbox ends TLS)`);
|
|
9643
|
+
} finally {
|
|
9644
|
+
await client.close();
|
|
9645
|
+
}
|
|
9646
|
+
});
|
|
9647
|
+
|
|
9648
|
+
// src/commands/k8s/proxy/ls.ts
|
|
9649
|
+
import { Command as Command120 } from "commander";
|
|
9650
|
+
var lsCommand19 = new Command120("ls").alias("list").description("list a cluster's kvbox.app addresses").argument("<cluster>", "cluster name").option("--json", "print as JSON").action(async (cluster, opts, cmd) => {
|
|
9651
|
+
const client = await k8sClient(cmd);
|
|
9652
|
+
try {
|
|
9653
|
+
const subs = await client.listClusterSubdomains(cluster);
|
|
9654
|
+
if (opts.json) {
|
|
9655
|
+
json(subs.map((s) => ({ cluster, subdomain: s.subdomain, url: s.url })));
|
|
9656
|
+
return;
|
|
9657
|
+
}
|
|
9658
|
+
if (subs.length === 0) info(`cluster ${cluster} has no kvbox.app address (kvbox k8s proxy claim ${cluster} <subdomain>)`);
|
|
9659
|
+
else table(subs.map((s) => ({ subdomain: s.subdomain, url: s.url })));
|
|
9660
|
+
} finally {
|
|
9661
|
+
await client.close();
|
|
9662
|
+
}
|
|
9663
|
+
});
|
|
9664
|
+
|
|
9665
|
+
// src/commands/k8s/proxy/release.ts
|
|
9666
|
+
import { Command as Command121 } from "commander";
|
|
9667
|
+
var releaseCommand2 = new Command121("release").description("give up one of a cluster's kvbox.app addresses").argument("<cluster>", "cluster name").argument("<subdomain>", "the subdomain (kvbox k8s proxy ls <cluster>)").option("-y, --yes", "do not ask for confirmation").action(async (cluster, subdomain, opts, cmd) => {
|
|
9668
|
+
const client = await k8sClient(cmd);
|
|
9669
|
+
try {
|
|
9670
|
+
if (!await confirm(`Give up ${subdomain}, one of cluster ${cluster}'s HTTPS addresses? Anyone may claim it after.`, opts.yes ?? false)) {
|
|
9671
|
+
info("cancelled");
|
|
9672
|
+
process.exitCode = 1;
|
|
9673
|
+
return;
|
|
9674
|
+
}
|
|
9675
|
+
const sub = await spin(`releasing ${subdomain}\u2026`, client.releaseClusterSubdomain(cluster, subdomain));
|
|
9676
|
+
info(`${color.green("\u2713")} ${sub.url.replace(/^https:\/\//, "")} no longer reaches cluster ${color.bold(cluster)}`);
|
|
9677
|
+
} finally {
|
|
9678
|
+
await client.close();
|
|
9679
|
+
}
|
|
9680
|
+
});
|
|
9681
|
+
|
|
9682
|
+
// src/commands/k8s/proxy/index.ts
|
|
9683
|
+
var proxyCommand2 = new Command122("proxy").description("a cluster's HTTPS addresses, https://<name>.kvbox.app: claim one, list them, give one up").addCommand(claimCommand2).addCommand(lsCommand19).addCommand(releaseCommand2);
|
|
9684
|
+
|
|
9685
|
+
// src/commands/k8s/rm.ts
|
|
9686
|
+
import { Command as Command123 } from "commander";
|
|
9687
|
+
var rmCommand17 = new Command123("rm").alias("remove").description("delete a cluster with everything running in it").argument("<name>", "cluster name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
9688
|
+
const client = await k8sClient(cmd);
|
|
9689
|
+
try {
|
|
9690
|
+
if (!await confirm(`Delete cluster ${name} with everything running in it?`, opts.yes ?? false)) {
|
|
9691
|
+
info("cancelled");
|
|
9692
|
+
process.exitCode = 1;
|
|
9693
|
+
return;
|
|
9694
|
+
}
|
|
9695
|
+
await spin(`deleting cluster ${name}\u2026`, client.deleteCluster(name));
|
|
9696
|
+
info(`${color.green("\u2713")} cluster ${name} deleted`);
|
|
9697
|
+
} finally {
|
|
9698
|
+
await client.close();
|
|
9699
|
+
}
|
|
9700
|
+
});
|
|
9701
|
+
|
|
9702
|
+
// src/commands/k8s/start.ts
|
|
9703
|
+
import { Command as Command124 } from "commander";
|
|
9704
|
+
var startCommand2 = new Command124("start").description("run a cluster's master and nodes again after they stopped").argument("<name>", "cluster name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
9705
|
+
const client = await k8sClient(cmd);
|
|
9706
|
+
try {
|
|
9707
|
+
const c2 = await spin(`starting cluster ${name}\u2026`, client.startCluster(name));
|
|
9708
|
+
if (opts.json) json(c2);
|
|
9709
|
+
else info(`${color.green("\u2713")} cluster ${shownName2(c2, client)} is ${c2.status}`);
|
|
9710
|
+
} finally {
|
|
9711
|
+
await client.close();
|
|
9712
|
+
}
|
|
9713
|
+
});
|
|
9714
|
+
|
|
9715
|
+
// src/commands/k8s/unlink.ts
|
|
9716
|
+
import { Command as Command125 } from "commander";
|
|
9717
|
+
var unlinkCommand2 = new Command125("unlink").description("take a cluster's link away (kvbox k8s link)").argument("<cluster>", "cluster name").argument("<target>", "the database or box it reaches").option("-p, --port <port>", "the port, when the cluster reaches several of that box's").option("-y, --yes", "do not ask for confirmation").option("--json", "print the removed link as JSON").action(async (cluster, target, opts, cmd) => {
|
|
9718
|
+
const port = opts.port === void 0 ? void 0 : parseLinkPort(opts.port);
|
|
9719
|
+
if (!await confirm(`Cut cluster ${cluster} off from ${target}${port !== void 0 ? ` port ${port}` : ""}? Its pods' open connections close too.`, opts.yes ?? false)) {
|
|
9720
|
+
info("cancelled");
|
|
9721
|
+
process.exitCode = 1;
|
|
9722
|
+
return;
|
|
9723
|
+
}
|
|
9724
|
+
const client = await k8sClient(cmd);
|
|
9725
|
+
try {
|
|
9726
|
+
const link2 = await spin(`unlinking ${cluster} from ${target}\u2026`, client.unlinkCluster(cluster, { to: target, ...port !== void 0 ? { port } : {} }));
|
|
9727
|
+
if (opts.json) {
|
|
9728
|
+
json(linkJson(link2, cluster));
|
|
9729
|
+
return;
|
|
9730
|
+
}
|
|
9731
|
+
info(`${color.green("\u2713")} cluster ${color.bold(cluster)} no longer reaches ${reachedText(link2)} port ${link2.port}`);
|
|
9732
|
+
} finally {
|
|
9733
|
+
await client.close();
|
|
9734
|
+
}
|
|
9735
|
+
});
|
|
9736
|
+
|
|
9737
|
+
// src/commands/k8s/index.ts
|
|
9738
|
+
var k8sCommand = new Command126("k8s").description("Kubernetes clusters kvbox runs for you").addCommand(createCommand10).addCommand(lsCommand17).addCommand(infoCommand2).addCommand(kubeconfigCommand).addCommand(poolCommand).addCommand(proxyCommand2).addCommand(domainCommand).addCommand(linkCommand2).addCommand(unlinkCommand2).addCommand(linksCommand2).addCommand(backupCommand4).addCommand(startCommand2).addCommand(rmCommand17);
|
|
9739
|
+
var withOrg3 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal clusters)");
|
|
9740
|
+
for (const cmd of k8sCommand.commands) {
|
|
9741
|
+
if (cmd.commands.length > 0) cmd.commands.forEach(withOrg3);
|
|
9742
|
+
else withOrg3(cmd);
|
|
9743
|
+
}
|
|
9744
|
+
|
|
9745
|
+
// src/commands/cron/index.ts
|
|
9746
|
+
import { Command as Command139 } from "commander";
|
|
9747
|
+
|
|
9748
|
+
// src/commands/cron/create.ts
|
|
9749
|
+
import { Command as Command127 } from "commander";
|
|
9750
|
+
|
|
9751
|
+
// src/commands/cron/shared.ts
|
|
9752
|
+
async function cronClient(cmd) {
|
|
9753
|
+
const client = await clientFor(cmd.optsWithGlobals());
|
|
9754
|
+
if (client.target.kind !== "cloud") {
|
|
9755
|
+
await client.close();
|
|
9756
|
+
throw new KvboxError("the cron service runs on the kvbox cloud: kvbox login first (on this host's own socket, use the box's own crontab)");
|
|
9757
|
+
}
|
|
9758
|
+
return client;
|
|
9759
|
+
}
|
|
9760
|
+
function shownName3(s, client) {
|
|
9761
|
+
const context = client.target.kind === "cloud" ? client.target.org ?? client.target.user : void 0;
|
|
9762
|
+
return s.owner === context ? s.name : `${s.owner}/${s.name}`;
|
|
9763
|
+
}
|
|
9764
|
+
function refFor(name, client) {
|
|
9765
|
+
if (client.target.kind !== "cloud" || name.includes("/")) return name;
|
|
9766
|
+
const { org, user } = client.target;
|
|
9767
|
+
return org && org !== user ? `${org}/${name}` : name;
|
|
9768
|
+
}
|
|
9769
|
+
var scheduleText = (t) => t.timezone === "UTC" ? t.expr : `${t.expr} (${t.timezone})`;
|
|
9770
|
+
function until(iso2, now = Date.now()) {
|
|
9771
|
+
const sec = Math.round((Date.parse(iso2) - now) / 1e3);
|
|
9772
|
+
return sec <= 0 ? "now" : `in ${duration(sec)}`;
|
|
9773
|
+
}
|
|
9774
|
+
function outcomeText(outcome) {
|
|
9775
|
+
const words = {
|
|
9776
|
+
running: "running",
|
|
9777
|
+
ok: "ok",
|
|
9778
|
+
failed: "failed",
|
|
9779
|
+
timeout: "timed out",
|
|
9780
|
+
"no-credit": "skipped: no credit",
|
|
9781
|
+
"box-stopped": "skipped: box stopped",
|
|
9782
|
+
"host-down": "host unreachable",
|
|
9783
|
+
"host-outdated": "host needs an update",
|
|
9784
|
+
lost: "lost",
|
|
9785
|
+
"still-running": "skipped: still running",
|
|
9786
|
+
"box-outdated": "box image too old"
|
|
9787
|
+
};
|
|
9788
|
+
const text2 = words[outcome];
|
|
9789
|
+
return outcome === "ok" ? color.green(text2) : outcome === "running" ? color.dim(text2) : color.red(text2);
|
|
9790
|
+
}
|
|
9791
|
+
function printTriggers(triggers) {
|
|
9792
|
+
table(
|
|
9793
|
+
triggers.map((t) => ({
|
|
9794
|
+
id: t.id,
|
|
9795
|
+
schedule: scheduleText(t),
|
|
9796
|
+
action: cronTarget(t),
|
|
9797
|
+
next: t.enabled ? t.nextRunAt ? until(t.nextRunAt) : "never" : color.yellow("paused"),
|
|
9798
|
+
"last run": t.lastRunAt && t.lastOutcome ? `${outcomeText(t.lastOutcome)} ${color.dim(age(t.lastRunAt))}` : "-"
|
|
9799
|
+
}))
|
|
9800
|
+
);
|
|
9801
|
+
}
|
|
9802
|
+
function printRows3(rows2) {
|
|
9803
|
+
const width2 = Math.max(...rows2.map(([label]) => label.length));
|
|
9804
|
+
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
9805
|
+
`);
|
|
9806
|
+
}
|
|
9807
|
+
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>")`);
|
|
9808
|
+
|
|
9809
|
+
// src/commands/cron/create.ts
|
|
9810
|
+
var createCommand11 = new Command127("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) => {
|
|
9811
|
+
const client = await cronClient(cmd);
|
|
9812
|
+
try {
|
|
9813
|
+
const service = await client.createCronService(name);
|
|
9814
|
+
if (opts.json) {
|
|
9815
|
+
json(service);
|
|
9816
|
+
return;
|
|
9817
|
+
}
|
|
9818
|
+
const shown = shownName3(service, client);
|
|
9819
|
+
info(`${color.green("\u2713")} cron service ${color.bold(shown)} made; it keeps the last ${service.keepRuns} runs of each trigger${service.price && service.price.perMonth > 0 ? `, ${money(service.price.perMonth, service.price.currency)} a month` : ""}`);
|
|
9820
|
+
info(color.dim(`Add a trigger: kvbox cron trigger add ${refFor(shown, client)} <box> "0 6 * * *" --port 3000 --path /tasks/daily`));
|
|
9821
|
+
} finally {
|
|
9822
|
+
await client.close();
|
|
9823
|
+
}
|
|
9824
|
+
});
|
|
9825
|
+
|
|
9826
|
+
// src/commands/cron/info.ts
|
|
9827
|
+
import { Command as Command128 } from "commander";
|
|
9828
|
+
var infoCommand3 = new Command128("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) => {
|
|
9829
|
+
const client = await cronClient(cmd);
|
|
9830
|
+
try {
|
|
9831
|
+
const service = await client.getCronService(name);
|
|
9832
|
+
const triggers = await client.listCronTriggers(name);
|
|
9833
|
+
if (opts.json) {
|
|
9834
|
+
json({ ...service, triggerList: triggers });
|
|
9835
|
+
return;
|
|
9836
|
+
}
|
|
9837
|
+
printRows3([
|
|
9838
|
+
["name", shownName3(service, client)],
|
|
9839
|
+
["triggers", String(service.triggers)],
|
|
9840
|
+
["runs kept", `the last ${service.keepRuns} of each trigger`],
|
|
9841
|
+
["made", `${age(service.createdAt)}${service.createdBy ? ` by ${service.createdBy}` : ""}`]
|
|
9842
|
+
]);
|
|
9843
|
+
process.stdout.write("\n");
|
|
9844
|
+
if (triggers.length === 0) noTriggers(refFor(name, client));
|
|
9845
|
+
else printTriggers(triggers);
|
|
9846
|
+
} finally {
|
|
9847
|
+
await client.close();
|
|
9848
|
+
}
|
|
9849
|
+
});
|
|
9850
|
+
|
|
9851
|
+
// src/commands/cron/ls.ts
|
|
9852
|
+
import { Command as Command129 } from "commander";
|
|
9853
|
+
var lsCommand20 = new Command129("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) => {
|
|
9854
|
+
const client = await cronClient(cmd);
|
|
9855
|
+
try {
|
|
9856
|
+
const services = await client.listCronServices({ all: opts.all });
|
|
9857
|
+
if (opts.json) {
|
|
9858
|
+
json(services);
|
|
9859
|
+
return;
|
|
9860
|
+
}
|
|
9861
|
+
if (services.length === 0) {
|
|
9862
|
+
info("no cron services yet; make one with: kvbox cron create <name>");
|
|
9863
|
+
return;
|
|
9864
|
+
}
|
|
9865
|
+
const me2 = client.target.kind === "cloud" ? client.target.user : void 0;
|
|
9866
|
+
table(services.map((s) => ({ owner: s.owner === me2 ? "private" : s.owner, name: s.name, triggers: s.triggers, "runs kept": s.keepRuns, created: age(s.createdAt) })));
|
|
9867
|
+
} finally {
|
|
9868
|
+
await client.close();
|
|
9869
|
+
}
|
|
9870
|
+
});
|
|
9871
|
+
|
|
9872
|
+
// src/commands/cron/rm.ts
|
|
9873
|
+
import { Command as Command130 } from "commander";
|
|
9874
|
+
var rmCommand18 = new Command130("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) => {
|
|
9875
|
+
const client = await cronClient(cmd);
|
|
9876
|
+
try {
|
|
9877
|
+
if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
|
|
9878
|
+
info("cancelled");
|
|
9879
|
+
process.exitCode = 1;
|
|
9880
|
+
return;
|
|
9881
|
+
}
|
|
9882
|
+
await client.deleteCronService(name);
|
|
9883
|
+
info(`${color.green("\u2713")} cron service ${name} deleted`);
|
|
9884
|
+
} finally {
|
|
9885
|
+
await client.close();
|
|
9886
|
+
}
|
|
9887
|
+
});
|
|
9888
|
+
|
|
9889
|
+
// src/commands/cron/trigger/index.ts
|
|
9890
|
+
import { Command as Command138 } from "commander";
|
|
9891
|
+
|
|
9892
|
+
// src/commands/cron/trigger/add.ts
|
|
9893
|
+
import { Command as Command131 } from "commander";
|
|
8819
9894
|
function portOf(value) {
|
|
8820
9895
|
const n2 = Number(value);
|
|
8821
9896
|
if (!Number.isInteger(n2) || n2 < 1 || n2 > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
|
|
@@ -8835,7 +9910,7 @@ function timeoutOf(value) {
|
|
|
8835
9910
|
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`);
|
|
8836
9911
|
return sec;
|
|
8837
9912
|
}
|
|
8838
|
-
var
|
|
9913
|
+
var addCommand5 = new Command131("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) => {
|
|
8839
9914
|
let action;
|
|
8840
9915
|
if (opts.run !== void 0) {
|
|
8841
9916
|
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");
|
|
@@ -8862,8 +9937,8 @@ var addCommand3 = new Command102("add").description("add a trigger: on a schedul
|
|
|
8862
9937
|
});
|
|
8863
9938
|
|
|
8864
9939
|
// src/commands/cron/trigger/ls.ts
|
|
8865
|
-
import { Command as
|
|
8866
|
-
var
|
|
9940
|
+
import { Command as Command132 } from "commander";
|
|
9941
|
+
var lsCommand21 = new Command132("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) => {
|
|
8867
9942
|
const client = await cronClient(cmd);
|
|
8868
9943
|
try {
|
|
8869
9944
|
const triggers = await client.listCronTriggers(service);
|
|
@@ -8879,8 +9954,8 @@ var lsCommand16 = new Command103("ls").alias("list").description("list a cron se
|
|
|
8879
9954
|
});
|
|
8880
9955
|
|
|
8881
9956
|
// src/commands/cron/trigger/pause.ts
|
|
8882
|
-
import { Command as
|
|
8883
|
-
var pauseCommand2 = new
|
|
9957
|
+
import { Command as Command133 } from "commander";
|
|
9958
|
+
var pauseCommand2 = new Command133("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) => {
|
|
8884
9959
|
const client = await cronClient(cmd);
|
|
8885
9960
|
try {
|
|
8886
9961
|
const trigger = await client.setCronTriggerEnabled(service, id, false);
|
|
@@ -8895,8 +9970,8 @@ var pauseCommand2 = new Command104("pause").description("stop a trigger from fir
|
|
|
8895
9970
|
});
|
|
8896
9971
|
|
|
8897
9972
|
// src/commands/cron/trigger/resume.ts
|
|
8898
|
-
import { Command as
|
|
8899
|
-
var resumeCommand2 = new
|
|
9973
|
+
import { Command as Command134 } from "commander";
|
|
9974
|
+
var resumeCommand2 = new Command134("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) => {
|
|
8900
9975
|
const client = await cronClient(cmd);
|
|
8901
9976
|
try {
|
|
8902
9977
|
const trigger = await client.setCronTriggerEnabled(service, id, true);
|
|
@@ -8911,8 +9986,8 @@ var resumeCommand2 = new Command105("resume").description("let a paused trigger
|
|
|
8911
9986
|
});
|
|
8912
9987
|
|
|
8913
9988
|
// src/commands/cron/trigger/rm.ts
|
|
8914
|
-
import { Command as
|
|
8915
|
-
var
|
|
9989
|
+
import { Command as Command135 } from "commander";
|
|
9990
|
+
var rmCommand19 = new Command135("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) => {
|
|
8916
9991
|
const client = await cronClient(cmd);
|
|
8917
9992
|
try {
|
|
8918
9993
|
if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
|
|
@@ -8928,8 +10003,8 @@ var rmCommand15 = new Command106("rm").alias("remove").description("delete a tri
|
|
|
8928
10003
|
});
|
|
8929
10004
|
|
|
8930
10005
|
// src/commands/cron/trigger/run.ts
|
|
8931
|
-
import { Command as
|
|
8932
|
-
var runCommand = new
|
|
10006
|
+
import { Command as Command136 } from "commander";
|
|
10007
|
+
var runCommand = new Command136("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) => {
|
|
8933
10008
|
const client = await cronClient(cmd);
|
|
8934
10009
|
try {
|
|
8935
10010
|
const trigger = await client.runCronTrigger(service, id);
|
|
@@ -8945,13 +10020,13 @@ var runCommand = new Command107("run").description("fire a trigger now, once, be
|
|
|
8945
10020
|
});
|
|
8946
10021
|
|
|
8947
10022
|
// src/commands/cron/trigger/runs.ts
|
|
8948
|
-
import { Command as
|
|
10023
|
+
import { Command as Command137 } from "commander";
|
|
8949
10024
|
function limitOf(value) {
|
|
8950
10025
|
const n2 = Number(value);
|
|
8951
10026
|
if (!Number.isInteger(n2) || n2 < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
|
|
8952
10027
|
return n2;
|
|
8953
10028
|
}
|
|
8954
|
-
var runsCommand = new
|
|
10029
|
+
var runsCommand = new Command137("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) => {
|
|
8955
10030
|
const limit = limitOf(opts.limit);
|
|
8956
10031
|
const client = await cronClient(cmd);
|
|
8957
10032
|
try {
|
|
@@ -8981,24 +10056,24 @@ var runsCommand = new Command108("runs").aliases(["logs"]).description("show how
|
|
|
8981
10056
|
});
|
|
8982
10057
|
|
|
8983
10058
|
// src/commands/cron/trigger/index.ts
|
|
8984
|
-
var triggerCommand = new
|
|
10059
|
+
var triggerCommand = new Command138("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand5).addCommand(lsCommand21).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand19);
|
|
8985
10060
|
|
|
8986
10061
|
// src/commands/cron/index.ts
|
|
8987
|
-
var cronCommand = new
|
|
8988
|
-
var
|
|
10062
|
+
var cronCommand = new Command139("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand11).addCommand(lsCommand20).addCommand(infoCommand3).addCommand(rmCommand18).addCommand(triggerCommand);
|
|
10063
|
+
var withOrg4 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
|
|
8989
10064
|
for (const cmd of cronCommand.commands) {
|
|
8990
|
-
if (cmd === triggerCommand) cmd.commands.forEach(
|
|
8991
|
-
else
|
|
10065
|
+
if (cmd === triggerCommand) cmd.commands.forEach(withOrg4);
|
|
10066
|
+
else withOrg4(cmd);
|
|
8992
10067
|
}
|
|
8993
10068
|
|
|
8994
10069
|
// src/commands/managed/kind.ts
|
|
8995
|
-
import { Command as
|
|
10070
|
+
import { Command as Command158 } from "commander";
|
|
8996
10071
|
|
|
8997
10072
|
// src/commands/managed/backup/index.ts
|
|
8998
|
-
import { Command as
|
|
10073
|
+
import { Command as Command146 } from "commander";
|
|
8999
10074
|
|
|
9000
10075
|
// src/commands/managed/backup/create.ts
|
|
9001
|
-
import { Command as
|
|
10076
|
+
import { Command as Command141 } from "commander";
|
|
9002
10077
|
|
|
9003
10078
|
// src/commands/managed/shared.ts
|
|
9004
10079
|
import "commander";
|
|
@@ -9030,7 +10105,7 @@ async function managedClient(cmd) {
|
|
|
9030
10105
|
}
|
|
9031
10106
|
return client;
|
|
9032
10107
|
}
|
|
9033
|
-
var
|
|
10108
|
+
var shownName4 = (m, user) => m.owner === user ? m.name : `${m.owner}/${m.name}`;
|
|
9034
10109
|
var storageText = (m) => m.health?.storageUsedBytes !== void 0 ? `${gb(m.health.storageUsedBytes)} of ${m.storageGib} GB used` : `${m.storageGib} GB`;
|
|
9035
10110
|
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;
|
|
9036
10111
|
function stateText(m) {
|
|
@@ -9041,7 +10116,7 @@ function stateText(m) {
|
|
|
9041
10116
|
return `${status(m.status)}, ${m.health.accepting ? "accepting connections" : color.yellow("not accepting connections")}`;
|
|
9042
10117
|
}
|
|
9043
10118
|
function infoRows(spec, m, user) {
|
|
9044
|
-
const name =
|
|
10119
|
+
const name = shownName4(m, user);
|
|
9045
10120
|
const rows2 = [
|
|
9046
10121
|
["name", color.bold(name)],
|
|
9047
10122
|
["status", stateText(m)],
|
|
@@ -9061,7 +10136,7 @@ function infoRows(spec, m, user) {
|
|
|
9061
10136
|
function scheduleText2(spec, name, s, now = Date.now()) {
|
|
9062
10137
|
return scheduleLine(`kvbox ${spec.command} backup schedule ${name}`, s, now);
|
|
9063
10138
|
}
|
|
9064
|
-
function
|
|
10139
|
+
function printRows4(rows2) {
|
|
9065
10140
|
const width2 = Math.max(...rows2.map(([label]) => label.length));
|
|
9066
10141
|
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
9067
10142
|
`);
|
|
@@ -9085,7 +10160,7 @@ function parseStorage(text2, flag) {
|
|
|
9085
10160
|
}
|
|
9086
10161
|
|
|
9087
10162
|
// src/commands/managed/backup/create.ts
|
|
9088
|
-
var
|
|
10163
|
+
var createCommand12 = (spec) => new Command141("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) => {
|
|
9089
10164
|
const client = await managedClient(cmd);
|
|
9090
10165
|
const ls = `kvbox ${spec.command} backup ls ${name}`;
|
|
9091
10166
|
try {
|
|
@@ -9112,8 +10187,8 @@ var createCommand10 = (spec) => new Command112("create").description("back up a
|
|
|
9112
10187
|
});
|
|
9113
10188
|
|
|
9114
10189
|
// src/commands/managed/backup/ls.ts
|
|
9115
|
-
import { Command as
|
|
9116
|
-
var
|
|
10190
|
+
import { Command as Command142 } from "commander";
|
|
10191
|
+
var lsCommand22 = (spec) => {
|
|
9117
10192
|
const removedOnes = async (err, name, client) => {
|
|
9118
10193
|
if (!(err instanceof CallError && err.status === 404)) throw err;
|
|
9119
10194
|
const gone = (await client.listManagedBackups(spec.kind)).filter((b) => b.name === name || `${b.owner}/${b.name}` === name);
|
|
@@ -9121,7 +10196,7 @@ var lsCommand17 = (spec) => {
|
|
|
9121
10196
|
const own = name.includes("/") ? [] : gone.filter((b) => b.owner === me(client));
|
|
9122
10197
|
return own.length > 0 ? own : gone;
|
|
9123
10198
|
};
|
|
9124
|
-
return new
|
|
10199
|
+
return new Command142("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) => {
|
|
9125
10200
|
const client = await managedClient(cmd);
|
|
9126
10201
|
try {
|
|
9127
10202
|
const list = name === void 0 ? await client.listManagedBackups(spec.kind) : await client.managedBackups(spec.kind, name).catch((err) => removedOnes(err, name, client));
|
|
@@ -9164,8 +10239,8 @@ var lsCommand17 = (spec) => {
|
|
|
9164
10239
|
};
|
|
9165
10240
|
|
|
9166
10241
|
// src/commands/managed/backup/restore.ts
|
|
9167
|
-
import { Command as
|
|
9168
|
-
var
|
|
10242
|
+
import { Command as Command143 } from "commander";
|
|
10243
|
+
var restoreCommand5 = (spec) => new Command143("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) => {
|
|
9169
10244
|
const client = await managedClient(cmd);
|
|
9170
10245
|
try {
|
|
9171
10246
|
const backup = await client.managedBackup(spec.kind, name, id);
|
|
@@ -9187,8 +10262,8 @@ var restoreCommand4 = (spec) => new Command114("restore").description("put a bac
|
|
|
9187
10262
|
});
|
|
9188
10263
|
|
|
9189
10264
|
// src/commands/managed/backup/rm.ts
|
|
9190
|
-
import { Command as
|
|
9191
|
-
var
|
|
10265
|
+
import { Command as Command144 } from "commander";
|
|
10266
|
+
var rmCommand20 = (spec) => new Command144("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) => {
|
|
9192
10267
|
const client = await managedClient(cmd);
|
|
9193
10268
|
try {
|
|
9194
10269
|
await removeListed(client, await client.listManagedBackups(spec.kind), (b) => b.name, name, id, `database ${name}`, opts.yes ?? false);
|
|
@@ -9198,8 +10273,8 @@ var rmCommand16 = (spec) => new Command115("rm").alias("remove").description("re
|
|
|
9198
10273
|
});
|
|
9199
10274
|
|
|
9200
10275
|
// src/commands/managed/backup/schedule.ts
|
|
9201
|
-
import { Command as
|
|
9202
|
-
var
|
|
10276
|
+
import { Command as Command145 } from "commander";
|
|
10277
|
+
var scheduleCommand5 = (spec) => scheduleFlags(new Command145("schedule").description("show or change when a database is backed up on its own (daily, UTC)").argument("<db>", "its name")).action(
|
|
9203
10278
|
async (name, flags, cmd) => {
|
|
9204
10279
|
const change = changeOf(flags);
|
|
9205
10280
|
const client = await managedClient(cmd);
|
|
@@ -9214,19 +10289,19 @@ var scheduleCommand4 = (spec) => scheduleFlags(new Command116("schedule").descri
|
|
|
9214
10289
|
);
|
|
9215
10290
|
|
|
9216
10291
|
// src/commands/managed/backup/index.ts
|
|
9217
|
-
var
|
|
9218
|
-
const command = new
|
|
9219
|
-
for (const make of [
|
|
10292
|
+
var backupCommand5 = (spec) => {
|
|
10293
|
+
const command = new Command146("backup").description("back up a database to the kvbox cloud, list backups, restore or remove one, or change its nightly schedule");
|
|
10294
|
+
for (const make of [createCommand12, lsCommand22, restoreCommand5, rmCommand20, scheduleCommand5]) command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
9220
10295
|
return command;
|
|
9221
10296
|
};
|
|
9222
10297
|
|
|
9223
10298
|
// src/commands/managed/create.ts
|
|
9224
|
-
import { Command as
|
|
10299
|
+
import { Command as Command147 } from "commander";
|
|
9225
10300
|
import { setTimeout as sleep5 } from "timers/promises";
|
|
9226
|
-
var
|
|
10301
|
+
var READY_WAIT_MS2 = 9e4;
|
|
9227
10302
|
var READY_STEP_MS = 2e3;
|
|
9228
|
-
var
|
|
9229
|
-
const command = new
|
|
10303
|
+
var createCommand13 = (spec) => {
|
|
10304
|
+
const command = new Command147("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");
|
|
9230
10305
|
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
9231
10306
|
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 a link between them stays on that host").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) => {
|
|
9232
10307
|
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
@@ -9242,14 +10317,14 @@ var createCommand11 = (spec) => {
|
|
|
9242
10317
|
try {
|
|
9243
10318
|
const doing = opts.fromBackup === void 0 ? `creating ${spec.title} database ${name}\u2026` : `creating ${spec.title} database ${name} from backup ${opts.fromBackup}\u2026`;
|
|
9244
10319
|
const made = await spin(doing, client.createManaged(spec.kind, req));
|
|
9245
|
-
const shown =
|
|
10320
|
+
const shown = shownName4(made, me(client));
|
|
9246
10321
|
if (opts.fromBackup !== void 0 && made.fromBackup === void 0) {
|
|
9247
10322
|
throw new KvboxError(
|
|
9248
10323
|
`this control plane does not know --from-backup yet: database ${shown} was made empty, not from backup ${opts.fromBackup}; remove it with: kvbox ${spec.command} rm ${shown}`
|
|
9249
10324
|
);
|
|
9250
10325
|
}
|
|
9251
10326
|
const ready = await spin(`starting ${spec.title}\u2026`, async () => {
|
|
9252
|
-
for (const until2 = Date.now() +
|
|
10327
|
+
for (const until2 = Date.now() + READY_WAIT_MS2; Date.now() < until2; await sleep5(READY_STEP_MS)) {
|
|
9253
10328
|
const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
|
|
9254
10329
|
if (now?.health?.ready && now.health.accepting) return true;
|
|
9255
10330
|
}
|
|
@@ -9261,13 +10336,13 @@ var createCommand11 = (spec) => {
|
|
|
9261
10336
|
}
|
|
9262
10337
|
const restored = made.fromBackup === void 0 ? "" : `, the data of backup ${made.fromBackup}`;
|
|
9263
10338
|
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${restored})`)}`);
|
|
9264
|
-
|
|
10339
|
+
printRows4([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
|
|
9265
10340
|
info("");
|
|
9266
10341
|
info("Nobody can reach it yet. To let something in:");
|
|
9267
10342
|
info(` a box of yours kvbox ${spec.command} link ${shown} <box> ${color.dim(`(a new one right next to it: kvbox new <box> --near ${shown})`)}`);
|
|
9268
10343
|
info(` the internet kvbox ${spec.command} public ${shown} on`);
|
|
9269
10344
|
info(color.dim(`It costs about ${money(made.price.perMonth, made.price.currency)} a month while it runs, ${money(made.price.storagePerMonth, made.price.currency)} stopped. The password again: kvbox ${spec.command} password ${shown}`));
|
|
9270
|
-
if (!ready) info(color.dim(`It was not answering after ${
|
|
10345
|
+
if (!ready) info(color.dim(`It was not answering after ${READY_WAIT_MS2 / 1e3} s; see how it is with: kvbox ${spec.command} info ${shown}`));
|
|
9271
10346
|
} finally {
|
|
9272
10347
|
await client.close();
|
|
9273
10348
|
}
|
|
@@ -9275,8 +10350,8 @@ var createCommand11 = (spec) => {
|
|
|
9275
10350
|
};
|
|
9276
10351
|
|
|
9277
10352
|
// src/commands/managed/grow.ts
|
|
9278
|
-
import { Command as
|
|
9279
|
-
var growCommand3 = (spec) => new
|
|
10353
|
+
import { Command as Command148 } from "commander";
|
|
10354
|
+
var growCommand3 = (spec) => new Command148("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) => {
|
|
9280
10355
|
const storageGib = parseStorage(size, "size");
|
|
9281
10356
|
const client = await managedClient(cmd);
|
|
9282
10357
|
try {
|
|
@@ -9289,21 +10364,21 @@ var growCommand3 = (spec) => new Command119("grow").description("give a database
|
|
|
9289
10364
|
});
|
|
9290
10365
|
|
|
9291
10366
|
// src/commands/managed/info.ts
|
|
9292
|
-
import { Command as
|
|
9293
|
-
var
|
|
10367
|
+
import { Command as Command149 } from "commander";
|
|
10368
|
+
var infoCommand4 = (spec) => new Command149("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) => {
|
|
9294
10369
|
const client = await managedClient(cmd);
|
|
9295
10370
|
try {
|
|
9296
10371
|
const m = await client.getManaged(spec.kind, name);
|
|
9297
10372
|
if (opts.json) json(m);
|
|
9298
|
-
else
|
|
10373
|
+
else printRows4(infoRows(spec, m, me(client)));
|
|
9299
10374
|
} finally {
|
|
9300
10375
|
await client.close();
|
|
9301
10376
|
}
|
|
9302
10377
|
});
|
|
9303
10378
|
|
|
9304
10379
|
// src/commands/managed/link.ts
|
|
9305
|
-
import { Command as
|
|
9306
|
-
var
|
|
10380
|
+
import { Command as Command150 } from "commander";
|
|
10381
|
+
var linkCommand3 = (spec) => new Command150("link").description("let a box reach a database privately").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box2, opts, cmd) => {
|
|
9307
10382
|
const client = await managedClient(cmd);
|
|
9308
10383
|
try {
|
|
9309
10384
|
const m = await spin(`linking ${box2} to ${name}\u2026`, client.linkManaged(spec.kind, name, box2));
|
|
@@ -9319,7 +10394,7 @@ var linkCommand2 = (spec) => new Command121("link").description("let a box reach
|
|
|
9319
10394
|
});
|
|
9320
10395
|
|
|
9321
10396
|
// src/commands/managed/ls.ts
|
|
9322
|
-
import { Command as
|
|
10397
|
+
import { Command as Command151 } from "commander";
|
|
9323
10398
|
function listRows(items, user, kindColumn) {
|
|
9324
10399
|
return items.map((m) => ({
|
|
9325
10400
|
owner: m.owner === user ? "private" : m.owner,
|
|
@@ -9333,7 +10408,7 @@ function listRows(items, user, kindColumn) {
|
|
|
9333
10408
|
created: age(m.createdAt)
|
|
9334
10409
|
}));
|
|
9335
10410
|
}
|
|
9336
|
-
var
|
|
10411
|
+
var lsCommand23 = (spec) => new Command151("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) => {
|
|
9337
10412
|
const client = await managedClient(cmd);
|
|
9338
10413
|
try {
|
|
9339
10414
|
const items = await client.listManaged(spec?.kind, { all: opts.all });
|
|
@@ -9353,8 +10428,8 @@ var lsCommand18 = (spec) => new Command122("ls").alias("list").description(spec
|
|
|
9353
10428
|
});
|
|
9354
10429
|
|
|
9355
10430
|
// src/commands/managed/password.ts
|
|
9356
|
-
import { Command as
|
|
9357
|
-
var passwordCommand = (spec) => new
|
|
10431
|
+
import { Command as Command152 } from "commander";
|
|
10432
|
+
var passwordCommand = (spec) => new Command152("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) => {
|
|
9358
10433
|
const client = await managedClient(cmd);
|
|
9359
10434
|
try {
|
|
9360
10435
|
const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
|
|
@@ -9363,15 +10438,15 @@ var passwordCommand = (spec) => new Command123("password").description("show a d
|
|
|
9363
10438
|
return;
|
|
9364
10439
|
}
|
|
9365
10440
|
if (opts.reset) info(`${color.green("\u2713")} database ${name} has a new password; the old one no longer works`);
|
|
9366
|
-
|
|
10441
|
+
printRows4(secretRows(secret));
|
|
9367
10442
|
} finally {
|
|
9368
10443
|
await client.close();
|
|
9369
10444
|
}
|
|
9370
10445
|
});
|
|
9371
10446
|
|
|
9372
10447
|
// src/commands/managed/public.ts
|
|
9373
|
-
import { Command as
|
|
9374
|
-
var publicCommand2 = (spec) => new
|
|
10448
|
+
import { Command as Command153 } from "commander";
|
|
10449
|
+
var publicCommand2 = (spec) => new Command153("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) => {
|
|
9375
10450
|
if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
|
|
9376
10451
|
const client = await managedClient(cmd);
|
|
9377
10452
|
try {
|
|
@@ -9392,8 +10467,8 @@ var publicCommand2 = (spec) => new Command124("public").description("open a data
|
|
|
9392
10467
|
});
|
|
9393
10468
|
|
|
9394
10469
|
// src/commands/managed/rm.ts
|
|
9395
|
-
import { Command as
|
|
9396
|
-
var
|
|
10470
|
+
import { Command as Command154 } from "commander";
|
|
10471
|
+
var rmCommand21 = (spec) => new Command154("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) => {
|
|
9397
10472
|
const client = await managedClient(cmd);
|
|
9398
10473
|
try {
|
|
9399
10474
|
if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
|
|
@@ -9409,8 +10484,8 @@ var rmCommand17 = (spec) => new Command125("rm").alias("remove").description("de
|
|
|
9409
10484
|
});
|
|
9410
10485
|
|
|
9411
10486
|
// src/commands/managed/start.ts
|
|
9412
|
-
import { Command as
|
|
9413
|
-
var
|
|
10487
|
+
import { Command as Command155 } from "commander";
|
|
10488
|
+
var startCommand3 = (spec) => new Command155("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
9414
10489
|
const client = await managedClient(cmd);
|
|
9415
10490
|
try {
|
|
9416
10491
|
const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
|
|
@@ -9422,8 +10497,8 @@ var startCommand2 = (spec) => new Command126("start").description("run a stopped
|
|
|
9422
10497
|
});
|
|
9423
10498
|
|
|
9424
10499
|
// src/commands/managed/stop.ts
|
|
9425
|
-
import { Command as
|
|
9426
|
-
var stopCommand2 = (spec) => new
|
|
10500
|
+
import { Command as Command156 } from "commander";
|
|
10501
|
+
var stopCommand2 = (spec) => new Command156("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) => {
|
|
9427
10502
|
const client = await managedClient(cmd);
|
|
9428
10503
|
try {
|
|
9429
10504
|
const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
|
|
@@ -9435,8 +10510,8 @@ var stopCommand2 = (spec) => new Command127("stop").description("shut a database
|
|
|
9435
10510
|
});
|
|
9436
10511
|
|
|
9437
10512
|
// src/commands/managed/unlink.ts
|
|
9438
|
-
import { Command as
|
|
9439
|
-
var
|
|
10513
|
+
import { Command as Command157 } from "commander";
|
|
10514
|
+
var unlinkCommand3 = (spec) => new Command157("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) => {
|
|
9440
10515
|
const client = await managedClient(cmd);
|
|
9441
10516
|
try {
|
|
9442
10517
|
const m = await spin(`unlinking ${box2} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box2));
|
|
@@ -9449,11 +10524,11 @@ var unlinkCommand2 = (spec) => new Command128("unlink").description("stop a box
|
|
|
9449
10524
|
|
|
9450
10525
|
// src/commands/managed/kind.ts
|
|
9451
10526
|
function kindCommand(spec, description) {
|
|
9452
|
-
const command = new
|
|
9453
|
-
for (const make of [
|
|
10527
|
+
const command = new Command158(spec.command).aliases(spec.aliases).description(description);
|
|
10528
|
+
for (const make of [createCommand13, lsCommand23, infoCommand4, passwordCommand, publicCommand2, linkCommand3, unlinkCommand3, growCommand3, stopCommand2, startCommand3, rmCommand21]) {
|
|
9454
10529
|
command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
9455
10530
|
}
|
|
9456
|
-
command.addCommand(
|
|
10531
|
+
command.addCommand(backupCommand5(spec));
|
|
9457
10532
|
return command;
|
|
9458
10533
|
}
|
|
9459
10534
|
|
|
@@ -9464,17 +10539,17 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
|
|
|
9464
10539
|
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
9465
10540
|
|
|
9466
10541
|
// src/commands/managed/index.ts
|
|
9467
|
-
import { Command as
|
|
9468
|
-
var managedCommand = new
|
|
10542
|
+
import { Command as Command159 } from "commander";
|
|
10543
|
+
var managedCommand = new Command159("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand23().option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
9469
10544
|
|
|
9470
10545
|
// src/commands/env/index.ts
|
|
9471
|
-
import { Command as
|
|
10546
|
+
import { Command as Command163 } from "commander";
|
|
9472
10547
|
|
|
9473
10548
|
// src/commands/env/ls.ts
|
|
9474
|
-
import { Command as
|
|
10549
|
+
import { Command as Command160 } from "commander";
|
|
9475
10550
|
|
|
9476
10551
|
// src/commands/env/shared.ts
|
|
9477
|
-
function
|
|
10552
|
+
function requireCloud5(client) {
|
|
9478
10553
|
if (client.target.kind === "local") throw new KvboxError("kvbox env needs kvbox.sh: kvbox login first");
|
|
9479
10554
|
return client.target.org ?? client.target.user ?? "you";
|
|
9480
10555
|
}
|
|
@@ -9498,7 +10573,7 @@ function firstBootHint(box2, name) {
|
|
|
9498
10573
|
}
|
|
9499
10574
|
|
|
9500
10575
|
// src/commands/env/ls.ts
|
|
9501
|
-
var
|
|
10576
|
+
var lsCommand24 = new Command160("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) => {
|
|
9502
10577
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
9503
10578
|
try {
|
|
9504
10579
|
if (opts.box !== void 0) {
|
|
@@ -9520,7 +10595,7 @@ var lsCommand19 = new Command131("ls").alias("list").description("list the varia
|
|
|
9520
10595
|
table([...own.vars.map((v) => row(v, "box")), ...inherited.map((v) => row(v, color.dim(slug)))]);
|
|
9521
10596
|
return;
|
|
9522
10597
|
}
|
|
9523
|
-
const owner =
|
|
10598
|
+
const owner = requireCloud5(client);
|
|
9524
10599
|
const vars = await client.listEnv();
|
|
9525
10600
|
if (opts.json) {
|
|
9526
10601
|
json(vars);
|
|
@@ -9537,12 +10612,12 @@ var lsCommand19 = new Command131("ls").alias("list").description("list the varia
|
|
|
9537
10612
|
});
|
|
9538
10613
|
|
|
9539
10614
|
// src/commands/env/rm.ts
|
|
9540
|
-
import { Command as
|
|
9541
|
-
var
|
|
10615
|
+
import { Command as Command161 } from "commander";
|
|
10616
|
+
var rmCommand22 = new Command161("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) => {
|
|
9542
10617
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
9543
10618
|
try {
|
|
9544
10619
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
9545
|
-
const owner = target === void 0 ?
|
|
10620
|
+
const owner = target === void 0 ? requireCloud5(client) : `box ${target.ref}`;
|
|
9546
10621
|
if (!await confirm(`Remove ${names2.join(", ")} from ${owner}'s variables?`, opts.yes ?? false)) {
|
|
9547
10622
|
info("cancelled");
|
|
9548
10623
|
process.exitCode = 1;
|
|
@@ -9575,11 +10650,11 @@ var rmCommand18 = new Command132("rm").alias("remove").description("remove varia
|
|
|
9575
10650
|
});
|
|
9576
10651
|
|
|
9577
10652
|
// src/commands/env/set.ts
|
|
9578
|
-
import { Command as
|
|
9579
|
-
var setCommand2 = new
|
|
10653
|
+
import { Command as Command162 } from "commander";
|
|
10654
|
+
var setCommand2 = new Command162("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) => {
|
|
9580
10655
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
9581
10656
|
try {
|
|
9582
|
-
const owner = opts.box === void 0 ?
|
|
10657
|
+
const owner = opts.box === void 0 ? requireCloud5(client) : void 0;
|
|
9583
10658
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
9584
10659
|
const ask = interactive();
|
|
9585
10660
|
if ((nameArg === void 0 || valueArg === void 0) && !ask) throw new KvboxError("give the name and the value: kvbox env set NAME VALUE (or run it in a terminal to be asked)");
|
|
@@ -9613,39 +10688,20 @@ var setCommand2 = new Command133("set").description("add or change a variable; b
|
|
|
9613
10688
|
});
|
|
9614
10689
|
|
|
9615
10690
|
// src/commands/env/index.ts
|
|
9616
|
-
var envCommand = new
|
|
10691
|
+
var envCommand = new Command163("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand24, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand22);
|
|
9617
10692
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
9618
10693
|
|
|
9619
10694
|
// src/commands/domain/index.ts
|
|
9620
|
-
import { Command as
|
|
10695
|
+
import { Command as Command167 } from "commander";
|
|
9621
10696
|
|
|
9622
10697
|
// src/commands/domain/add.ts
|
|
9623
|
-
import { Command as
|
|
9624
|
-
|
|
9625
|
-
// src/commands/domain/shared.ts
|
|
9626
|
-
function requireCloud5(client) {
|
|
9627
|
-
if (client.target.kind !== "cloud") throw new KvboxError("custom domains need the kvbox cloud: kvbox login (this host's own socket has none)");
|
|
9628
|
-
}
|
|
9629
|
-
var boxOf2 = (d, user) => user !== void 0 && d.owner !== user ? `${d.owner}/${d.box}` : d.box;
|
|
9630
|
-
function domainJson(d, user) {
|
|
9631
|
-
return { domain: d.domain, box: boxOf2(d, user), port: d.port, status: d.status, www: d.www, url: d.url, error: d.error, records: d.records, createdAt: d.createdAt };
|
|
9632
|
-
}
|
|
9633
|
-
function zoneOf(domain) {
|
|
9634
|
-
const labels = domain.split(".");
|
|
9635
|
-
const n2 = labels.length > 2 && labels.at(-1).length === 2 && labels.at(-2).length <= 3 ? 3 : 2;
|
|
9636
|
-
return labels.slice(-n2).join(".");
|
|
9637
|
-
}
|
|
9638
|
-
function hostIn(name, zone) {
|
|
9639
|
-
return name === zone ? "@" : name.endsWith(`.${zone}`) ? name.slice(0, -(zone.length + 1)) : name;
|
|
9640
|
-
}
|
|
9641
|
-
|
|
9642
|
-
// src/commands/domain/add.ts
|
|
9643
|
-
var addCommand4 = new Command135("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) => {
|
|
10698
|
+
import { Command as Command164 } from "commander";
|
|
10699
|
+
var addCommand6 = new Command164("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) => {
|
|
9644
10700
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
9645
10701
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
9646
10702
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
9647
10703
|
try {
|
|
9648
|
-
|
|
10704
|
+
requireCloud4(client);
|
|
9649
10705
|
const user = me(client);
|
|
9650
10706
|
const box2 = displayName(await findBox(client, name), user);
|
|
9651
10707
|
const d = await spin(`adding ${domain}\u2026`, client.addDomain(box2, { domain, ...port !== void 0 ? { port } : {} }));
|
|
@@ -9676,11 +10732,11 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
9676
10732
|
});
|
|
9677
10733
|
|
|
9678
10734
|
// src/commands/domain/ls.ts
|
|
9679
|
-
import { Command as
|
|
9680
|
-
var
|
|
10735
|
+
import { Command as Command165 } from "commander";
|
|
10736
|
+
var lsCommand25 = new Command165("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
9681
10737
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
9682
10738
|
try {
|
|
9683
|
-
|
|
10739
|
+
requireCloud4(client);
|
|
9684
10740
|
const user = me(client);
|
|
9685
10741
|
const domains = await client.listDomains();
|
|
9686
10742
|
if (opts.json) {
|
|
@@ -9706,14 +10762,14 @@ var lsCommand20 = new Command136("ls").alias("list").description("list your cust
|
|
|
9706
10762
|
});
|
|
9707
10763
|
|
|
9708
10764
|
// src/commands/domain/rm.ts
|
|
9709
|
-
import { Command as
|
|
9710
|
-
var
|
|
10765
|
+
import { Command as Command166 } from "commander";
|
|
10766
|
+
var rmCommand23 = new Command166("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) => {
|
|
9711
10767
|
const domain = domainArg.trim().toLowerCase();
|
|
9712
10768
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
9713
10769
|
try {
|
|
9714
|
-
|
|
10770
|
+
requireCloud4(client);
|
|
9715
10771
|
const found = (await client.listDomains()).find((d) => d.domain === domain);
|
|
9716
|
-
if (!found) throw new KvboxError(`domain ${domain}: not found (kvbox domain ls)`);
|
|
10772
|
+
if (!found) throw new KvboxError(`domain ${domain}: not found (kvbox domain ls; a cluster's is removed with kvbox k8s domain rm <cluster> ${domain})`);
|
|
9717
10773
|
const box2 = boxOf2(found, me(client));
|
|
9718
10774
|
if (!await confirm(`Stop serving box ${box2} at ${domain}?`, opts.yes ?? false)) {
|
|
9719
10775
|
info("cancelled");
|
|
@@ -9728,15 +10784,15 @@ var rmCommand19 = new Command137("rm").alias("remove").description("stop serving
|
|
|
9728
10784
|
});
|
|
9729
10785
|
|
|
9730
10786
|
// src/commands/domain/index.ts
|
|
9731
|
-
var
|
|
9732
|
-
for (const cmd of
|
|
10787
|
+
var domainCommand2 = new Command167("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand6).addCommand(lsCommand25).addCommand(rmCommand23);
|
|
10788
|
+
for (const cmd of domainCommand2.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
9733
10789
|
|
|
9734
10790
|
// src/commands/update.ts
|
|
9735
10791
|
import { spawn as spawn8 } from "child_process";
|
|
9736
10792
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
9737
10793
|
import { tmpdir } from "os";
|
|
9738
10794
|
import { join as join9 } from "path";
|
|
9739
|
-
import { Command as
|
|
10795
|
+
import { Command as Command168 } from "commander";
|
|
9740
10796
|
|
|
9741
10797
|
// src/update.ts
|
|
9742
10798
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -9855,7 +10911,7 @@ function run2(cmd, args) {
|
|
|
9855
10911
|
child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
|
|
9856
10912
|
});
|
|
9857
10913
|
}
|
|
9858
|
-
var selfUpdateCommand = new
|
|
10914
|
+
var selfUpdateCommand = new Command168("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
|
|
9859
10915
|
suppressUpdateNotice();
|
|
9860
10916
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
9861
10917
|
let code;
|
|
@@ -9879,7 +10935,7 @@ var selfUpdateCommand = new Command139("update").description("update kvbox to th
|
|
|
9879
10935
|
import { chmod as chmod2, mkdir as mkdir4, readFile as readFile9, writeFile as writeFile5 } from "fs/promises";
|
|
9880
10936
|
import { homedir as homedir2 } from "os";
|
|
9881
10937
|
import { dirname as dirname2, join as join11 } from "path";
|
|
9882
|
-
import { Command as
|
|
10938
|
+
import { Command as Command169 } from "commander";
|
|
9883
10939
|
|
|
9884
10940
|
// src/sshConfig.ts
|
|
9885
10941
|
import { spawnSync as spawnSync4 } from "child_process";
|
|
@@ -10001,7 +11057,7 @@ async function forgetReplacedBox(alias, id, p) {
|
|
|
10001
11057
|
}
|
|
10002
11058
|
|
|
10003
11059
|
// src/commands/sshConfig.ts
|
|
10004
|
-
var sshConfigCommand = new
|
|
11060
|
+
var sshConfigCommand = new Command169("ssh-config").description("add your boxes to ~/.ssh/config, so ssh and VS Code Remote-SSH reach them as <box>.kvbox").argument("[box...]", "only these boxes, added to the ones listed already (default: every box)").option("--remove", "take these boxes off the list; with no box, take the whole kvbox block out").option("--file <path>", "the ssh config file to write (default: ~/.ssh/config)").option("--json", "print the result as JSON").action(async (boxes, opts, cmd) => {
|
|
10005
11061
|
const file = opts.file ?? join11(homedir2(), ".ssh", "config");
|
|
10006
11062
|
const before = await readFile9(file, "utf8").catch((err) => {
|
|
10007
11063
|
if (err.code === "ENOENT") return "";
|
|
@@ -10067,8 +11123,8 @@ async function aliasesOf(client, boxes, gone) {
|
|
|
10067
11123
|
|
|
10068
11124
|
// src/commands/sshProxy.ts
|
|
10069
11125
|
import { connect } from "net";
|
|
10070
|
-
import { Command as
|
|
10071
|
-
var sshProxyCommand = new
|
|
11126
|
+
import { Command as Command170 } from "commander";
|
|
11127
|
+
var sshProxyCommand = new Command170("ssh-proxy").description("connect ssh to a box (used by kvbox ssh-config)").argument("<host>", "the ssh name: <box>.kvbox or <box>.<org>.kvbox").option("--renew", "only renew the SSH certificate if it is about to expire").action(async (host, opts, cmd) => {
|
|
10072
11128
|
const ref = parseAlias(host);
|
|
10073
11129
|
if (ref === void 0) throw new KvboxError(`${host}: not a kvbox name (<box>.kvbox or <box>.<org>.kvbox)`);
|
|
10074
11130
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -10168,6 +11224,7 @@ var HELP_GROUPS = [
|
|
|
10168
11224
|
["bucket", "object storage: S3 buckets for your files"],
|
|
10169
11225
|
["pg", "managed PostgreSQL: a database kvbox runs for you"],
|
|
10170
11226
|
["redis", "managed Redis (Valkey): a Redis kvbox runs for you"],
|
|
11227
|
+
["k8s", "managed Kubernetes: a cluster kvbox runs for you, its nodes your boxes"],
|
|
10171
11228
|
["managed", "every managed database, whatever its kind"],
|
|
10172
11229
|
["cron", "call a box on a schedule, waking it first if it sleeps"],
|
|
10173
11230
|
["env", "environment variables and secrets every box of yours gets"],
|
|
@@ -10230,7 +11287,7 @@ function installRootHelp(program) {
|
|
|
10230
11287
|
|
|
10231
11288
|
// src/program.ts
|
|
10232
11289
|
function buildProgram() {
|
|
10233
|
-
const program = new
|
|
11290
|
+
const program = new Command171("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();
|
|
10234
11291
|
program.addCommand(vmCommand);
|
|
10235
11292
|
program.addCommand(snapshotsCommand);
|
|
10236
11293
|
program.addCommand(volumeCommand);
|
|
@@ -10239,8 +11296,9 @@ function buildProgram() {
|
|
|
10239
11296
|
program.addCommand(redisCommand);
|
|
10240
11297
|
program.addCommand(managedCommand);
|
|
10241
11298
|
program.addCommand(cronCommand);
|
|
11299
|
+
program.addCommand(k8sCommand);
|
|
10242
11300
|
program.addCommand(envCommand);
|
|
10243
|
-
program.addCommand(
|
|
11301
|
+
program.addCommand(domainCommand2);
|
|
10244
11302
|
program.addCommand(loginCommand);
|
|
10245
11303
|
program.addCommand(logoutCommand);
|
|
10246
11304
|
program.addCommand(whoamiCommand);
|