@kvbox/cli 0.6.3 → 0.6.5
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 +1275 -937
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -149,7 +149,7 @@ async function spin(message, work, opts = {}) {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// src/program.ts
|
|
152
|
-
import { Command as
|
|
152
|
+
import { Command as Command116 } from "commander";
|
|
153
153
|
|
|
154
154
|
// ../shared/src/version.ts
|
|
155
155
|
import { createRequire } from "module";
|
|
@@ -164,17 +164,20 @@ function versionOf(srcFileUrl, injected) {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// src/version.ts
|
|
167
|
-
var VERSION = versionOf(import.meta.url, true ? "0.6.
|
|
167
|
+
var VERSION = versionOf(import.meta.url, true ? "0.6.5" : void 0);
|
|
168
168
|
|
|
169
169
|
// src/commands/vm/index.ts
|
|
170
170
|
import { Command as Command37 } from "commander";
|
|
171
171
|
|
|
172
172
|
// src/commands/vm/connect.ts
|
|
173
|
-
import { spawnSync as
|
|
173
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
174
174
|
import { Command as Command2 } from "commander";
|
|
175
175
|
|
|
176
176
|
// src/cert.ts
|
|
177
|
-
import {
|
|
177
|
+
import { spawnSync } from "child_process";
|
|
178
|
+
import { randomBytes } from "crypto";
|
|
179
|
+
import { link, mkdir as mkdir2, readFile as readFile2, rename, rm as rm2, writeFile as writeFile2 } from "fs/promises";
|
|
180
|
+
import { hostname as osHostname } from "os";
|
|
178
181
|
|
|
179
182
|
// ../shared/src/paths.ts
|
|
180
183
|
import { homedir } from "os";
|
|
@@ -334,113 +337,10 @@ function volumeMountPath(volume) {
|
|
|
334
337
|
|
|
335
338
|
// src/session.ts
|
|
336
339
|
import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
337
|
-
import { z } from "zod";
|
|
338
|
-
var SessionSchema = z.object({
|
|
339
|
-
url: z.string(),
|
|
340
|
-
token: z.string(),
|
|
341
|
-
user: z.string(),
|
|
342
|
-
/** When the SSH certificate at paths().sshCert stops being accepted (ISO); absent before the first login with a key. */
|
|
343
|
-
sshCertExpires: z.string().optional(),
|
|
344
|
-
/** Whose boxes that certificate opens (`<slug>@<realm>`, the user and their orgs); absent with `sshCertExpires`. */
|
|
345
|
-
sshCertPrincipals: z.array(z.string()).optional()
|
|
346
|
-
});
|
|
347
|
-
async function readSession(p = paths()) {
|
|
348
|
-
let text2;
|
|
349
|
-
try {
|
|
350
|
-
text2 = await readFile(p.cli, "utf8");
|
|
351
|
-
} catch (err) {
|
|
352
|
-
if (err.code === "ENOENT") return null;
|
|
353
|
-
throw err;
|
|
354
|
-
}
|
|
355
|
-
try {
|
|
356
|
-
return SessionSchema.parse(JSON.parse(text2));
|
|
357
|
-
} catch {
|
|
358
|
-
throw new KvboxError(`${p.cli} is unreadable; run: kvbox logout (then log in again)`);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
async function writeSession(session, p = paths()) {
|
|
362
|
-
await mkdir(p.home, { recursive: true });
|
|
363
|
-
await writeFile(p.cli, JSON.stringify(session, null, 2) + "\n", { mode: 384 });
|
|
364
|
-
await chmod(p.cli, 384);
|
|
365
|
-
}
|
|
366
|
-
async function clearSession(p = paths()) {
|
|
367
|
-
await rm(p.cli, { force: true });
|
|
368
|
-
}
|
|
369
|
-
function hostOf(url) {
|
|
370
|
-
try {
|
|
371
|
-
return new URL(url).host;
|
|
372
|
-
} catch {
|
|
373
|
-
return url;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
function isLoopback(hostname) {
|
|
377
|
-
return hostname === "localhost" || hostname.startsWith("127.") || hostname === "[::1]";
|
|
378
|
-
}
|
|
379
|
-
function normalizeUrl(input) {
|
|
380
|
-
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(input) ? input : `https://${input}`;
|
|
381
|
-
let url;
|
|
382
|
-
try {
|
|
383
|
-
url = new URL(withScheme);
|
|
384
|
-
} catch {
|
|
385
|
-
throw new KvboxError(`not a URL: ${input}`);
|
|
386
|
-
}
|
|
387
|
-
if (!/^https?:$/.test(url.protocol) || url.hostname === "" || /\s/.test(input)) throw new KvboxError(`not a URL: ${input}`);
|
|
388
|
-
if (url.protocol === "http:" && !isLoopback(url.hostname)) {
|
|
389
|
-
throw new KvboxError(`${input}: use https (plain http is only allowed for localhost)`);
|
|
390
|
-
}
|
|
391
|
-
return url.origin + url.pathname.replace(/\/+$/, "");
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// src/cert.ts
|
|
395
|
-
var RENEW_BEFORE_MS = 60 * 60 * 1e3;
|
|
396
|
-
async function writeCert(cert, p = paths()) {
|
|
397
|
-
await writeFile2(p.sshCert, cert.trim() + "\n", { mode: 420 });
|
|
398
|
-
}
|
|
399
|
-
async function renewAfterRefusal(client, kept, owner, p = paths()) {
|
|
400
|
-
if (kept !== "kept") return false;
|
|
401
|
-
await ensureCert(client, p, Date.now(), { owner, force: true });
|
|
402
|
-
return true;
|
|
403
|
-
}
|
|
404
|
-
async function removeCert(p = paths()) {
|
|
405
|
-
await rm2(p.sshCert, { force: true });
|
|
406
|
-
}
|
|
407
|
-
async function ensureCert(client, p = paths(), now = Date.now(), opts = {}) {
|
|
408
|
-
if (client.target.kind !== "cloud") return "local";
|
|
409
|
-
const session = await readSession(p);
|
|
410
|
-
if (!session) return "local";
|
|
411
|
-
const expires = session.sshCertExpires ? new Date(session.sshCertExpires).getTime() : 0;
|
|
412
|
-
const onDisk = await readFile2(p.sshCert, "utf8").then(() => true, () => false);
|
|
413
|
-
const names2 = opts.owner === void 0 || (session.sshCertPrincipals ?? []).includes(opts.owner);
|
|
414
|
-
if (onDisk && expires - now > RENEW_BEFORE_MS && names2 && !opts.force) return "kept";
|
|
415
|
-
const publicKey = await readFile2(`${p.sshKey}.pub`, "utf8").catch(() => null);
|
|
416
|
-
if (publicKey === null) throw new KvboxError(`could not renew your SSH certificate: no key at ${p.sshKey}.pub; run: kvbox login`);
|
|
417
|
-
let signed;
|
|
418
|
-
try {
|
|
419
|
-
signed = await client.sshCert({ publicKey: publicKey.trim() });
|
|
420
|
-
} catch (err) {
|
|
421
|
-
throw new KvboxError(`could not renew your SSH certificate: ${err.message}`);
|
|
422
|
-
}
|
|
423
|
-
await writeCert(signed.cert, p);
|
|
424
|
-
await writeSession({ ...session, sshCertExpires: signed.expires, sshCertPrincipals: signed.principals }, p);
|
|
425
|
-
if (opts.owner !== void 0 && !signed.principals.includes(opts.owner)) {
|
|
426
|
-
const slug = opts.owner.split("@")[0];
|
|
427
|
-
const sameSlugElsewhere = signed.principals.find((pr) => pr.split("@")[0] === slug && pr !== opts.owner);
|
|
428
|
-
const why = sameSlugElsewhere ? `the control plane signs for ${sameSlugElsewhere} but the box's host qualifies its owner as ${opts.owner}: the control plane's name (KVBOX_CLOUD_NAME) changed after the host joined` : `you are not a member of ${slug} (a platform admin reaches org boxes over the API, not over SSH)`;
|
|
429
|
-
throw new KvboxError(`your SSH certificate does not name ${opts.owner}: ${why}`);
|
|
430
|
-
}
|
|
431
|
-
return "renewed";
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// src/client.ts
|
|
435
|
-
import { spawn } from "child_process";
|
|
436
|
-
import { openSync } from "fs";
|
|
437
|
-
import { mkdir as mkdir2, readFile as readFile3, stat } from "fs/promises";
|
|
438
|
-
import { setTimeout as sleep } from "timers/promises";
|
|
439
|
-
import { Agent, request } from "undici";
|
|
440
|
-
import { z as z7 } from "zod";
|
|
340
|
+
import { z as z2 } from "zod";
|
|
441
341
|
|
|
442
342
|
// ../shared/src/api.ts
|
|
443
|
-
import { z
|
|
343
|
+
import { z } from "zod";
|
|
444
344
|
|
|
445
345
|
// ../shared/src/sizes.ts
|
|
446
346
|
var SIZES = {
|
|
@@ -460,923 +360,1151 @@ function parseMib(text2) {
|
|
|
460
360
|
}
|
|
461
361
|
|
|
462
362
|
// ../shared/src/api.ts
|
|
463
|
-
var SizeSchema =
|
|
363
|
+
var SizeSchema = z.enum(SIZE_NAMES);
|
|
464
364
|
var BOX_SSH_USER = "kvbox";
|
|
465
|
-
var BoxStatusSchema =
|
|
466
|
-
var PortProtoSchema =
|
|
365
|
+
var BoxStatusSchema = z.enum(["running", "standby", "hibernated", "stopped", "unknown"]);
|
|
366
|
+
var PortProtoSchema = z.enum(["tcp", "udp"]);
|
|
467
367
|
var MAX_BOX_PORTS = 16;
|
|
468
|
-
var PortForwardSchema =
|
|
469
|
-
guestPort:
|
|
470
|
-
hostPort:
|
|
368
|
+
var PortForwardSchema = z.object({
|
|
369
|
+
guestPort: z.number().int().min(1).max(65535),
|
|
370
|
+
hostPort: z.number().int(),
|
|
471
371
|
proto: PortProtoSchema,
|
|
472
372
|
/** The host's public address; only the control plane fills it in, as for `ssh`. */
|
|
473
|
-
address:
|
|
373
|
+
address: z.string().optional(),
|
|
474
374
|
/**
|
|
475
375
|
* Closed but kept (#173): nothing reaches the box through it, and the host port stays the box's, so
|
|
476
376
|
* publishing the same box port again opens the same number. Absent: open while the box runs.
|
|
477
377
|
*/
|
|
478
|
-
closed:
|
|
378
|
+
closed: z.literal(true).optional()
|
|
479
379
|
});
|
|
480
|
-
var PortsRequest =
|
|
481
|
-
ports:
|
|
380
|
+
var PortsRequest = z.object({
|
|
381
|
+
ports: z.array(z.object({ guestPort: z.number().int().min(1).max(65535), proto: PortProtoSchema.optional() })).min(1).max(MAX_BOX_PORTS),
|
|
482
382
|
/** `DELETE` only (#173): close the ports but keep their host ports for the box (`closed`). */
|
|
483
|
-
keep:
|
|
484
|
-
});
|
|
485
|
-
var BoxPortSchema =
|
|
486
|
-
var BoxLinkSchema =
|
|
487
|
-
var LinkRequest =
|
|
488
|
-
var ClaimSubdomainRequest =
|
|
489
|
-
var SubdomainPortRequest =
|
|
490
|
-
var SubdomainRouteRequest =
|
|
491
|
-
var SubdomainSchema =
|
|
492
|
-
owner:
|
|
493
|
-
box:
|
|
494
|
-
subdomain:
|
|
383
|
+
keep: z.boolean().optional()
|
|
384
|
+
});
|
|
385
|
+
var BoxPortSchema = z.number().int().min(1).max(65535);
|
|
386
|
+
var BoxLinkSchema = z.object({ from: z.string(), port: BoxPortSchema });
|
|
387
|
+
var LinkRequest = z.object({ from: z.string().min(1), fromOwner: z.string().optional(), port: BoxPortSchema });
|
|
388
|
+
var ClaimSubdomainRequest = z.object({ name: z.string(), port: BoxPortSchema });
|
|
389
|
+
var SubdomainPortRequest = z.object({ port: BoxPortSchema });
|
|
390
|
+
var SubdomainRouteRequest = z.object({ name: z.string(), port: BoxPortSchema });
|
|
391
|
+
var SubdomainSchema = z.object({
|
|
392
|
+
owner: z.string(),
|
|
393
|
+
box: z.string(),
|
|
394
|
+
subdomain: z.string(),
|
|
495
395
|
port: BoxPortSchema,
|
|
496
|
-
url:
|
|
497
|
-
routes:
|
|
396
|
+
url: z.string(),
|
|
397
|
+
routes: z.array(z.object({ name: z.string(), port: BoxPortSchema, url: z.string() }))
|
|
498
398
|
});
|
|
499
|
-
var AddDomainRequest =
|
|
500
|
-
var DomainSchema =
|
|
501
|
-
owner:
|
|
502
|
-
box:
|
|
503
|
-
domain:
|
|
399
|
+
var AddDomainRequest = z.object({ domain: z.string(), port: BoxPortSchema.optional() });
|
|
400
|
+
var DomainSchema = z.object({
|
|
401
|
+
owner: z.string(),
|
|
402
|
+
box: z.string(),
|
|
403
|
+
domain: z.string(),
|
|
504
404
|
port: BoxPortSchema,
|
|
505
|
-
status:
|
|
506
|
-
www:
|
|
507
|
-
url:
|
|
508
|
-
error:
|
|
509
|
-
records:
|
|
510
|
-
createdAt:
|
|
511
|
-
});
|
|
512
|
-
var WakeHookSchema =
|
|
513
|
-
id:
|
|
514
|
-
owner:
|
|
515
|
-
box:
|
|
516
|
-
url:
|
|
517
|
-
createdBy:
|
|
518
|
-
createdAt:
|
|
519
|
-
lastCalledAt:
|
|
405
|
+
status: z.enum(["pending", "live"]),
|
|
406
|
+
www: z.boolean(),
|
|
407
|
+
url: z.string(),
|
|
408
|
+
error: z.string().nullable(),
|
|
409
|
+
records: z.array(z.object({ type: z.enum(["A", "TXT", "CNAME"]), name: z.string(), value: z.string() })),
|
|
410
|
+
createdAt: z.string()
|
|
411
|
+
});
|
|
412
|
+
var WakeHookSchema = z.object({
|
|
413
|
+
id: z.string(),
|
|
414
|
+
owner: z.string(),
|
|
415
|
+
box: z.string(),
|
|
416
|
+
url: z.string(),
|
|
417
|
+
createdBy: z.string().nullable(),
|
|
418
|
+
createdAt: z.string(),
|
|
419
|
+
lastCalledAt: z.string().nullable()
|
|
520
420
|
});
|
|
521
|
-
var CreatedWakeHookSchema = WakeHookSchema.extend({ secret:
|
|
522
|
-
var WakeHookCallSchema =
|
|
523
|
-
box:
|
|
524
|
-
action:
|
|
525
|
-
reason:
|
|
421
|
+
var CreatedWakeHookSchema = WakeHookSchema.extend({ secret: z.string() });
|
|
422
|
+
var WakeHookCallSchema = z.object({
|
|
423
|
+
box: z.string(),
|
|
424
|
+
action: z.enum(["wake", "resume", "none"]),
|
|
425
|
+
reason: z.string().optional()
|
|
526
426
|
});
|
|
527
427
|
var BACKUP_STATUSES = ["running", "ready", "failed"];
|
|
528
428
|
var BACKUP_KINDS = ["box", "volume"];
|
|
529
|
-
var BackupSchema =
|
|
530
|
-
id:
|
|
531
|
-
owner:
|
|
532
|
-
box:
|
|
533
|
-
status:
|
|
429
|
+
var BackupSchema = z.object({
|
|
430
|
+
id: z.string(),
|
|
431
|
+
owner: z.string(),
|
|
432
|
+
box: z.string(),
|
|
433
|
+
status: z.enum(BACKUP_STATUSES),
|
|
534
434
|
/** Why it failed; null otherwise. */
|
|
535
|
-
error:
|
|
435
|
+
error: z.string().nullable(),
|
|
536
436
|
/** The image version the disk stacks on (a restore needs it on the host), and the image (absent: base). */
|
|
537
|
-
base:
|
|
538
|
-
image:
|
|
539
|
-
vcpu:
|
|
540
|
-
memMib:
|
|
437
|
+
base: z.string().nullable(),
|
|
438
|
+
image: z.string().optional(),
|
|
439
|
+
vcpu: z.number().int().nullable(),
|
|
440
|
+
memMib: z.number().int().nullable(),
|
|
541
441
|
/** The disk's size. */
|
|
542
|
-
diskBytes:
|
|
442
|
+
diskBytes: z.number().int().nullable(),
|
|
543
443
|
/** What it holds: the slots that are not all zeros. */
|
|
544
|
-
dataBytes:
|
|
444
|
+
dataBytes: z.number().int().nullable(),
|
|
545
445
|
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
546
|
-
uploadedBytes:
|
|
547
|
-
createdBy:
|
|
548
|
-
createdAt:
|
|
549
|
-
finishedAt:
|
|
550
|
-
});
|
|
551
|
-
var HostBackupRequest =
|
|
552
|
-
var HostBackupManifestSchema =
|
|
553
|
-
id:
|
|
554
|
-
sizeBytes:
|
|
555
|
-
chunks:
|
|
556
|
-
env:
|
|
557
|
-
base:
|
|
558
|
-
image:
|
|
559
|
-
vcpu:
|
|
560
|
-
memMib:
|
|
561
|
-
});
|
|
562
|
-
var HostUploadRequest =
|
|
563
|
-
var HostUploadResultSchema =
|
|
564
|
-
var HostRestoreRequest =
|
|
446
|
+
uploadedBytes: z.number().int().nullable(),
|
|
447
|
+
createdBy: z.string().nullable(),
|
|
448
|
+
createdAt: z.string(),
|
|
449
|
+
finishedAt: z.string().nullable()
|
|
450
|
+
});
|
|
451
|
+
var HostBackupRequest = z.object({ id: z.string(), key: z.string() });
|
|
452
|
+
var HostBackupManifestSchema = z.object({
|
|
453
|
+
id: z.string(),
|
|
454
|
+
sizeBytes: z.number().int(),
|
|
455
|
+
chunks: z.array(z.string().nullable()),
|
|
456
|
+
env: z.string().nullable(),
|
|
457
|
+
base: z.string(),
|
|
458
|
+
image: z.string().optional(),
|
|
459
|
+
vcpu: z.number().int(),
|
|
460
|
+
memMib: z.number().int()
|
|
461
|
+
});
|
|
462
|
+
var HostUploadRequest = z.object({ key: z.string(), urls: z.record(z.string(), z.string()), pin: z.string().optional() });
|
|
463
|
+
var HostUploadResultSchema = z.object({ chunks: z.number().int(), bytes: z.number().int(), sizes: z.record(z.string(), z.number().int()) });
|
|
464
|
+
var HostRestoreRequest = z.object({
|
|
565
465
|
/** The backup's id: its variables were sealed under it. */
|
|
566
|
-
id:
|
|
567
|
-
key:
|
|
568
|
-
sizeBytes:
|
|
569
|
-
base:
|
|
570
|
-
image:
|
|
571
|
-
env:
|
|
572
|
-
chunks:
|
|
466
|
+
id: z.string(),
|
|
467
|
+
key: z.string(),
|
|
468
|
+
sizeBytes: z.number().int().positive(),
|
|
469
|
+
base: z.string(),
|
|
470
|
+
image: z.string().optional(),
|
|
471
|
+
env: z.string().nullable(),
|
|
472
|
+
chunks: z.array(z.object({ index: z.number().int().nonnegative(), hash: z.string(), url: z.string() })),
|
|
573
473
|
/** The certificate fingerprint of the store the URLs point at (see HostUploadRequest). */
|
|
574
|
-
pin:
|
|
474
|
+
pin: z.string().optional()
|
|
575
475
|
});
|
|
576
|
-
var VolumeBackupSchema =
|
|
577
|
-
id:
|
|
578
|
-
owner:
|
|
579
|
-
volume:
|
|
580
|
-
status:
|
|
476
|
+
var VolumeBackupSchema = z.object({
|
|
477
|
+
id: z.string(),
|
|
478
|
+
owner: z.string(),
|
|
479
|
+
volume: z.string(),
|
|
480
|
+
status: z.enum(BACKUP_STATUSES),
|
|
581
481
|
/** Why it failed; null otherwise. */
|
|
582
|
-
error:
|
|
482
|
+
error: z.string().nullable(),
|
|
583
483
|
/** The volume's size when taken. */
|
|
584
|
-
diskBytes:
|
|
484
|
+
diskBytes: z.number().int().nullable(),
|
|
585
485
|
/** What it holds: the slots that are not all zeros. */
|
|
586
|
-
dataBytes:
|
|
486
|
+
dataBytes: z.number().int().nullable(),
|
|
587
487
|
/** What this backup added to storage (encrypted, compressed): the chunks no earlier backup had. */
|
|
588
|
-
uploadedBytes:
|
|
589
|
-
createdBy:
|
|
590
|
-
createdAt:
|
|
591
|
-
finishedAt:
|
|
592
|
-
});
|
|
593
|
-
var HostVolumeBackupManifestSchema =
|
|
594
|
-
var HostVolumeRestoreRequest =
|
|
595
|
-
id:
|
|
596
|
-
key:
|
|
597
|
-
sizeBytes:
|
|
598
|
-
chunks:
|
|
599
|
-
pin:
|
|
600
|
-
});
|
|
601
|
-
var BackupStoreSetupRequest =
|
|
602
|
-
var BackupStoreStatusSchema =
|
|
603
|
-
path:
|
|
604
|
-
bucket:
|
|
605
|
-
accessKey:
|
|
488
|
+
uploadedBytes: z.number().int().nullable(),
|
|
489
|
+
createdBy: z.string().nullable(),
|
|
490
|
+
createdAt: z.string(),
|
|
491
|
+
finishedAt: z.string().nullable()
|
|
492
|
+
});
|
|
493
|
+
var HostVolumeBackupManifestSchema = z.object({ id: z.string(), sizeBytes: z.number().int(), chunks: z.array(z.string().nullable()) });
|
|
494
|
+
var HostVolumeRestoreRequest = z.object({
|
|
495
|
+
id: z.string(),
|
|
496
|
+
key: z.string(),
|
|
497
|
+
sizeBytes: z.number().int().positive(),
|
|
498
|
+
chunks: z.array(z.object({ index: z.number().int().nonnegative(), hash: z.string(), url: z.string() })),
|
|
499
|
+
pin: z.string().optional()
|
|
500
|
+
});
|
|
501
|
+
var BackupStoreSetupRequest = z.object({ path: z.string().min(1), force: z.boolean().optional(), newStore: z.boolean().optional() });
|
|
502
|
+
var BackupStoreStatusSchema = z.object({
|
|
503
|
+
path: z.string(),
|
|
504
|
+
bucket: z.string(),
|
|
505
|
+
accessKey: z.string(),
|
|
606
506
|
/** Whether Garage is running and can store. */
|
|
607
|
-
running:
|
|
507
|
+
running: z.boolean(),
|
|
608
508
|
/** The filesystem the path is on. */
|
|
609
|
-
totalBytes:
|
|
610
|
-
freeBytes:
|
|
509
|
+
totalBytes: z.number().int(),
|
|
510
|
+
freeBytes: z.number().int(),
|
|
611
511
|
/** What the bucket holds, when Garage answers. */
|
|
612
|
-
objects:
|
|
613
|
-
storedBytes:
|
|
512
|
+
objects: z.number().int().optional(),
|
|
513
|
+
storedBytes: z.number().int().optional(),
|
|
614
514
|
/** Whether the control plane took the store's registration at setup. */
|
|
615
|
-
registered:
|
|
515
|
+
registered: z.boolean().optional()
|
|
616
516
|
});
|
|
617
|
-
var BackupStoreRegistration =
|
|
618
|
-
var CloudBackupStoreSchema =
|
|
619
|
-
id:
|
|
517
|
+
var BackupStoreRegistration = z.object({ bucket: z.string().min(1), region: z.string().min(1), accessKey: z.string().min(1), secretKey: z.string().min(1) });
|
|
518
|
+
var CloudBackupStoreSchema = z.object({
|
|
519
|
+
id: z.string(),
|
|
620
520
|
/** Null while no host serves it (its host left; it comes back when a host registers its key and secret again). */
|
|
621
|
-
host:
|
|
622
|
-
endpoint:
|
|
623
|
-
bucket:
|
|
624
|
-
accessKey:
|
|
625
|
-
createdAt:
|
|
521
|
+
host: z.string().nullable(),
|
|
522
|
+
endpoint: z.string().nullable(),
|
|
523
|
+
bucket: z.string(),
|
|
524
|
+
accessKey: z.string(),
|
|
525
|
+
createdAt: z.string(),
|
|
626
526
|
/** The host answered a poll in the last minute and its Garage runs. */
|
|
627
|
-
live:
|
|
527
|
+
live: z.boolean(),
|
|
628
528
|
/** From the host's last poll; null when it never reported a store. */
|
|
629
|
-
totalBytes:
|
|
630
|
-
freeBytes:
|
|
529
|
+
totalBytes: z.number().int().nullable(),
|
|
530
|
+
freeBytes: z.number().int().nullable(),
|
|
631
531
|
/** Ready backups kept here, and what their chunks take (encrypted, compressed). */
|
|
632
|
-
backups:
|
|
633
|
-
storedBytes:
|
|
532
|
+
backups: z.number().int(),
|
|
533
|
+
storedBytes: z.number().int(),
|
|
634
534
|
/** How many boxes have a ready backup here (a box and an earlier one of the same name count once), and how many volumes (#168). */
|
|
635
|
-
boxes:
|
|
636
|
-
volumes:
|
|
535
|
+
boxes: z.number().int(),
|
|
536
|
+
volumes: z.number().int(),
|
|
637
537
|
/** When the newest ready backup kept here finished; null when it keeps none. */
|
|
638
|
-
lastBackupAt:
|
|
538
|
+
lastBackupAt: z.string().nullable()
|
|
639
539
|
});
|
|
640
|
-
var StoredItemSchema =
|
|
641
|
-
kind:
|
|
642
|
-
owner:
|
|
643
|
-
name:
|
|
540
|
+
var StoredItemSchema = z.object({
|
|
541
|
+
kind: z.enum(BACKUP_KINDS),
|
|
542
|
+
owner: z.string(),
|
|
543
|
+
name: z.string(),
|
|
644
544
|
/** The host the box (or volume) is on now; null when it is gone (its backups stay). */
|
|
645
|
-
host:
|
|
545
|
+
host: z.string().nullable(),
|
|
646
546
|
/** It is on the store's own host: losing that host loses it and its backups together. */
|
|
647
|
-
sameHost:
|
|
547
|
+
sameHost: z.boolean(),
|
|
648
548
|
/** Ready backups kept here, and what they added to the store together (encrypted, compressed). */
|
|
649
|
-
backups:
|
|
650
|
-
uploadedBytes:
|
|
549
|
+
backups: z.number().int(),
|
|
550
|
+
uploadedBytes: z.number().int(),
|
|
651
551
|
/** The newest backup sent here, whatever became of it. */
|
|
652
|
-
latest:
|
|
552
|
+
latest: z.object({ id: z.string(), status: z.enum(BACKUP_STATUSES), error: z.string().nullable(), createdAt: z.string() })
|
|
653
553
|
});
|
|
654
|
-
var FailedBackupSchema =
|
|
655
|
-
id:
|
|
656
|
-
owner:
|
|
554
|
+
var FailedBackupSchema = z.object({
|
|
555
|
+
id: z.string(),
|
|
556
|
+
owner: z.string(),
|
|
657
557
|
/** What it was a backup of: a box or a volume (#168), and its name. */
|
|
658
|
-
kind:
|
|
659
|
-
name:
|
|
660
|
-
error:
|
|
558
|
+
kind: z.enum(BACKUP_KINDS),
|
|
559
|
+
name: z.string(),
|
|
560
|
+
error: z.string().nullable(),
|
|
661
561
|
/** The host that took it, and the host of the store it was going to; null when gone, or when it failed before a store was picked. */
|
|
662
|
-
host:
|
|
663
|
-
store:
|
|
664
|
-
createdAt:
|
|
562
|
+
host: z.string().nullable(),
|
|
563
|
+
store: z.string().nullable(),
|
|
564
|
+
createdAt: z.string()
|
|
665
565
|
});
|
|
666
|
-
var MachineSchema =
|
|
566
|
+
var MachineSchema = z.object({
|
|
667
567
|
/** Host-unique short id (the tap is `kv-<id>`). Missing only on a box made before ids that has not restarted since. */
|
|
668
|
-
id:
|
|
669
|
-
name:
|
|
568
|
+
id: z.string(),
|
|
569
|
+
name: z.string(),
|
|
670
570
|
/** Who the box belongs to; names are unique per owner. A bare name is local to the host, `user@control-plane` later. */
|
|
671
|
-
owner:
|
|
672
|
-
ip:
|
|
673
|
-
mac:
|
|
674
|
-
pid:
|
|
675
|
-
vcpu:
|
|
676
|
-
memMib:
|
|
677
|
-
diskBytes:
|
|
571
|
+
owner: z.string(),
|
|
572
|
+
ip: z.string(),
|
|
573
|
+
mac: z.string(),
|
|
574
|
+
pid: z.number().int().nullable(),
|
|
575
|
+
vcpu: z.number().int(),
|
|
576
|
+
memMib: z.number().int(),
|
|
577
|
+
diskBytes: z.number().int(),
|
|
678
578
|
// the box's own writable disk, as the guest sees it
|
|
679
|
-
diskUsedBytes:
|
|
579
|
+
diskUsedBytes: z.number().int(),
|
|
680
580
|
// what the box uses of it: the filesystem's own count, like the guest's `df` (#115)
|
|
681
581
|
/** What the disk's sparse file occupies on the host. Grows while the box runs, `kvbox stop` trims it back. Hosts before 0.5.42 do not send it. */
|
|
682
|
-
diskHostBytes:
|
|
683
|
-
base:
|
|
582
|
+
diskHostBytes: z.number().int().optional(),
|
|
583
|
+
base: z.string(),
|
|
684
584
|
// version of the image the box's overlay stacks on
|
|
685
585
|
/** The image (#87) when it is not the base one: `postgres`. `base` is then that image's version. */
|
|
686
|
-
image:
|
|
687
|
-
createdAt:
|
|
688
|
-
source:
|
|
586
|
+
image: z.string().optional(),
|
|
587
|
+
createdAt: z.string(),
|
|
588
|
+
source: z.string(),
|
|
689
589
|
// "base", "snapshot:<owner/name>" or "fork:<owner/name>" (#79)
|
|
690
590
|
status: BoxStatusSchema,
|
|
691
591
|
/**
|
|
692
592
|
* Public TCP port on the host that reaches the box's SSH while it runs (#49). Only boxes made
|
|
693
593
|
* through a control plane have one; the control plane adds the host's address for `connect` (#21).
|
|
694
594
|
*/
|
|
695
|
-
sshPort:
|
|
595
|
+
sshPort: z.number().int().optional(),
|
|
696
596
|
/**
|
|
697
597
|
* Where `ssh` reaches the box from outside: the host's public address and that port (#21). Only
|
|
698
598
|
* the control plane fills it in (a host does not know its own public address); absent for a box
|
|
699
599
|
* whose host reported no port or did not answer.
|
|
700
600
|
*/
|
|
701
|
-
ssh:
|
|
601
|
+
ssh: z.object({ host: z.string(), port: z.number().int(), user: z.string() }).optional(),
|
|
702
602
|
/** Box ports published on the host (#30). Absent: none. */
|
|
703
|
-
ports:
|
|
603
|
+
ports: z.array(PortForwardSchema).optional(),
|
|
704
604
|
/** Whether the owner slug is a user or an org. Only the control plane knows; it fills it in on `GET /machines`. */
|
|
705
|
-
ownerKind:
|
|
605
|
+
ownerKind: z.enum(["user", "org"]).optional(),
|
|
706
606
|
/**
|
|
707
607
|
* The name of the host the box runs on. Only the control plane fills it in, on `GET /machines`: a box
|
|
708
608
|
* links to, and a volume attaches to, only a box on the same host.
|
|
709
609
|
*/
|
|
710
|
-
host:
|
|
610
|
+
host: z.string().optional(),
|
|
711
611
|
/** The country code of that host (`RO`, `US`), when its admin gave one. Only the control plane fills it in. */
|
|
712
|
-
country:
|
|
612
|
+
country: z.string().optional(),
|
|
713
613
|
/**
|
|
714
614
|
* The kind of managed service the box runs (`postgres`, `redis`, `storage`). Only an admin's
|
|
715
615
|
* `GET /machines?all=1` lists such boxes, so a host's boxes add up; every other listing hides them.
|
|
716
616
|
*/
|
|
717
|
-
managed:
|
|
617
|
+
managed: z.string().optional(),
|
|
718
618
|
/** Seconds without network traffic before the host hibernates the box (#47). Absent: never. */
|
|
719
|
-
autoHibernateSec:
|
|
619
|
+
autoHibernateSec: z.number().int().positive().optional(),
|
|
720
620
|
/** A script inside the box that says it is idle (#102, exit 0): auto-hibernate asks it instead of watching the traffic. */
|
|
721
|
-
idleCheck:
|
|
621
|
+
idleCheck: z.string().optional(),
|
|
722
622
|
/** Volumes attached to the box (#52), in drive order; each is mounted at `mountPath` while the box runs. Absent: none. */
|
|
723
|
-
volumes:
|
|
623
|
+
volumes: z.array(z.object({ name: z.string(), sizeGib: z.number().int(), mountPath: z.string() })).optional(),
|
|
724
624
|
/** Boxes that may reach this one, each on one port (#98). Absent: none. */
|
|
725
|
-
links:
|
|
625
|
+
links: z.array(BoxLinkSchema).optional(),
|
|
726
626
|
/** How to reach what the box serves, its secrets masked (#87): `postgres://postgres:****@db.kvbox:5432/postgres`. */
|
|
727
|
-
url:
|
|
627
|
+
url: z.string().optional(),
|
|
728
628
|
/**
|
|
729
629
|
* Only in what `POST /machines` answers, for an image that declares one (#87): how to reach what it
|
|
730
630
|
* serves, e.g. `postgres://postgres:<password>@db.kvbox:5432/postgres`. Holds the box's variables.
|
|
731
631
|
*/
|
|
732
|
-
connect:
|
|
632
|
+
connect: z.string().optional()
|
|
733
633
|
});
|
|
734
|
-
var VolumeSchema =
|
|
634
|
+
var VolumeSchema = z.object({
|
|
735
635
|
/** The host's 6-hex volume id (#91): the ledger's key, so a name removed and made again is two volumes. */
|
|
736
|
-
id:
|
|
737
|
-
name:
|
|
738
|
-
owner:
|
|
739
|
-
sizeGib:
|
|
636
|
+
id: z.string(),
|
|
637
|
+
name: z.string(),
|
|
638
|
+
owner: z.string(),
|
|
639
|
+
sizeGib: z.number().int(),
|
|
740
640
|
/** What the sparse file really occupies on the host. */
|
|
741
|
-
usedBytes:
|
|
742
|
-
attachedTo:
|
|
743
|
-
createdAt:
|
|
641
|
+
usedBytes: z.number().int(),
|
|
642
|
+
attachedTo: z.string().nullable(),
|
|
643
|
+
createdAt: z.string(),
|
|
744
644
|
/** Whether the owner slug is a user or an org. Only the control plane knows; it fills it in on `GET /volumes`. */
|
|
745
|
-
ownerKind:
|
|
645
|
+
ownerKind: z.enum(["user", "org"]).optional(),
|
|
746
646
|
/** The name of the host the volume lives on; only the control plane fills it in. It attaches only to a box there. */
|
|
747
|
-
host:
|
|
647
|
+
host: z.string().optional()
|
|
748
648
|
});
|
|
749
649
|
var MAX_VOLUME_GIB = 4096;
|
|
750
650
|
var VOLUME_NAME_RE = /^[a-z0-9][a-z0-9-]{0,11}$/;
|
|
751
651
|
var VOLUME_NAME_RULE = "1-12 chars, lowercase letters, digits and '-', starting with a letter or digit";
|
|
752
|
-
var CreateVolumeRequest =
|
|
753
|
-
name:
|
|
754
|
-
sizeGib:
|
|
652
|
+
var CreateVolumeRequest = z.object({
|
|
653
|
+
name: z.string(),
|
|
654
|
+
sizeGib: z.number().int().min(1).max(MAX_VOLUME_GIB),
|
|
755
655
|
/**
|
|
756
656
|
* Through a control plane (#91): the box this volume is for, so it is made on that box's host; the
|
|
757
657
|
* control plane requires it (a volume attaches only to a box on its own host, so one made for no box
|
|
758
658
|
* could never attach) and the CLI attaches right after. A host ignores it.
|
|
759
659
|
*/
|
|
760
|
-
box:
|
|
660
|
+
box: z.string().optional()
|
|
761
661
|
});
|
|
762
|
-
var AttachVolumeRequest =
|
|
763
|
-
box:
|
|
662
|
+
var AttachVolumeRequest = z.object({
|
|
663
|
+
box: z.string()
|
|
764
664
|
});
|
|
765
|
-
var ResizeVolumeRequest =
|
|
766
|
-
sizeGib:
|
|
665
|
+
var ResizeVolumeRequest = z.object({
|
|
666
|
+
sizeGib: z.number().int().min(1).max(MAX_VOLUME_GIB)
|
|
767
667
|
});
|
|
768
|
-
var RunScriptRequest =
|
|
769
|
-
var ScriptOutputSchema =
|
|
668
|
+
var RunScriptRequest = z.object({ input: z.unknown().optional() });
|
|
669
|
+
var ScriptOutputSchema = z.object({ output: z.unknown() });
|
|
770
670
|
var BOX_RUN_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
771
|
-
var StartRunRequest =
|
|
772
|
-
id:
|
|
773
|
-
command:
|
|
671
|
+
var StartRunRequest = z.object({
|
|
672
|
+
id: z.string().regex(BOX_RUN_ID_RE),
|
|
673
|
+
command: z.string().min(1).max(8192),
|
|
774
674
|
/** The command and everything it started are killed after this long. */
|
|
775
|
-
timeoutSec:
|
|
675
|
+
timeoutSec: z.number().int().min(1).max(86400)
|
|
776
676
|
});
|
|
777
|
-
var StartRunAnswerSchema =
|
|
778
|
-
id:
|
|
677
|
+
var StartRunAnswerSchema = z.object({
|
|
678
|
+
id: z.string(),
|
|
779
679
|
/** False: a run of this id was already there. */
|
|
780
|
-
started:
|
|
680
|
+
started: z.boolean(),
|
|
781
681
|
/** The box was asleep and this request woke it. */
|
|
782
|
-
woke:
|
|
682
|
+
woke: z.boolean()
|
|
783
683
|
});
|
|
784
684
|
var BOX_RUN_STATES = ["running", "exited", "timeout", "unknown"];
|
|
785
|
-
var BoxRunSchema =
|
|
786
|
-
id:
|
|
787
|
-
state:
|
|
685
|
+
var BoxRunSchema = z.object({
|
|
686
|
+
id: z.string(),
|
|
687
|
+
state: z.enum(BOX_RUN_STATES),
|
|
788
688
|
/** With `exited`; 128 + the signal for a command a signal ended. */
|
|
789
|
-
exitCode:
|
|
790
|
-
});
|
|
791
|
-
var RunRefusalSchema =
|
|
792
|
-
var EnvVarSchema =
|
|
793
|
-
name:
|
|
794
|
-
value:
|
|
795
|
-
secret:
|
|
796
|
-
updatedAt:
|
|
797
|
-
});
|
|
798
|
-
var BoxEnvSchema =
|
|
799
|
-
box:
|
|
800
|
-
vars:
|
|
801
|
-
});
|
|
802
|
-
var BoxEnvChangeSchema =
|
|
803
|
-
box:
|
|
804
|
-
name:
|
|
689
|
+
exitCode: z.number().int().optional()
|
|
690
|
+
});
|
|
691
|
+
var RunRefusalSchema = z.object({ error: z.string(), code: z.string().optional() });
|
|
692
|
+
var EnvVarSchema = z.object({
|
|
693
|
+
name: z.string(),
|
|
694
|
+
value: z.string().optional(),
|
|
695
|
+
secret: z.boolean(),
|
|
696
|
+
updatedAt: z.string()
|
|
697
|
+
});
|
|
698
|
+
var BoxEnvSchema = z.object({
|
|
699
|
+
box: z.string(),
|
|
700
|
+
vars: z.array(EnvVarSchema)
|
|
701
|
+
});
|
|
702
|
+
var BoxEnvChangeSchema = z.object({
|
|
703
|
+
box: z.string(),
|
|
704
|
+
name: z.string(),
|
|
805
705
|
/** Whether the box is running now: the change waits for its next start. */
|
|
806
|
-
running:
|
|
706
|
+
running: z.boolean()
|
|
807
707
|
});
|
|
808
|
-
var SetEnvRequest =
|
|
809
|
-
value:
|
|
810
|
-
secret:
|
|
708
|
+
var SetEnvRequest = z.object({
|
|
709
|
+
value: z.string(),
|
|
710
|
+
secret: z.boolean().optional()
|
|
811
711
|
});
|
|
812
|
-
var EnvChangeSchema =
|
|
813
|
-
owner:
|
|
814
|
-
name:
|
|
815
|
-
boxes:
|
|
712
|
+
var EnvChangeSchema = z.object({
|
|
713
|
+
owner: z.string(),
|
|
714
|
+
name: z.string(),
|
|
715
|
+
boxes: z.number().int()
|
|
816
716
|
});
|
|
817
|
-
var HostEnvRequest =
|
|
818
|
-
version:
|
|
819
|
-
vars:
|
|
717
|
+
var HostEnvRequest = z.object({
|
|
718
|
+
version: z.number().int().min(0),
|
|
719
|
+
vars: z.array(z.object({ name: z.string(), value: z.string() }))
|
|
820
720
|
});
|
|
821
|
-
var HostEnvVersionsSchema =
|
|
822
|
-
var CreateMachineRequest =
|
|
823
|
-
name:
|
|
721
|
+
var HostEnvVersionsSchema = z.array(z.object({ owner: z.string(), version: z.number().int() }));
|
|
722
|
+
var CreateMachineRequest = z.object({
|
|
723
|
+
name: z.string().optional(),
|
|
824
724
|
/** Ignored over the local socket (the caller is the host owner); the control plane sets it over HTTPS. */
|
|
825
|
-
owner:
|
|
725
|
+
owner: z.string().optional(),
|
|
826
726
|
size: SizeSchema.optional(),
|
|
827
|
-
from:
|
|
828
|
-
force:
|
|
727
|
+
from: z.string().optional(),
|
|
728
|
+
force: z.boolean().optional(),
|
|
829
729
|
/**
|
|
830
730
|
* Extra authorized_keys lines for the box, on top of the host's own key: the control plane sends
|
|
831
731
|
* its SSH CA as one `cert-authority …` line (#51). Written into the box's authorized_keys at every
|
|
832
732
|
* boot (#49); a host older than that ignores them.
|
|
833
733
|
*/
|
|
834
|
-
sshKeys:
|
|
734
|
+
sshKeys: z.array(z.string()).optional(),
|
|
835
735
|
/** Seconds without network traffic before the box is hibernated (#47); 0: never. Absent: the host's default. */
|
|
836
|
-
autoHibernateSec:
|
|
736
|
+
autoHibernateSec: z.number().int().min(0).optional(),
|
|
837
737
|
/**
|
|
838
738
|
* Place the box on the host of this box (#98, `kvbox new --near`), so the two can be linked. Only the
|
|
839
739
|
* control plane reads it; a host has one place to put a box.
|
|
840
740
|
*/
|
|
841
|
-
near:
|
|
741
|
+
near: z.string().optional(),
|
|
842
742
|
/**
|
|
843
743
|
* Place the box on a host in this country (`kvbox new --country romania`): a code or an English name,
|
|
844
744
|
* `@kvbox/shared/country`. Only the control plane reads it.
|
|
845
745
|
*/
|
|
846
|
-
country:
|
|
746
|
+
country: z.string().optional(),
|
|
847
747
|
/**
|
|
848
748
|
* Place the box on the host of this name and nowhere else (`kvbox new --host kvbox2`, a hidden flag):
|
|
849
749
|
* an admin's, to try a host out. Only the control plane reads it, and refuses it from anyone else.
|
|
850
750
|
*/
|
|
851
|
-
host:
|
|
751
|
+
host: z.string().optional(),
|
|
852
752
|
/** The image to boot (#87, `kvbox new --base postgres`). Absent: the base image. */
|
|
853
|
-
image:
|
|
753
|
+
image: z.string().optional(),
|
|
854
754
|
/** The box's own environment variables (#87, `kvbox new -e NAME=value`), over its owner's. */
|
|
855
|
-
env:
|
|
755
|
+
env: z.array(z.object({ name: z.string(), value: z.string() })).optional()
|
|
856
756
|
});
|
|
857
|
-
var ForkMachineRequest =
|
|
858
|
-
name:
|
|
757
|
+
var ForkMachineRequest = z.object({
|
|
758
|
+
name: z.string().optional(),
|
|
859
759
|
/**
|
|
860
760
|
* The new box's slug, bare (`acme`): the control plane sends the target of `--org` here; the host
|
|
861
761
|
* qualifies it with the caller's realm. Absent: the source's owner. A CLI leaves it out.
|
|
862
762
|
*/
|
|
863
|
-
owner:
|
|
763
|
+
owner: z.string().optional(),
|
|
864
764
|
/** A cold fork only: a warm one keeps the source's vCPU and memory. */
|
|
865
765
|
size: SizeSchema.optional(),
|
|
866
|
-
force:
|
|
766
|
+
force: z.boolean().optional(),
|
|
867
767
|
/** As in CreateMachineRequest: the control plane's CA line for the new box's owner. */
|
|
868
|
-
sshKeys:
|
|
869
|
-
autoHibernateSec:
|
|
768
|
+
sshKeys: z.array(z.string()).optional(),
|
|
769
|
+
autoHibernateSec: z.number().int().min(0).optional()
|
|
870
770
|
});
|
|
871
|
-
var SetSshKeysRequest =
|
|
872
|
-
sshKeys:
|
|
771
|
+
var SetSshKeysRequest = z.object({
|
|
772
|
+
sshKeys: z.array(z.string())
|
|
873
773
|
});
|
|
874
|
-
var RescaleMachineRequest =
|
|
774
|
+
var RescaleMachineRequest = z.object({
|
|
875
775
|
size: SizeSchema.optional(),
|
|
876
|
-
vcpu:
|
|
877
|
-
memMib:
|
|
878
|
-
diskGib:
|
|
776
|
+
vcpu: z.number().int().min(1).max(64).optional(),
|
|
777
|
+
memMib: z.number().int().min(256).optional(),
|
|
778
|
+
diskGib: z.number().int().min(1).optional(),
|
|
879
779
|
/** Skip the capacity guard when a running box grows (#37). */
|
|
880
|
-
force:
|
|
780
|
+
force: z.boolean().optional()
|
|
881
781
|
});
|
|
882
|
-
var StartMachineRequest =
|
|
883
|
-
force:
|
|
782
|
+
var StartMachineRequest = z.object({
|
|
783
|
+
force: z.boolean().optional()
|
|
884
784
|
});
|
|
885
|
-
var SetMachineRequest =
|
|
785
|
+
var SetMachineRequest = z.object({
|
|
886
786
|
/** Seconds without network traffic before the box is hibernated (#47); 0: never. */
|
|
887
|
-
autoHibernateSec:
|
|
787
|
+
autoHibernateSec: z.number().int().min(0).optional(),
|
|
888
788
|
/** The box's idle check (#102): an absolute path to a script inside the box, exit 0 = idle; "": none, back to network traffic. */
|
|
889
|
-
idleCheck:
|
|
789
|
+
idleCheck: z.union([z.literal(""), z.string().max(255).regex(/^\/[^\0\n]*$/, "an absolute path inside the box")]).optional()
|
|
890
790
|
});
|
|
891
|
-
var SnapshotSchema =
|
|
892
|
-
name:
|
|
893
|
-
owner:
|
|
894
|
-
source:
|
|
791
|
+
var SnapshotSchema = z.object({
|
|
792
|
+
name: z.string(),
|
|
793
|
+
owner: z.string(),
|
|
794
|
+
source: z.string(),
|
|
895
795
|
// the box it was taken from, as owner/name
|
|
896
|
-
base:
|
|
796
|
+
base: z.string(),
|
|
897
797
|
// version of the image the overlay stacks on; a restore needs the same one
|
|
898
798
|
/** As in MachineSchema: the image when it is not the base one (#87). */
|
|
899
|
-
image:
|
|
900
|
-
vcpu:
|
|
901
|
-
memMib:
|
|
902
|
-
sizeBytes:
|
|
799
|
+
image: z.string().optional(),
|
|
800
|
+
vcpu: z.number().int(),
|
|
801
|
+
memMib: z.number().int(),
|
|
802
|
+
sizeBytes: z.number().int(),
|
|
903
803
|
// what vmstate + mem + overlay really occupy on the host
|
|
904
|
-
createdAt:
|
|
804
|
+
createdAt: z.string()
|
|
905
805
|
});
|
|
906
|
-
var CreateSnapshotRequest =
|
|
907
|
-
box:
|
|
908
|
-
name:
|
|
806
|
+
var CreateSnapshotRequest = z.object({
|
|
807
|
+
box: z.string(),
|
|
808
|
+
name: z.string(),
|
|
909
809
|
/** Retake a snapshot under a name that exists (#83): the old one goes only once the new one is complete. */
|
|
910
|
-
replace:
|
|
911
|
-
});
|
|
912
|
-
var DiskCapacitySchema =
|
|
913
|
-
totalGib:
|
|
914
|
-
freeGib:
|
|
915
|
-
volumesGib:
|
|
916
|
-
volumesUsedGib:
|
|
917
|
-
headroomGib:
|
|
918
|
-
});
|
|
919
|
-
var CapacitySchema =
|
|
920
|
-
hostMemMib:
|
|
921
|
-
hostCores:
|
|
922
|
-
reservedMemMib:
|
|
923
|
-
reservedVcpu:
|
|
924
|
-
running:
|
|
810
|
+
replace: z.boolean().optional()
|
|
811
|
+
});
|
|
812
|
+
var DiskCapacitySchema = z.object({
|
|
813
|
+
totalGib: z.number().int(),
|
|
814
|
+
freeGib: z.number().int(),
|
|
815
|
+
volumesGib: z.number().int(),
|
|
816
|
+
volumesUsedGib: z.number().int(),
|
|
817
|
+
headroomGib: z.number().int()
|
|
818
|
+
});
|
|
819
|
+
var CapacitySchema = z.object({
|
|
820
|
+
hostMemMib: z.number().int(),
|
|
821
|
+
hostCores: z.number().int(),
|
|
822
|
+
reservedMemMib: z.number().int(),
|
|
823
|
+
reservedVcpu: z.number().int(),
|
|
824
|
+
running: z.number().int(),
|
|
925
825
|
/** Absent on a host from before volumes (#91): it cannot take one. */
|
|
926
826
|
disk: DiskCapacitySchema.optional(),
|
|
927
827
|
/**
|
|
928
828
|
* The images a new box can be made from here (#87), with the version `new` uses; the base is `base`.
|
|
929
829
|
* Absent on a host from before images: it has only the base.
|
|
930
830
|
*/
|
|
931
|
-
images:
|
|
831
|
+
images: z.array(z.object({ name: z.string(), version: z.string() })).optional(),
|
|
932
832
|
/** kvbox-server's version, so the control plane's host list shows it without a call per host. Older servers omit it. */
|
|
933
|
-
version:
|
|
833
|
+
version: z.string().optional(),
|
|
934
834
|
/** Present on a host set up as a backup store: the disk its Garage keeps chunks on, and whether Garage runs. */
|
|
935
|
-
backupStore:
|
|
835
|
+
backupStore: z.object({ totalBytes: z.number().int(), freeBytes: z.number().int(), running: z.boolean() }).optional(),
|
|
936
836
|
/** True on a kvbox-server that reaches a backup store by its certificate's `pin`; older ones omit it and cannot back up to a store. */
|
|
937
|
-
storeClient:
|
|
837
|
+
storeClient: z.boolean().optional()
|
|
938
838
|
});
|
|
939
|
-
var ImageSchema =
|
|
940
|
-
var ImageIndexSchema =
|
|
941
|
-
updatedAt:
|
|
942
|
-
images:
|
|
839
|
+
var ImageSchema = z.object({ name: z.string(), version: z.string().nullable() });
|
|
840
|
+
var ImageIndexSchema = z.object({
|
|
841
|
+
updatedAt: z.string(),
|
|
842
|
+
images: z.record(z.string(), z.object({ version: z.string().min(1), minServer: z.string().min(1).optional() }))
|
|
943
843
|
});
|
|
944
|
-
var LatestImagesSchema =
|
|
945
|
-
updatedAt:
|
|
844
|
+
var LatestImagesSchema = z.object({
|
|
845
|
+
updatedAt: z.string().nullable(),
|
|
946
846
|
images: ImageIndexSchema.shape.images,
|
|
947
|
-
checkedAt:
|
|
948
|
-
});
|
|
949
|
-
var RecoveryReportSchema =
|
|
950
|
-
at:
|
|
951
|
-
booted:
|
|
952
|
-
leftStopped:
|
|
953
|
-
failed:
|
|
954
|
-
});
|
|
955
|
-
var HostUpdateSchema =
|
|
956
|
-
state:
|
|
957
|
-
startedAt:
|
|
958
|
-
finishedAt:
|
|
847
|
+
checkedAt: z.string().nullable()
|
|
848
|
+
});
|
|
849
|
+
var RecoveryReportSchema = z.object({
|
|
850
|
+
at: z.string(),
|
|
851
|
+
booted: z.array(z.string()),
|
|
852
|
+
leftStopped: z.array(z.string()),
|
|
853
|
+
failed: z.array(z.object({ box: z.string(), error: z.string() }))
|
|
854
|
+
});
|
|
855
|
+
var HostUpdateSchema = z.object({
|
|
856
|
+
state: z.enum(["running", "done", "failed"]),
|
|
857
|
+
startedAt: z.string(),
|
|
858
|
+
finishedAt: z.string().nullable(),
|
|
959
859
|
/** kvbox-server's version when the update started, and when it ended (null while running or when it failed before). */
|
|
960
|
-
from:
|
|
961
|
-
to:
|
|
962
|
-
error:
|
|
963
|
-
needsManual:
|
|
964
|
-
});
|
|
965
|
-
var HealthSchema =
|
|
966
|
-
ok:
|
|
967
|
-
version:
|
|
968
|
-
pid:
|
|
860
|
+
from: z.string(),
|
|
861
|
+
to: z.string().nullable(),
|
|
862
|
+
error: z.string().nullable(),
|
|
863
|
+
needsManual: z.array(z.string())
|
|
864
|
+
});
|
|
865
|
+
var HealthSchema = z.object({
|
|
866
|
+
ok: z.literal(true),
|
|
867
|
+
version: z.string(),
|
|
868
|
+
pid: z.number().int(),
|
|
969
869
|
/** Base image version new boxes get (null when the host has no usable base image yet). */
|
|
970
|
-
base:
|
|
870
|
+
base: z.string().nullable(),
|
|
971
871
|
/** Owner that boxes made over the local socket get (the Unix user running the server). */
|
|
972
|
-
owner:
|
|
872
|
+
owner: z.string(),
|
|
973
873
|
/** The control plane this host joined (null when none). */
|
|
974
|
-
controlPlane:
|
|
874
|
+
controlPlane: z.object({
|
|
975
875
|
/** Realm name, e.g. kvbox.sh. */
|
|
976
|
-
name:
|
|
977
|
-
url:
|
|
876
|
+
name: z.string(),
|
|
877
|
+
url: z.string(),
|
|
978
878
|
/** Where this host answers the control plane. */
|
|
979
|
-
hostUrl:
|
|
879
|
+
hostUrl: z.string()
|
|
980
880
|
}).nullable(),
|
|
981
881
|
/** The relay this host reaches the internet through (#50); null when it has its own public address. Older servers omit it. */
|
|
982
|
-
relay:
|
|
983
|
-
name:
|
|
882
|
+
relay: z.object({
|
|
883
|
+
name: z.string(),
|
|
984
884
|
/** The public IP the relay owns for this host. */
|
|
985
|
-
publicIp:
|
|
885
|
+
publicIp: z.string(),
|
|
986
886
|
/** The relay's WireGuard endpoint the tunnel dials. */
|
|
987
|
-
endpoint:
|
|
887
|
+
endpoint: z.string(),
|
|
988
888
|
/** Times the server redialed the tunnel since it started, because the relay stopped answering. Older servers omit them. */
|
|
989
|
-
restarts:
|
|
990
|
-
lastRestartAt:
|
|
889
|
+
restarts: z.number().int().optional(),
|
|
890
|
+
lastRestartAt: z.string().nullable().optional()
|
|
991
891
|
}).nullable().optional(),
|
|
992
892
|
/** Boxes brought back at the server's last start; null when there were none or it is still at it. Older servers omit it. */
|
|
993
893
|
recovery: RecoveryReportSchema.nullable().optional(),
|
|
994
894
|
/** The last self-update; null when none ran. Older servers omit it. */
|
|
995
895
|
update: HostUpdateSchema.nullable().optional()
|
|
996
896
|
});
|
|
997
|
-
var MachineUsageSchema =
|
|
998
|
-
name:
|
|
999
|
-
owner:
|
|
897
|
+
var MachineUsageSchema = z.object({
|
|
898
|
+
name: z.string(),
|
|
899
|
+
owner: z.string(),
|
|
1000
900
|
status: BoxStatusSchema,
|
|
1001
|
-
window:
|
|
1002
|
-
seconds:
|
|
1003
|
-
running:
|
|
1004
|
-
standby:
|
|
1005
|
-
hibernated:
|
|
1006
|
-
stopped:
|
|
901
|
+
window: z.object({ from: z.string(), to: z.string() }),
|
|
902
|
+
seconds: z.object({
|
|
903
|
+
running: z.number().int(),
|
|
904
|
+
standby: z.number().int(),
|
|
905
|
+
hibernated: z.number().int(),
|
|
906
|
+
stopped: z.number().int()
|
|
1007
907
|
}),
|
|
1008
|
-
vcpuHours:
|
|
1009
|
-
ramGibHours:
|
|
1010
|
-
diskGibHours:
|
|
1011
|
-
cost:
|
|
908
|
+
vcpuHours: z.number(),
|
|
909
|
+
ramGibHours: z.number(),
|
|
910
|
+
diskGibHours: z.number(),
|
|
911
|
+
cost: z.object({ amount: z.number(), currency: z.string() }).optional(),
|
|
1012
912
|
/** Stops the server did not witness (Firecracker died, host rebooted) and dated to when it noticed. */
|
|
1013
|
-
estimatedStops:
|
|
1014
|
-
historyFrom:
|
|
913
|
+
estimatedStops: z.number().int(),
|
|
914
|
+
historyFrom: z.string().nullable()
|
|
1015
915
|
});
|
|
1016
|
-
var GuestStatsSchema =
|
|
916
|
+
var GuestStatsSchema = z.object({
|
|
1017
917
|
/** Load average over 1, 5 and 15 minutes. */
|
|
1018
|
-
load:
|
|
1019
|
-
cpus:
|
|
1020
|
-
memTotalMib:
|
|
918
|
+
load: z.tuple([z.number(), z.number(), z.number()]),
|
|
919
|
+
cpus: z.number().int(),
|
|
920
|
+
memTotalMib: z.number().int(),
|
|
1021
921
|
/** Total minus available: page cache counts as free. */
|
|
1022
|
-
memUsedMib:
|
|
922
|
+
memUsedMib: z.number().int(),
|
|
1023
923
|
/** The box's root, which is its overlay disk: the box's own writes, not the shared base. */
|
|
1024
|
-
diskTotalBytes:
|
|
1025
|
-
diskUsedBytes:
|
|
1026
|
-
uptimeSec:
|
|
924
|
+
diskTotalBytes: z.number().int(),
|
|
925
|
+
diskUsedBytes: z.number().int(),
|
|
926
|
+
uptimeSec: z.number().int()
|
|
1027
927
|
});
|
|
1028
|
-
var MachineStatsSchema =
|
|
1029
|
-
name:
|
|
1030
|
-
owner:
|
|
928
|
+
var MachineStatsSchema = z.object({
|
|
929
|
+
name: z.string(),
|
|
930
|
+
owner: z.string(),
|
|
1031
931
|
stats: GuestStatsSchema.nullable()
|
|
1032
932
|
});
|
|
1033
|
-
var UsageStatusSchema =
|
|
933
|
+
var UsageStatusSchema = z.enum([...BoxStatusSchema.options, "removed"]);
|
|
1034
934
|
var BoxUsageSchema = MachineUsageSchema.omit({ window: true, status: true }).extend({
|
|
1035
935
|
/** The host's box id; a name removed and recreated appears twice, with two ids. */
|
|
1036
|
-
id:
|
|
936
|
+
id: z.string(),
|
|
1037
937
|
status: UsageStatusSchema,
|
|
1038
938
|
/** Through a control plane: whether the owner slug is a user's or an org's (what `kvbox ls` shows). */
|
|
1039
|
-
ownerKind:
|
|
939
|
+
ownerKind: z.enum(["user", "org"]).optional(),
|
|
1040
940
|
/**
|
|
1041
941
|
* Through a control plane: the username that made the box (#60), absent when the box is gone from
|
|
1042
942
|
* the index (removed), was found by reconcile, or its maker was deleted. The ledger does not record it.
|
|
1043
943
|
*/
|
|
1044
|
-
createdBy:
|
|
944
|
+
createdBy: z.string().optional()
|
|
1045
945
|
});
|
|
1046
|
-
var VolumeUsageSchema =
|
|
946
|
+
var VolumeUsageSchema = z.object({
|
|
1047
947
|
/** The host's volume id; a name removed and made again appears twice, with two ids. */
|
|
1048
|
-
id:
|
|
1049
|
-
name:
|
|
1050
|
-
owner:
|
|
1051
|
-
ownerKind:
|
|
948
|
+
id: z.string(),
|
|
949
|
+
name: z.string(),
|
|
950
|
+
owner: z.string(),
|
|
951
|
+
ownerKind: z.enum(["user", "org"]).optional(),
|
|
1052
952
|
/** The size at the end of the window (or when removed). */
|
|
1053
|
-
sizeGib:
|
|
1054
|
-
status:
|
|
1055
|
-
volumeHours:
|
|
1056
|
-
volumeGibHours:
|
|
1057
|
-
cost:
|
|
1058
|
-
historyFrom:
|
|
1059
|
-
});
|
|
1060
|
-
var CronUsageSchema =
|
|
1061
|
-
id:
|
|
1062
|
-
name:
|
|
1063
|
-
owner:
|
|
1064
|
-
ownerKind:
|
|
1065
|
-
status:
|
|
1066
|
-
hours:
|
|
1067
|
-
cost:
|
|
953
|
+
sizeGib: z.number().int(),
|
|
954
|
+
status: z.enum(["present", "removed"]),
|
|
955
|
+
volumeHours: z.number(),
|
|
956
|
+
volumeGibHours: z.number(),
|
|
957
|
+
cost: z.object({ amount: z.number(), currency: z.string() }).optional(),
|
|
958
|
+
historyFrom: z.string().nullable()
|
|
959
|
+
});
|
|
960
|
+
var CronUsageSchema = z.object({
|
|
961
|
+
id: z.string(),
|
|
962
|
+
name: z.string(),
|
|
963
|
+
owner: z.string(),
|
|
964
|
+
ownerKind: z.enum(["user", "org"]).optional(),
|
|
965
|
+
status: z.enum(["present", "removed"]),
|
|
966
|
+
hours: z.number(),
|
|
967
|
+
cost: z.object({ amount: z.number(), currency: z.string() }).optional(),
|
|
1068
968
|
/** When it was made. */
|
|
1069
|
-
historyFrom:
|
|
969
|
+
historyFrom: z.string().nullable()
|
|
1070
970
|
});
|
|
1071
|
-
var UsageDayItemSchema =
|
|
1072
|
-
id:
|
|
1073
|
-
name:
|
|
1074
|
-
owner:
|
|
971
|
+
var UsageDayItemSchema = z.object({
|
|
972
|
+
id: z.string(),
|
|
973
|
+
name: z.string(),
|
|
974
|
+
owner: z.string(),
|
|
1075
975
|
/** Removed by the end of the report's window. */
|
|
1076
|
-
removed:
|
|
1077
|
-
cost:
|
|
976
|
+
removed: z.boolean(),
|
|
977
|
+
cost: z.number()
|
|
1078
978
|
});
|
|
1079
|
-
var UsageDaySchema =
|
|
979
|
+
var UsageDaySchema = z.object({
|
|
1080
980
|
/** `YYYY-MM-DD`, UTC. */
|
|
1081
|
-
date:
|
|
1082
|
-
from:
|
|
1083
|
-
to:
|
|
1084
|
-
cost:
|
|
1085
|
-
currency:
|
|
1086
|
-
boxes:
|
|
1087
|
-
volumes:
|
|
981
|
+
date: z.string(),
|
|
982
|
+
from: z.string(),
|
|
983
|
+
to: z.string(),
|
|
984
|
+
cost: z.number(),
|
|
985
|
+
currency: z.string(),
|
|
986
|
+
boxes: z.array(UsageDayItemSchema),
|
|
987
|
+
volumes: z.array(UsageDayItemSchema),
|
|
1088
988
|
/** Object storage that existed that day (#182); absent on a day without any. */
|
|
1089
|
-
storage:
|
|
989
|
+
storage: z.array(UsageDayItemSchema).optional(),
|
|
1090
990
|
/** Cron services that existed that day (#190); absent on a day without any. */
|
|
1091
|
-
cron:
|
|
991
|
+
cron: z.array(UsageDayItemSchema).optional()
|
|
1092
992
|
});
|
|
1093
|
-
var UsageReportSchema =
|
|
1094
|
-
window:
|
|
1095
|
-
boxes:
|
|
993
|
+
var UsageReportSchema = z.object({
|
|
994
|
+
window: z.object({ from: z.string(), to: z.string() }),
|
|
995
|
+
boxes: z.array(BoxUsageSchema),
|
|
1096
996
|
/** Absent from a side older than #91. */
|
|
1097
|
-
volumes:
|
|
997
|
+
volumes: z.array(VolumeUsageSchema).optional(),
|
|
1098
998
|
/**
|
|
1099
999
|
* Object storage (#182, control plane only): one row per storage a slug has or had, shaped like a
|
|
1100
1000
|
* volume's. `volumeHours` are the hours it existed, `volumeGibHours` those of the GiB beyond the
|
|
1101
1001
|
* included ones, `sizeGib` its whole size. Absent when there is none.
|
|
1102
1002
|
*/
|
|
1103
|
-
storage:
|
|
1003
|
+
storage: z.array(VolumeUsageSchema).optional(),
|
|
1104
1004
|
/** Cron services (#190, control plane only): one row per service a slug has or had. Absent when there is none. */
|
|
1105
|
-
cron:
|
|
1005
|
+
cron: z.array(CronUsageSchema).optional(),
|
|
1106
1006
|
/** With `?by=day` only, oldest day first. */
|
|
1107
|
-
days:
|
|
1108
|
-
totals:
|
|
1007
|
+
days: z.array(UsageDaySchema).optional(),
|
|
1008
|
+
totals: z.object({
|
|
1109
1009
|
seconds: MachineUsageSchema.shape.seconds,
|
|
1110
|
-
vcpuHours:
|
|
1111
|
-
ramGibHours:
|
|
1112
|
-
diskGibHours:
|
|
1113
|
-
volumeHours:
|
|
1114
|
-
volumeGibHours:
|
|
1010
|
+
vcpuHours: z.number(),
|
|
1011
|
+
ramGibHours: z.number(),
|
|
1012
|
+
diskGibHours: z.number(),
|
|
1013
|
+
volumeHours: z.number().optional(),
|
|
1014
|
+
volumeGibHours: z.number().optional(),
|
|
1115
1015
|
/** Boxes, volumes, object storage and cron services together. */
|
|
1116
|
-
cost:
|
|
1016
|
+
cost: z.object({ amount: z.number(), currency: z.string() }).optional()
|
|
1117
1017
|
})
|
|
1118
1018
|
});
|
|
1119
|
-
var UsageEventRowSchema =
|
|
1120
|
-
id:
|
|
1121
|
-
boxId:
|
|
1122
|
-
owner:
|
|
1123
|
-
name:
|
|
1124
|
-
at:
|
|
1125
|
-
state:
|
|
1126
|
-
vcpu:
|
|
1127
|
-
memMib:
|
|
1128
|
-
diskGib:
|
|
1129
|
-
by:
|
|
1130
|
-
});
|
|
1131
|
-
var UsageEventsResponseSchema =
|
|
1132
|
-
ledger:
|
|
1133
|
-
events:
|
|
1134
|
-
next:
|
|
1135
|
-
});
|
|
1136
|
-
var VolumeEventRowSchema =
|
|
1137
|
-
id:
|
|
1138
|
-
volumeId:
|
|
1139
|
-
owner:
|
|
1140
|
-
name:
|
|
1141
|
-
at:
|
|
1142
|
-
sizeGib:
|
|
1143
|
-
by:
|
|
1144
|
-
});
|
|
1145
|
-
var VolumeEventsResponseSchema =
|
|
1146
|
-
ledger:
|
|
1147
|
-
events:
|
|
1148
|
-
next:
|
|
1019
|
+
var UsageEventRowSchema = z.object({
|
|
1020
|
+
id: z.number().int(),
|
|
1021
|
+
boxId: z.string(),
|
|
1022
|
+
owner: z.string(),
|
|
1023
|
+
name: z.string(),
|
|
1024
|
+
at: z.string(),
|
|
1025
|
+
state: z.enum(["running", "standby", "hibernated", "stopped"]),
|
|
1026
|
+
vcpu: z.number().int(),
|
|
1027
|
+
memMib: z.number().int(),
|
|
1028
|
+
diskGib: z.number().int(),
|
|
1029
|
+
by: z.string()
|
|
1030
|
+
});
|
|
1031
|
+
var UsageEventsResponseSchema = z.object({
|
|
1032
|
+
ledger: z.string().min(1),
|
|
1033
|
+
events: z.array(UsageEventRowSchema),
|
|
1034
|
+
next: z.number().int()
|
|
1035
|
+
});
|
|
1036
|
+
var VolumeEventRowSchema = z.object({
|
|
1037
|
+
id: z.number().int(),
|
|
1038
|
+
volumeId: z.string(),
|
|
1039
|
+
owner: z.string(),
|
|
1040
|
+
name: z.string(),
|
|
1041
|
+
at: z.string(),
|
|
1042
|
+
sizeGib: z.number().int(),
|
|
1043
|
+
by: z.enum(["create", "resize", "rm"])
|
|
1044
|
+
});
|
|
1045
|
+
var VolumeEventsResponseSchema = z.object({
|
|
1046
|
+
ledger: z.string().min(1),
|
|
1047
|
+
events: z.array(VolumeEventRowSchema),
|
|
1048
|
+
next: z.number().int()
|
|
1149
1049
|
});
|
|
1150
1050
|
var API_ERROR_CODES = ["account-inactive", "org-inactive", "out-of-credit"];
|
|
1151
|
-
var ApiErrorCodeSchema =
|
|
1152
|
-
var ApiErrorSchema =
|
|
1153
|
-
error:
|
|
1051
|
+
var ApiErrorCodeSchema = z.enum(API_ERROR_CODES);
|
|
1052
|
+
var ApiErrorSchema = z.object({
|
|
1053
|
+
error: z.string(),
|
|
1154
1054
|
code: ApiErrorCodeSchema.optional()
|
|
1155
1055
|
});
|
|
1156
1056
|
var DEFAULT_CLOUD_URL = "https://api.kvbox.sh";
|
|
1157
1057
|
var ACTIVATED_BY = ["card", "admin"];
|
|
1158
|
-
var ActivatedBySchema =
|
|
1159
|
-
var CloudUserSchema =
|
|
1058
|
+
var ActivatedBySchema = z.enum(ACTIVATED_BY);
|
|
1059
|
+
var CloudUserSchema = z.object({
|
|
1160
1060
|
/** The handle: what hosts file boxes under (`<username>@<control plane>`). Lowercase, no `@` or `/`. */
|
|
1161
|
-
username:
|
|
1061
|
+
username: z.string(),
|
|
1162
1062
|
/** Display name, free text ("Alexandru Ghiura"). */
|
|
1163
|
-
name:
|
|
1063
|
+
name: z.string(),
|
|
1164
1064
|
/** Login identity, unique. */
|
|
1165
|
-
email:
|
|
1166
|
-
role:
|
|
1167
|
-
createdAt:
|
|
1065
|
+
email: z.string(),
|
|
1066
|
+
role: z.enum(["admin", "user"]),
|
|
1067
|
+
createdAt: z.string(),
|
|
1168
1068
|
/**
|
|
1169
1069
|
* False until a card is on file or an admin activates the account (#74): then only `/me` and
|
|
1170
1070
|
* `/logout` answer. Admins are never gated. A control plane older than #74 does not send these and
|
|
1171
1071
|
* gates nobody, hence the defaults: a newer CLI must still parse its answers.
|
|
1172
1072
|
*/
|
|
1173
|
-
active:
|
|
1073
|
+
active: z.boolean().default(true),
|
|
1174
1074
|
activatedBy: ActivatedBySchema.nullable().default(null),
|
|
1175
1075
|
/** When too many wrong passwords locked the account (#161); null when it is not locked. Older control planes omit it. */
|
|
1176
|
-
lockedAt:
|
|
1076
|
+
lockedAt: z.string().nullable().default(null)
|
|
1177
1077
|
});
|
|
1178
1078
|
var ORG_ROLES = ["owner", "admin", "member"];
|
|
1179
|
-
var OrgRoleSchema =
|
|
1180
|
-
var CloudOrgSchema =
|
|
1181
|
-
slug:
|
|
1079
|
+
var OrgRoleSchema = z.enum(ORG_ROLES);
|
|
1080
|
+
var CloudOrgSchema = z.object({
|
|
1081
|
+
slug: z.string(),
|
|
1182
1082
|
/** Display name; the slug never changes, this may. */
|
|
1183
|
-
name:
|
|
1184
|
-
createdAt:
|
|
1083
|
+
name: z.string(),
|
|
1084
|
+
createdAt: z.string(),
|
|
1185
1085
|
/** An org pays for itself (#74): off until it has a card or an admin activates it; its boxes are 402. Defaults as on CloudUser. */
|
|
1186
|
-
active:
|
|
1086
|
+
active: z.boolean().default(true),
|
|
1187
1087
|
activatedBy: ActivatedBySchema.nullable().default(null)
|
|
1188
1088
|
});
|
|
1189
1089
|
var OrgMembershipSchema = CloudOrgSchema.extend({ role: OrgRoleSchema });
|
|
1190
|
-
var OrgMemberSchema =
|
|
1191
|
-
username:
|
|
1192
|
-
name:
|
|
1090
|
+
var OrgMemberSchema = z.object({
|
|
1091
|
+
username: z.string(),
|
|
1092
|
+
name: z.string(),
|
|
1193
1093
|
role: OrgRoleSchema,
|
|
1194
|
-
addedAt:
|
|
1094
|
+
addedAt: z.string()
|
|
1195
1095
|
});
|
|
1196
|
-
var OrgDetailSchema = CloudOrgSchema.extend({ members:
|
|
1197
|
-
var CreateOrgRequestSchema =
|
|
1198
|
-
slug:
|
|
1199
|
-
name:
|
|
1096
|
+
var OrgDetailSchema = CloudOrgSchema.extend({ members: z.array(OrgMemberSchema) });
|
|
1097
|
+
var CreateOrgRequestSchema = z.object({
|
|
1098
|
+
slug: z.string().min(1),
|
|
1099
|
+
name: z.string().min(1)
|
|
1200
1100
|
});
|
|
1201
|
-
var RenameOrgRequestSchema =
|
|
1202
|
-
var AddMemberRequestSchema =
|
|
1203
|
-
username:
|
|
1101
|
+
var RenameOrgRequestSchema = z.object({ name: z.string().min(1) });
|
|
1102
|
+
var AddMemberRequestSchema = z.object({
|
|
1103
|
+
username: z.string().min(1),
|
|
1204
1104
|
role: OrgRoleSchema.default("member")
|
|
1205
1105
|
});
|
|
1206
|
-
var SetRoleRequestSchema =
|
|
1207
|
-
var MeResponseSchema = CloudUserSchema.extend({ orgs:
|
|
1208
|
-
var BalanceSchema =
|
|
1209
|
-
slug:
|
|
1210
|
-
balance:
|
|
1211
|
-
currency:
|
|
1212
|
-
topUps:
|
|
1213
|
-
spent:
|
|
1106
|
+
var SetRoleRequestSchema = z.object({ role: OrgRoleSchema });
|
|
1107
|
+
var MeResponseSchema = CloudUserSchema.extend({ orgs: z.array(OrgMembershipSchema) });
|
|
1108
|
+
var BalanceSchema = z.object({
|
|
1109
|
+
slug: z.string(),
|
|
1110
|
+
balance: z.number(),
|
|
1111
|
+
currency: z.string(),
|
|
1112
|
+
topUps: z.number(),
|
|
1113
|
+
spent: z.number(),
|
|
1214
1114
|
/** The first moment usage counts from: the slug's first top-up or redeemed code; null when it has none. */
|
|
1215
|
-
since:
|
|
1115
|
+
since: z.string().nullable(),
|
|
1216
1116
|
/** When the slug ran out and its boxes were hibernated (the `sweep-credit` job); null in good standing. Absent from a control plane older than this field. */
|
|
1217
|
-
suspendedAt:
|
|
1117
|
+
suspendedAt: z.string().nullable().default(null),
|
|
1218
1118
|
/** Promo credit left (#163), already counted in `balance`; 0 with none. Absent from a control plane older than this field. */
|
|
1219
|
-
promo:
|
|
1119
|
+
promo: z.number().default(0),
|
|
1220
1120
|
/** When the next promo credit expires; null with none left. */
|
|
1221
|
-
promoExpiresAt:
|
|
1121
|
+
promoExpiresAt: z.string().nullable().default(null)
|
|
1222
1122
|
});
|
|
1223
|
-
var TopUpRequestSchema =
|
|
1224
|
-
slug:
|
|
1123
|
+
var TopUpRequestSchema = z.object({
|
|
1124
|
+
slug: z.string().min(1),
|
|
1225
1125
|
/** In the control plane's currency; negative corrects a mistake. */
|
|
1226
|
-
amount:
|
|
1227
|
-
note:
|
|
1228
|
-
});
|
|
1229
|
-
var TopUpSchema =
|
|
1230
|
-
id:
|
|
1231
|
-
slug:
|
|
1232
|
-
amount:
|
|
1233
|
-
currency:
|
|
1126
|
+
amount: z.number().finite(),
|
|
1127
|
+
note: z.string().max(200).optional()
|
|
1128
|
+
});
|
|
1129
|
+
var TopUpSchema = z.object({
|
|
1130
|
+
id: z.string(),
|
|
1131
|
+
slug: z.string(),
|
|
1132
|
+
amount: z.number(),
|
|
1133
|
+
currency: z.string(),
|
|
1234
1134
|
/** `transfer` (#93): an owner moving credit to an org they own, a negative row on their slug and a positive one on the org's. */
|
|
1235
|
-
source:
|
|
1236
|
-
note:
|
|
1237
|
-
at:
|
|
1135
|
+
source: z.enum(["admin", "card", "trial", "transfer"]),
|
|
1136
|
+
note: z.string().nullable(),
|
|
1137
|
+
at: z.string()
|
|
1238
1138
|
});
|
|
1239
|
-
var CreateCodeRequestSchema =
|
|
1139
|
+
var CreateCodeRequestSchema = z.object({
|
|
1240
1140
|
/** In the control plane's currency, cents at most. */
|
|
1241
|
-
amount:
|
|
1141
|
+
amount: z.number().positive().multipleOf(0.01, "amount is in cents at most"),
|
|
1242
1142
|
/** A day (`2026-12-11`, through the end of it, UTC) or an ISO time. The credit is gone then, and so is the code. */
|
|
1243
|
-
expiresAt:
|
|
1244
|
-
note:
|
|
1245
|
-
});
|
|
1246
|
-
var CreditCodeSchema =
|
|
1247
|
-
code:
|
|
1248
|
-
amount:
|
|
1249
|
-
currency:
|
|
1250
|
-
expiresAt:
|
|
1251
|
-
note:
|
|
1252
|
-
status:
|
|
1253
|
-
createdBy:
|
|
1254
|
-
createdAt:
|
|
1143
|
+
expiresAt: z.string().min(1),
|
|
1144
|
+
note: z.string().max(200).optional()
|
|
1145
|
+
});
|
|
1146
|
+
var CreditCodeSchema = z.object({
|
|
1147
|
+
code: z.string(),
|
|
1148
|
+
amount: z.number(),
|
|
1149
|
+
currency: z.string(),
|
|
1150
|
+
expiresAt: z.string(),
|
|
1151
|
+
note: z.string().nullable(),
|
|
1152
|
+
status: z.enum(["unused", "redeemed", "expired", "revoked"]),
|
|
1153
|
+
createdBy: z.string(),
|
|
1154
|
+
createdAt: z.string(),
|
|
1255
1155
|
/** Who redeemed it and the slug the credit went to (their own, or an org they own). */
|
|
1256
|
-
redeemedBy:
|
|
1257
|
-
redeemedSlug:
|
|
1258
|
-
redeemedAt:
|
|
1259
|
-
revokedAt:
|
|
1260
|
-
});
|
|
1261
|
-
var RedeemRequestSchema =
|
|
1262
|
-
code:
|
|
1263
|
-
org:
|
|
1264
|
-
});
|
|
1265
|
-
var RedeemResponseSchema =
|
|
1266
|
-
slug:
|
|
1267
|
-
amount:
|
|
1268
|
-
currency:
|
|
1269
|
-
expiresAt:
|
|
1156
|
+
redeemedBy: z.string().nullable(),
|
|
1157
|
+
redeemedSlug: z.string().nullable(),
|
|
1158
|
+
redeemedAt: z.string().nullable(),
|
|
1159
|
+
revokedAt: z.string().nullable()
|
|
1160
|
+
});
|
|
1161
|
+
var RedeemRequestSchema = z.object({
|
|
1162
|
+
code: z.string().min(1).max(64),
|
|
1163
|
+
org: z.string().min(1).optional()
|
|
1164
|
+
});
|
|
1165
|
+
var RedeemResponseSchema = z.object({
|
|
1166
|
+
slug: z.string(),
|
|
1167
|
+
amount: z.number(),
|
|
1168
|
+
currency: z.string(),
|
|
1169
|
+
expiresAt: z.string(),
|
|
1270
1170
|
balance: BalanceSchema,
|
|
1271
1171
|
/** The slug was out of credit and this put it back above zero: it may start boxes again. */
|
|
1272
|
-
reinstated:
|
|
1172
|
+
reinstated: z.boolean()
|
|
1273
1173
|
});
|
|
1274
1174
|
var TOP_UP_AMOUNTS = [10, 25, 50, 100];
|
|
1275
|
-
var BillingInfoSchema =
|
|
1276
|
-
card:
|
|
1277
|
-
cardInUse:
|
|
1175
|
+
var BillingInfoSchema = z.object({
|
|
1176
|
+
card: z.object({ brand: z.string(), last4: z.string() }).nullable(),
|
|
1177
|
+
cardInUse: z.boolean(),
|
|
1278
1178
|
balance: BalanceSchema
|
|
1279
1179
|
});
|
|
1280
|
-
var BillingRedirectSchema =
|
|
1281
|
-
var TopUpCheckoutRequestSchema =
|
|
1282
|
-
amount:
|
|
1180
|
+
var BillingRedirectSchema = z.object({ url: z.string() });
|
|
1181
|
+
var TopUpCheckoutRequestSchema = z.object({
|
|
1182
|
+
amount: z.literal(TOP_UP_AMOUNTS)
|
|
1283
1183
|
});
|
|
1284
|
-
var TransferRequestSchema =
|
|
1285
|
-
org:
|
|
1286
|
-
amount:
|
|
1184
|
+
var TransferRequestSchema = z.object({
|
|
1185
|
+
org: z.string().min(1),
|
|
1186
|
+
amount: z.number().positive().multipleOf(0.01, "amount is in cents at most")
|
|
1287
1187
|
});
|
|
1288
|
-
var TransferResponseSchema =
|
|
1289
|
-
var LoginRequestSchema =
|
|
1290
|
-
email:
|
|
1291
|
-
password:
|
|
1292
|
-
publicKey:
|
|
1188
|
+
var TransferResponseSchema = z.object({ from: BalanceSchema, to: BalanceSchema, activated: z.boolean() });
|
|
1189
|
+
var LoginRequestSchema = z.object({
|
|
1190
|
+
email: z.string().min(1),
|
|
1191
|
+
password: z.string().min(1),
|
|
1192
|
+
publicKey: z.string().optional()
|
|
1293
1193
|
});
|
|
1294
|
-
var SignupRequestSchema =
|
|
1295
|
-
username:
|
|
1296
|
-
name:
|
|
1297
|
-
email:
|
|
1298
|
-
password:
|
|
1194
|
+
var SignupRequestSchema = z.object({
|
|
1195
|
+
username: z.string().min(1),
|
|
1196
|
+
name: z.string().min(1),
|
|
1197
|
+
email: z.string().min(1),
|
|
1198
|
+
password: z.string().min(1)
|
|
1299
1199
|
});
|
|
1300
|
-
var LoginResponseSchema =
|
|
1301
|
-
token:
|
|
1200
|
+
var LoginResponseSchema = z.object({
|
|
1201
|
+
token: z.string(),
|
|
1302
1202
|
user: CloudUserSchema,
|
|
1303
|
-
sshCert:
|
|
1304
|
-
sshCertExpires:
|
|
1203
|
+
sshCert: z.string().optional(),
|
|
1204
|
+
sshCertExpires: z.string().optional(),
|
|
1305
1205
|
/** Whose boxes the certificate opens: `<slug>@<realm>` for the user and each org they are in (orgs phase 4). */
|
|
1306
|
-
sshCertPrincipals:
|
|
1307
|
-
});
|
|
1308
|
-
var SshCertRequestSchema = z2.object({
|
|
1309
|
-
publicKey: z2.string().min(1)
|
|
1310
|
-
});
|
|
1311
|
-
var SshCertResponseSchema = z2.object({
|
|
1312
|
-
cert: z2.string(),
|
|
1313
|
-
expires: z2.string(),
|
|
1314
|
-
principals: z2.array(z2.string())
|
|
1206
|
+
sshCertPrincipals: z.array(z.string()).optional()
|
|
1315
1207
|
});
|
|
1316
|
-
var
|
|
1317
|
-
|
|
1208
|
+
var DEVICE_LOGIN_PICKUP_SEC = 60;
|
|
1209
|
+
var DeviceLoginRequestSchema = z.object({
|
|
1210
|
+
// Capped: anyone may open a login, and the key is stored until it expires (an RSA-16384 key is ~2.8 KB).
|
|
1211
|
+
publicKey: z.string().max(16384).optional(),
|
|
1212
|
+
hostname: z.string().max(255).optional()
|
|
1213
|
+
});
|
|
1214
|
+
var DeviceLoginStartSchema = z.object({
|
|
1215
|
+
deviceCode: z.string(),
|
|
1216
|
+
userCode: z.string(),
|
|
1217
|
+
verifyUrl: z.string(),
|
|
1218
|
+
expiresIn: z.number(),
|
|
1219
|
+
interval: z.number()
|
|
1220
|
+
});
|
|
1221
|
+
var DeviceLoginPollRequestSchema = z.object({ deviceCode: z.string().min(1) });
|
|
1222
|
+
var DeviceLoginPollSchema = z.union([
|
|
1223
|
+
z.object({ status: z.enum(["pending", "slow_down", "refused", "expired"]) }),
|
|
1224
|
+
LoginResponseSchema.extend({ status: z.literal("approved") })
|
|
1225
|
+
]);
|
|
1226
|
+
var DeviceLoginInfoSchema = z.object({
|
|
1227
|
+
userCode: z.string(),
|
|
1228
|
+
hostname: z.string(),
|
|
1229
|
+
/** The address the request came from; null when the control plane could not tell. */
|
|
1230
|
+
ip: z.string().nullable(),
|
|
1231
|
+
createdAt: z.string(),
|
|
1232
|
+
expiresAt: z.string()
|
|
1233
|
+
});
|
|
1234
|
+
var DEFAULT_API_KEY_DAYS = 90;
|
|
1235
|
+
var API_KEY_NAME_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/;
|
|
1236
|
+
var ApiKeySchema = z.object({
|
|
1237
|
+
name: z.string(),
|
|
1238
|
+
createdAt: z.string(),
|
|
1239
|
+
/** Last request made with it (ISO); null: never used. */
|
|
1240
|
+
lastUsedAt: z.string().nullable(),
|
|
1241
|
+
/** When it stops working (ISO); null: never. */
|
|
1242
|
+
expiresAt: z.string().nullable()
|
|
1243
|
+
});
|
|
1244
|
+
var CreateApiKeyRequestSchema = z.object({
|
|
1245
|
+
name: z.string().regex(API_KEY_NAME_RE, "a key's name is lowercase letters, digits, '.', '_' or '-' (up to 32 characters)"),
|
|
1246
|
+
expiresAt: z.iso.datetime({ offset: true }).nullable().optional()
|
|
1247
|
+
});
|
|
1248
|
+
var CreatedApiKeySchema = ApiKeySchema.extend({ key: z.string() });
|
|
1249
|
+
var SshCertRequestSchema = z.object({
|
|
1250
|
+
publicKey: z.string().min(1)
|
|
1251
|
+
});
|
|
1252
|
+
var SshCertResponseSchema = z.object({
|
|
1253
|
+
cert: z.string(),
|
|
1254
|
+
expires: z.string(),
|
|
1255
|
+
principals: z.array(z.string())
|
|
1256
|
+
});
|
|
1257
|
+
var SshCaResponseSchema = z.object({
|
|
1258
|
+
publicKey: z.string(),
|
|
1318
1259
|
/** CAs replaced by `ca rotate` (#55), newest first; a box still holding one of these has not had `kvbox-server trust-ca` run on its host. */
|
|
1319
|
-
retired:
|
|
1260
|
+
retired: z.array(z.object({ publicKey: z.string(), retiredAt: z.string() })).optional()
|
|
1320
1261
|
});
|
|
1321
|
-
var HostSshCaResponseSchema =
|
|
1322
|
-
publicKey:
|
|
1262
|
+
var HostSshCaResponseSchema = z.object({
|
|
1263
|
+
publicKey: z.string()
|
|
1323
1264
|
});
|
|
1324
|
-
var CloudCaSchema =
|
|
1325
|
-
controlPlane:
|
|
1326
|
-
publicKey:
|
|
1327
|
-
fingerprint:
|
|
1265
|
+
var CloudCaSchema = z.object({
|
|
1266
|
+
controlPlane: z.string(),
|
|
1267
|
+
publicKey: z.string(),
|
|
1268
|
+
fingerprint: z.string()
|
|
1328
1269
|
});
|
|
1329
|
-
var TrustCaRequestSchema =
|
|
1330
|
-
publicKey:
|
|
1270
|
+
var TrustCaRequestSchema = z.object({
|
|
1271
|
+
publicKey: z.string().min(1)
|
|
1331
1272
|
});
|
|
1332
|
-
var SshKeysAppliedSchema =
|
|
1333
|
-
var TrustCaReportSchema =
|
|
1334
|
-
publicKey:
|
|
1335
|
-
fingerprint:
|
|
1273
|
+
var SshKeysAppliedSchema = z.enum(["now", "start", "wake", "resume", "later"]);
|
|
1274
|
+
var TrustCaReportSchema = z.object({
|
|
1275
|
+
publicKey: z.string(),
|
|
1276
|
+
fingerprint: z.string(),
|
|
1336
1277
|
/** The guest trusts the CA now. */
|
|
1337
|
-
updated:
|
|
1278
|
+
updated: z.array(z.string()),
|
|
1338
1279
|
/** meta.json has the line; the guest gets it at `when`. */
|
|
1339
|
-
pending:
|
|
1340
|
-
failed:
|
|
1280
|
+
pending: z.array(z.object({ box: z.string(), when: SshKeysAppliedSchema, why: z.string().optional() })),
|
|
1281
|
+
failed: z.array(z.object({ box: z.string(), error: z.string() })),
|
|
1341
1282
|
/** Local boxes, untouched: they trust the host's key only. */
|
|
1342
|
-
local:
|
|
1283
|
+
local: z.number().int(),
|
|
1343
1284
|
/** Cloud boxes made without a CA line (a managed service's, #173), untouched: no certificate opens them. Absent from older servers. */
|
|
1344
|
-
skipped:
|
|
1345
|
-
});
|
|
1346
|
-
var HostJoinRequestSchema =
|
|
1347
|
-
token:
|
|
1348
|
-
name:
|
|
1349
|
-
url:
|
|
1350
|
-
fingerprint:
|
|
1351
|
-
publicAddress:
|
|
1285
|
+
skipped: z.array(z.string()).optional()
|
|
1286
|
+
});
|
|
1287
|
+
var HostJoinRequestSchema = z.object({
|
|
1288
|
+
token: z.string().min(1),
|
|
1289
|
+
name: z.string().min(1),
|
|
1290
|
+
url: z.string().url(),
|
|
1291
|
+
fingerprint: z.string().regex(/^([0-9A-F]{2}:){31}[0-9A-F]{2}$/),
|
|
1292
|
+
publicAddress: z.string().min(1),
|
|
1352
1293
|
/** Where the host is (`kvbox-server join --country`): a code or an English name. */
|
|
1353
|
-
country:
|
|
1294
|
+
country: z.string().optional()
|
|
1354
1295
|
});
|
|
1355
|
-
var HostJoinResponseSchema =
|
|
1356
|
-
hostSecret:
|
|
1357
|
-
controlPlane:
|
|
1296
|
+
var HostJoinResponseSchema = z.object({
|
|
1297
|
+
hostSecret: z.string(),
|
|
1298
|
+
controlPlane: z.object({ name: z.string() })
|
|
1358
1299
|
});
|
|
1359
|
-
var CloudHostSchema =
|
|
1360
|
-
name:
|
|
1361
|
-
url:
|
|
1362
|
-
publicAddress:
|
|
1363
|
-
joinedAt:
|
|
1364
|
-
lastSeenAt:
|
|
1300
|
+
var CloudHostSchema = z.object({
|
|
1301
|
+
name: z.string(),
|
|
1302
|
+
url: z.string(),
|
|
1303
|
+
publicAddress: z.string(),
|
|
1304
|
+
joinedAt: z.string(),
|
|
1305
|
+
lastSeenAt: z.string().nullable(),
|
|
1365
1306
|
capacity: CapacitySchema.nullable(),
|
|
1366
1307
|
/** ISO 3166-1 alpha-2 code (`RO`), null when nobody said where the host is. */
|
|
1367
|
-
country:
|
|
1308
|
+
country: z.string().nullable(),
|
|
1368
1309
|
/** The S3 region a storage made on this host answers to (`ro-west-1`); null: it takes no storage. */
|
|
1369
|
-
region:
|
|
1310
|
+
region: z.string().nullable(),
|
|
1370
1311
|
/** kvbox-server's version as of the poller's last look (`capacity.version`); null before one, or for a server older than 0.5.45. */
|
|
1371
|
-
version:
|
|
1312
|
+
version: z.string().nullable()
|
|
1372
1313
|
});
|
|
1373
|
-
var HostInfoSchema =
|
|
1314
|
+
var HostInfoSchema = z.object({
|
|
1374
1315
|
host: CloudHostSchema,
|
|
1375
1316
|
health: HealthSchema.nullable(),
|
|
1376
|
-
error:
|
|
1317
|
+
error: z.string().nullable()
|
|
1377
1318
|
});
|
|
1378
|
-
var HostPatchRequest =
|
|
1379
|
-
var CountrySchema =
|
|
1319
|
+
var HostPatchRequest = z.object({ country: z.string().nullable().optional(), region: z.string().nullable().optional() }).refine((b) => b.country !== void 0 || b.region !== void 0, { message: "give country, region or both" });
|
|
1320
|
+
var CountrySchema = z.object({ code: z.string(), name: z.string() });
|
|
1321
|
+
|
|
1322
|
+
// src/session.ts
|
|
1323
|
+
var SessionSchema = z2.object({
|
|
1324
|
+
url: z2.string(),
|
|
1325
|
+
token: z2.string(),
|
|
1326
|
+
user: z2.string(),
|
|
1327
|
+
/** When the SSH certificate at paths().sshCert stops being accepted (ISO); absent before the first login with a key. */
|
|
1328
|
+
sshCertExpires: z2.string().optional(),
|
|
1329
|
+
/** Whose boxes that certificate opens (`<slug>@<realm>`, the user and their orgs); absent with `sshCertExpires`. */
|
|
1330
|
+
sshCertPrincipals: z2.array(z2.string()).optional()
|
|
1331
|
+
});
|
|
1332
|
+
async function readSession(p = paths()) {
|
|
1333
|
+
let text2;
|
|
1334
|
+
try {
|
|
1335
|
+
text2 = await readFile(p.cli, "utf8");
|
|
1336
|
+
} catch (err) {
|
|
1337
|
+
if (err.code === "ENOENT") return null;
|
|
1338
|
+
throw err;
|
|
1339
|
+
}
|
|
1340
|
+
try {
|
|
1341
|
+
return SessionSchema.parse(JSON.parse(text2));
|
|
1342
|
+
} catch {
|
|
1343
|
+
throw new KvboxError(`${p.cli} is unreadable; run: kvbox logout (then log in again)`);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
async function writeSession(session, p = paths()) {
|
|
1347
|
+
await mkdir(p.home, { recursive: true });
|
|
1348
|
+
await writeFile(p.cli, JSON.stringify(session, null, 2) + "\n", { mode: 384 });
|
|
1349
|
+
await chmod(p.cli, 384);
|
|
1350
|
+
}
|
|
1351
|
+
async function clearSession(p = paths()) {
|
|
1352
|
+
await rm(p.cli, { force: true });
|
|
1353
|
+
}
|
|
1354
|
+
function envLogin(env = process.env) {
|
|
1355
|
+
const token = env["KVBOX_TOKEN"]?.trim();
|
|
1356
|
+
if (token === void 0 || token === "") return null;
|
|
1357
|
+
const url = env["KVBOX_URL"]?.trim();
|
|
1358
|
+
return { url: normalizeUrl(url === void 0 || url === "" ? DEFAULT_CLOUD_URL : url), token };
|
|
1359
|
+
}
|
|
1360
|
+
function hostOf(url) {
|
|
1361
|
+
try {
|
|
1362
|
+
return new URL(url).host;
|
|
1363
|
+
} catch {
|
|
1364
|
+
return url;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
function isLoopback(hostname) {
|
|
1368
|
+
return hostname === "localhost" || hostname.startsWith("127.") || hostname === "[::1]";
|
|
1369
|
+
}
|
|
1370
|
+
function normalizeUrl(input) {
|
|
1371
|
+
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(input) ? input : `https://${input}`;
|
|
1372
|
+
let url;
|
|
1373
|
+
try {
|
|
1374
|
+
url = new URL(withScheme);
|
|
1375
|
+
} catch {
|
|
1376
|
+
throw new KvboxError(`not a URL: ${input}`);
|
|
1377
|
+
}
|
|
1378
|
+
if (!/^https?:$/.test(url.protocol) || url.hostname === "" || /\s/.test(input)) throw new KvboxError(`not a URL: ${input}`);
|
|
1379
|
+
if (url.protocol === "http:" && !isLoopback(url.hostname)) {
|
|
1380
|
+
throw new KvboxError(`${input}: use https (plain http is only allowed for localhost)`);
|
|
1381
|
+
}
|
|
1382
|
+
return url.origin + url.pathname.replace(/\/+$/, "");
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
// src/cert.ts
|
|
1386
|
+
var RENEW_BEFORE_MS = 60 * 60 * 1e3;
|
|
1387
|
+
async function writeCert(cert, p = paths()) {
|
|
1388
|
+
const tmp = `${p.sshCert}.${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
1389
|
+
try {
|
|
1390
|
+
await writeFile2(tmp, cert.trim() + "\n", { mode: 420 });
|
|
1391
|
+
for (let attempt = 1; ; attempt++) {
|
|
1392
|
+
try {
|
|
1393
|
+
await rename(tmp, p.sshCert);
|
|
1394
|
+
break;
|
|
1395
|
+
} catch (err) {
|
|
1396
|
+
if (attempt >= 10 || !["EPERM", "EBUSY", "EACCES"].includes(err.code ?? "")) throw err;
|
|
1397
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
} finally {
|
|
1401
|
+
await rm2(tmp, { force: true });
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
async function renewAfterRefusal(client, kept, owner, p = paths()) {
|
|
1405
|
+
if (kept !== "kept") return false;
|
|
1406
|
+
await ensureCert(client, p, Date.now(), { owner, force: true });
|
|
1407
|
+
return true;
|
|
1408
|
+
}
|
|
1409
|
+
async function removeCert(p = paths()) {
|
|
1410
|
+
await rm2(p.sshCert, { force: true });
|
|
1411
|
+
}
|
|
1412
|
+
function sshKeygen(args) {
|
|
1413
|
+
const res = spawnSync("ssh-keygen", args, { stdio: ["ignore", "pipe", "pipe"], encoding: "utf8" });
|
|
1414
|
+
if (res.error) {
|
|
1415
|
+
if (res.error.code === "ENOENT") throw new KvboxError("ssh-keygen not found; install OpenSSH");
|
|
1416
|
+
throw new KvboxError(`could not run ssh-keygen: ${res.error.message}`);
|
|
1417
|
+
}
|
|
1418
|
+
if (res.status !== 0) throw new KvboxError(`ssh-keygen failed: ${res.stderr.trim()}`);
|
|
1419
|
+
return res.stdout;
|
|
1420
|
+
}
|
|
1421
|
+
async function placeKey(tmp, dest) {
|
|
1422
|
+
try {
|
|
1423
|
+
await link(tmp, dest);
|
|
1424
|
+
} catch (err) {
|
|
1425
|
+
if (!["EPERM", "ENOTSUP", "ENOSYS", "EXDEV", "EOPNOTSUPP"].includes(err.code ?? "")) throw err;
|
|
1426
|
+
await writeFile2(dest, await readFile2(tmp), { flag: "wx", mode: 384 });
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
async function ensureSshKey(p = paths(), hostname = osHostname()) {
|
|
1430
|
+
const pubPath = `${p.sshKey}.pub`;
|
|
1431
|
+
const pub = await readFile2(pubPath, "utf8").catch(() => null);
|
|
1432
|
+
if (pub !== null) return pub.trim();
|
|
1433
|
+
await mkdir2(p.ssh, { recursive: true, mode: 448 });
|
|
1434
|
+
const tmp = `${p.sshKey}.${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
1435
|
+
try {
|
|
1436
|
+
const havePrivate = await readFile2(p.sshKey).then(() => true, () => false);
|
|
1437
|
+
if (!havePrivate) {
|
|
1438
|
+
sshKeygen(["-q", "-t", "ed25519", "-N", "", "-C", `kvbox@${hostname}`, "-f", tmp]);
|
|
1439
|
+
try {
|
|
1440
|
+
await placeKey(tmp, p.sshKey);
|
|
1441
|
+
await rename(`${tmp}.pub`, pubPath);
|
|
1442
|
+
return (await readFile2(pubPath, "utf8")).trim();
|
|
1443
|
+
} catch (err) {
|
|
1444
|
+
if (err.code !== "EEXIST") throw err;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
let derived;
|
|
1448
|
+
for (let attempt = 1; derived === void 0; attempt++) {
|
|
1449
|
+
try {
|
|
1450
|
+
derived = sshKeygen(["-y", "-f", p.sshKey]);
|
|
1451
|
+
} catch (err) {
|
|
1452
|
+
if (attempt >= 10) throw err;
|
|
1453
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
await writeFile2(`${tmp}.pub`, derived.trim() + "\n");
|
|
1457
|
+
await rename(`${tmp}.pub`, pubPath);
|
|
1458
|
+
} finally {
|
|
1459
|
+
await rm2(tmp, { force: true });
|
|
1460
|
+
await rm2(`${tmp}.pub`, { force: true });
|
|
1461
|
+
}
|
|
1462
|
+
return (await readFile2(pubPath, "utf8")).trim();
|
|
1463
|
+
}
|
|
1464
|
+
async function forgetCertOf(p) {
|
|
1465
|
+
const session = await readSession(p).catch(() => null);
|
|
1466
|
+
if (!session || session.sshCertExpires === void 0) return;
|
|
1467
|
+
const { sshCertExpires: _expires, sshCertPrincipals: _principals, ...rest } = session;
|
|
1468
|
+
await writeSession(rest, p);
|
|
1469
|
+
}
|
|
1470
|
+
async function ensureCert(client, p = paths(), now = Date.now(), opts = {}) {
|
|
1471
|
+
if (client.target.kind !== "cloud") return "local";
|
|
1472
|
+
const fromEnv = client.target.env === true;
|
|
1473
|
+
const session = fromEnv ? null : await readSession(p);
|
|
1474
|
+
if (!fromEnv && !session) return "local";
|
|
1475
|
+
if (session) {
|
|
1476
|
+
const expires = session.sshCertExpires ? new Date(session.sshCertExpires).getTime() : 0;
|
|
1477
|
+
const onDisk = await readFile2(p.sshCert, "utf8").then(() => true, () => false);
|
|
1478
|
+
const names2 = opts.owner === void 0 || (session.sshCertPrincipals ?? []).includes(opts.owner);
|
|
1479
|
+
if (onDisk && expires - now > RENEW_BEFORE_MS && names2 && !opts.force) return "kept";
|
|
1480
|
+
}
|
|
1481
|
+
const publicKey = fromEnv ? await ensureSshKey(p) : await readFile2(`${p.sshKey}.pub`, "utf8").catch(() => null);
|
|
1482
|
+
if (publicKey === null) throw new KvboxError(`could not renew your SSH certificate: no key at ${p.sshKey}.pub; run: kvbox login`);
|
|
1483
|
+
let signed;
|
|
1484
|
+
try {
|
|
1485
|
+
signed = await client.sshCert({ publicKey: publicKey.trim() });
|
|
1486
|
+
} catch (err) {
|
|
1487
|
+
throw new KvboxError(`could not renew your SSH certificate: ${err.message}`);
|
|
1488
|
+
}
|
|
1489
|
+
await writeCert(signed.cert, p);
|
|
1490
|
+
if (session) await writeSession({ ...session, sshCertExpires: signed.expires, sshCertPrincipals: signed.principals }, p);
|
|
1491
|
+
else await forgetCertOf(p);
|
|
1492
|
+
if (opts.owner !== void 0 && !signed.principals.includes(opts.owner)) {
|
|
1493
|
+
const slug = opts.owner.split("@")[0];
|
|
1494
|
+
const sameSlugElsewhere = signed.principals.find((pr) => pr.split("@")[0] === slug && pr !== opts.owner);
|
|
1495
|
+
const why = sameSlugElsewhere ? `the control plane signs for ${sameSlugElsewhere} but the box's host qualifies its owner as ${opts.owner}: the control plane's name (KVBOX_CLOUD_NAME) changed after the host joined` : `you are not a member of ${slug} (a platform admin reaches org boxes over the API, not over SSH)`;
|
|
1496
|
+
throw new KvboxError(`your SSH certificate does not name ${opts.owner}: ${why}`);
|
|
1497
|
+
}
|
|
1498
|
+
return "renewed";
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// src/client.ts
|
|
1502
|
+
import { spawn } from "child_process";
|
|
1503
|
+
import { openSync } from "fs";
|
|
1504
|
+
import { mkdir as mkdir3, readFile as readFile3, stat } from "fs/promises";
|
|
1505
|
+
import { setTimeout as sleep } from "timers/promises";
|
|
1506
|
+
import { Agent, request } from "undici";
|
|
1507
|
+
import { z as z7 } from "zod";
|
|
1380
1508
|
|
|
1381
1509
|
// ../shared/src/managed.ts
|
|
1382
1510
|
import { z as z4 } from "zod";
|
|
@@ -1715,7 +1843,7 @@ function groupWithMember(gid, user, groupFile) {
|
|
|
1715
1843
|
}
|
|
1716
1844
|
|
|
1717
1845
|
// ../shared/src/systemd.ts
|
|
1718
|
-
import { spawnSync } from "child_process";
|
|
1846
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
1719
1847
|
import { readFileSync as readFileSync2 } from "fs";
|
|
1720
1848
|
import { resolve } from "path";
|
|
1721
1849
|
var UNIT = "kvbox-server";
|
|
@@ -1731,11 +1859,11 @@ function hasUnitFor(p, file = UNIT_FILE) {
|
|
|
1731
1859
|
return home !== void 0 && resolve(home) === resolve(p.home);
|
|
1732
1860
|
}
|
|
1733
1861
|
function startUnitProcess() {
|
|
1734
|
-
const res =
|
|
1862
|
+
const res = spawnSync2("sudo", ["-n", "systemctl", "start", UNIT], { encoding: "utf8" });
|
|
1735
1863
|
return { ok: res.status === 0, out: `${res.stdout ?? ""}${res.stderr ?? ""}`.trim() };
|
|
1736
1864
|
}
|
|
1737
1865
|
function unitActive() {
|
|
1738
|
-
const res =
|
|
1866
|
+
const res = spawnSync2("systemctl", ["is-active", UNIT], { encoding: "utf8" });
|
|
1739
1867
|
return (res.stdout ?? "").trim() === "active";
|
|
1740
1868
|
}
|
|
1741
1869
|
|
|
@@ -1748,13 +1876,17 @@ function orgOption(opts) {
|
|
|
1748
1876
|
}
|
|
1749
1877
|
async function resolveTarget(opts, p = paths()) {
|
|
1750
1878
|
if (!opts.local) {
|
|
1751
|
-
const
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1879
|
+
const org = orgOption(opts);
|
|
1880
|
+
const fromEnv = envLogin();
|
|
1881
|
+
if (fromEnv) {
|
|
1882
|
+
const asking = new ServerClient({ kind: "cloud", ...fromEnv, env: true }, { autoStart: false });
|
|
1883
|
+
const user = await asking.me().finally(() => asking.close());
|
|
1884
|
+
return { kind: "cloud", ...fromEnv, env: true, user: user.username, ...org === void 0 ? {} : { org } };
|
|
1755
1885
|
}
|
|
1886
|
+
const session = await readSession(p);
|
|
1887
|
+
if (session) return { kind: "cloud", url: session.url, token: session.token, user: session.user, ...org === void 0 ? {} : { org } };
|
|
1756
1888
|
}
|
|
1757
|
-
return { kind: "local", socketPath: p.serverSock };
|
|
1889
|
+
return { kind: "local", socketPath: p.serverSock, ...opts.local ? {} : { noLogin: true } };
|
|
1758
1890
|
}
|
|
1759
1891
|
var allQuery = (opts) => opts.all ? "?all=1" : "";
|
|
1760
1892
|
var ServerClient = class {
|
|
@@ -1793,25 +1925,30 @@ var ServerClient = class {
|
|
|
1793
1925
|
if (this.target.kind === "local") {
|
|
1794
1926
|
if (this.autoStart && !this.startedOnce) {
|
|
1795
1927
|
this.startedOnce = true;
|
|
1796
|
-
|
|
1928
|
+
const { noLogin } = this.target;
|
|
1929
|
+
await spin("starting kvbox-server\u2026", startLocalServer(paths(), 5e3)).catch((err2) => {
|
|
1930
|
+
throw noLogin && err2 instanceof KvboxError && err2.message === NOT_A_HOST_HINT ? new KvboxError(NOT_LOGGED_IN) : err2;
|
|
1931
|
+
});
|
|
1797
1932
|
return this.call(method, path, schema, body, org, timeoutMs);
|
|
1798
1933
|
}
|
|
1799
1934
|
throw new KvboxError(`kvbox-server is not running (${String(code)}); start it with: kvbox-server start -d`);
|
|
1800
1935
|
}
|
|
1801
|
-
throw new
|
|
1936
|
+
throw new CallError(cloudDown(this.target.url, String(code)), 0);
|
|
1802
1937
|
}
|
|
1803
1938
|
const text2 = await res.body.text();
|
|
1804
1939
|
const where = this.target.kind === "cloud" ? hostOf(this.target.url) : "kvbox-server";
|
|
1805
1940
|
if (res.statusCode >= 300) {
|
|
1806
1941
|
const parsed = ApiErrorSchema.safeParse(safeJson(text2) ?? {});
|
|
1807
|
-
if (!parsed.success) throw new
|
|
1942
|
+
if (!parsed.success) throw new CallError(`${where} answered ${res.statusCode}`, res.statusCode);
|
|
1808
1943
|
if (this.target.kind === "cloud" && this.target.token !== "") {
|
|
1809
|
-
if (res.statusCode === 401)
|
|
1944
|
+
if (res.statusCode === 401) {
|
|
1945
|
+
throw new KvboxError(this.target.env ? `${where} refused the API key in KVBOX_TOKEN: it was removed or has expired` : "session expired: kvbox login");
|
|
1946
|
+
}
|
|
1810
1947
|
if (res.statusCode === 404 && this.target.org !== void 0 && parsed.data.error === `org ${this.target.org}: not found`) {
|
|
1811
1948
|
throw new KvboxError(`${parsed.data.error} (you are not in it, or it is gone)`);
|
|
1812
1949
|
}
|
|
1813
1950
|
}
|
|
1814
|
-
throw new
|
|
1951
|
+
throw new CallError(parsed.data.error, res.statusCode, res.statusCode === 501 ? 2 : 1);
|
|
1815
1952
|
}
|
|
1816
1953
|
if (text2 === "") return schema.parse(void 0);
|
|
1817
1954
|
const json2 = safeJson(text2);
|
|
@@ -2152,12 +2289,29 @@ var ServerClient = class {
|
|
|
2152
2289
|
login(req) {
|
|
2153
2290
|
return this.call("POST", "/login", LoginResponseSchema, req);
|
|
2154
2291
|
}
|
|
2292
|
+
/** Device login (#189): open one, then poll with the answer's `deviceCode` until it is approved, refused or expired. */
|
|
2293
|
+
startDeviceLogin(req) {
|
|
2294
|
+
return this.call("POST", "/login/device", DeviceLoginStartSchema, req);
|
|
2295
|
+
}
|
|
2296
|
+
pollDeviceLogin(deviceCode) {
|
|
2297
|
+
return this.call("POST", "/login/device/token", DeviceLoginPollSchema, { deviceCode });
|
|
2298
|
+
}
|
|
2155
2299
|
logout() {
|
|
2156
2300
|
return this.call("POST", "/logout", z7.unknown()).then(() => void 0);
|
|
2157
2301
|
}
|
|
2158
2302
|
me() {
|
|
2159
2303
|
return this.call("GET", "/me", MeResponseSchema);
|
|
2160
2304
|
}
|
|
2305
|
+
// ---- API keys (`kvbox key …`, #189) ----
|
|
2306
|
+
listApiKeys() {
|
|
2307
|
+
return this.call("GET", "/keys", z7.array(ApiKeySchema));
|
|
2308
|
+
}
|
|
2309
|
+
createApiKey(req) {
|
|
2310
|
+
return this.call("POST", "/keys", CreatedApiKeySchema, req);
|
|
2311
|
+
}
|
|
2312
|
+
deleteApiKey(name) {
|
|
2313
|
+
return this.call("DELETE", `/keys/${encodeURIComponent(name)}`, z7.unknown()).then(() => void 0);
|
|
2314
|
+
}
|
|
2161
2315
|
// ---- orgs (`kvbox org …`) ----
|
|
2162
2316
|
listOrgs() {
|
|
2163
2317
|
return this.call("GET", "/orgs", z7.array(OrgMembershipSchema));
|
|
@@ -2199,6 +2353,14 @@ var ServerClient = class {
|
|
|
2199
2353
|
await this.dispatcher.close();
|
|
2200
2354
|
}
|
|
2201
2355
|
};
|
|
2356
|
+
var CallError = class extends KvboxError {
|
|
2357
|
+
constructor(message, status2, exitCode = 1) {
|
|
2358
|
+
super(message, exitCode);
|
|
2359
|
+
this.status = status2;
|
|
2360
|
+
}
|
|
2361
|
+
status;
|
|
2362
|
+
};
|
|
2363
|
+
var isUnreachable = (err) => err instanceof CallError && [0, 502, 503, 504].includes(err.status);
|
|
2202
2364
|
function cloudDown(url, code) {
|
|
2203
2365
|
const host = hostOf(url);
|
|
2204
2366
|
const hint = host.endsWith("kvbox.sh") ? "check status.kvbox.sh" : "use --local for this machine, or kvbox logout";
|
|
@@ -2284,10 +2446,11 @@ async function checkDirect(ep) {
|
|
|
2284
2446
|
throw new KvboxError(`--direct: cannot reach ${ep.host}:${ep.port}; it works only on the box's host (leave it out to go through the public address)`);
|
|
2285
2447
|
});
|
|
2286
2448
|
}
|
|
2449
|
+
var NOT_LOGGED_IN = "you are not logged in. Run: kvbox login";
|
|
2287
2450
|
var NOT_A_HOST_HINT = "kvbox-server is not installed, so this machine is not a kvbox host. Set it up with install-server.sh, or log in to the cloud with: kvbox login";
|
|
2288
2451
|
async function lastErrorLine(logPath, from = 0) {
|
|
2289
|
-
const { readFile:
|
|
2290
|
-
const text2 = (await
|
|
2452
|
+
const { readFile: readFile8 } = await import("fs/promises");
|
|
2453
|
+
const text2 = (await readFile8(logPath).catch(() => Buffer.alloc(0))).subarray(from).toString("utf8");
|
|
2291
2454
|
for (const line of text2.trimEnd().split("\n").slice(-20).reverse()) {
|
|
2292
2455
|
const m = /^(?:\[[^\]]*\])?\[?error\]?: (.*)$/.exec(line);
|
|
2293
2456
|
if (m?.[1] !== void 0) return m[1];
|
|
@@ -2295,7 +2458,7 @@ async function lastErrorLine(logPath, from = 0) {
|
|
|
2295
2458
|
return void 0;
|
|
2296
2459
|
}
|
|
2297
2460
|
async function startLocalServer(p = paths(), timeoutMs = 5e3) {
|
|
2298
|
-
await
|
|
2461
|
+
await mkdir3(p.home, { recursive: true });
|
|
2299
2462
|
if (hasUnitFor(p)) return startUnit(p, timeoutMs);
|
|
2300
2463
|
const log = openSync(p.serverLog, "a");
|
|
2301
2464
|
const launcher = serverLauncher();
|
|
@@ -2741,14 +2904,14 @@ var connectCommand = new Command2("connect").alias("cn").description("open a she
|
|
|
2741
2904
|
} finally {
|
|
2742
2905
|
await client.close();
|
|
2743
2906
|
}
|
|
2744
|
-
let res =
|
|
2907
|
+
let res = spawnSync3("ssh", [...sshArgs(ep), ...cmdArgs], { stdio: "inherit" });
|
|
2745
2908
|
if (res.error) throw new KvboxError(`could not run ssh: ${res.error.message}`);
|
|
2746
2909
|
if (res.status === SSH_FAILED) {
|
|
2747
2910
|
const again = await clientFor(cmd.optsWithGlobals());
|
|
2748
2911
|
const retry = await renewAfterRefusal(again, cert, owner).finally(() => again.close());
|
|
2749
2912
|
if (retry) {
|
|
2750
2913
|
info("renewed your SSH certificate, trying again\u2026");
|
|
2751
|
-
res =
|
|
2914
|
+
res = spawnSync3("ssh", [...sshArgs(ep), ...cmdArgs], { stdio: "inherit" });
|
|
2752
2915
|
if (res.error) throw new KvboxError(`could not run ssh: ${res.error.message}`);
|
|
2753
2916
|
}
|
|
2754
2917
|
}
|
|
@@ -3048,8 +3211,8 @@ var linkCommand = new Command8("link").description("let one box reach a port of
|
|
|
3048
3211
|
return;
|
|
3049
3212
|
}
|
|
3050
3213
|
const fromName = from.slice(from.lastIndexOf("/") + 1);
|
|
3051
|
-
const
|
|
3052
|
-
const apart =
|
|
3214
|
+
const link2 = box.links?.find((l) => l.port === port && l.from.slice(l.from.lastIndexOf("/") + 1) === fromName);
|
|
3215
|
+
const apart = link2 !== void 0 ? link2.from.includes("/") : from.includes("/") && from.split("/")[0] !== slugOf(box.owner);
|
|
3053
3216
|
const host = apart ? `${box.name}.${slugOf(box.owner)}.kvbox` : `${box.name}.kvbox`;
|
|
3054
3217
|
info(`${color.green("\u2713")} box ${color.bold(from)} can reach ${color.bold(`${host}:${port}`)}`);
|
|
3055
3218
|
if (box.status !== "running") info(` box ${shown} is ${box.status}: the link opens when it runs`);
|
|
@@ -4007,17 +4170,53 @@ for (const cmd of vmCommand.commands) if (cmd !== proxyCommand && cmd !== hookCo
|
|
|
4007
4170
|
var vmAliases = [newCommand, lsCommand, getCommand, connectCommand, execCommand, stopCommand, startCommand, pauseCommand, resumeCommand, hibernateCommand, wakeCommand, rmCommand3, claimCommand];
|
|
4008
4171
|
|
|
4009
4172
|
// src/commands/login.ts
|
|
4010
|
-
import {
|
|
4011
|
-
import { mkdir as mkdir3, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
|
|
4012
|
-
import { hostname as osHostname } from "os";
|
|
4173
|
+
import { hostname as osHostname2 } from "os";
|
|
4013
4174
|
import { createInterface as createInterface2 } from "readline/promises";
|
|
4175
|
+
import { setTimeout as sleep3 } from "timers/promises";
|
|
4014
4176
|
import { Writable } from "stream";
|
|
4015
4177
|
import { Command as Command38 } from "commander";
|
|
4016
|
-
|
|
4178
|
+
|
|
4179
|
+
// src/browser.ts
|
|
4180
|
+
import { spawn as spawn4 } from "child_process";
|
|
4181
|
+
function isWebLink(url) {
|
|
4182
|
+
if (/[^\x21-\x7e]/.test(url)) return false;
|
|
4183
|
+
let parsed;
|
|
4184
|
+
try {
|
|
4185
|
+
parsed = new URL(url);
|
|
4186
|
+
} catch {
|
|
4187
|
+
return false;
|
|
4188
|
+
}
|
|
4189
|
+
if (parsed.protocol === "https:") return parsed.hostname !== "";
|
|
4190
|
+
const host = parsed.hostname;
|
|
4191
|
+
return parsed.protocol === "http:" && (host === "localhost" || host.startsWith("127.") || host === "[::1]");
|
|
4192
|
+
}
|
|
4193
|
+
function browserCommand(url, platform = process.platform, env = process.env, isTTY = process.stderr.isTTY === true) {
|
|
4194
|
+
if (!isWebLink(url)) return null;
|
|
4195
|
+
if (!isTTY || env["SSH_CONNECTION"] || env["SSH_TTY"] || env["CI"]) return null;
|
|
4196
|
+
if (platform === "darwin") return ["open", url];
|
|
4197
|
+
if (platform === "win32") return ["rundll32", "url.dll,FileProtocolHandler", url];
|
|
4198
|
+
if (!env["DISPLAY"] && !env["WAYLAND_DISPLAY"]) return null;
|
|
4199
|
+
return ["xdg-open", url];
|
|
4200
|
+
}
|
|
4201
|
+
function openBrowser(url) {
|
|
4202
|
+
const argv = browserCommand(url);
|
|
4203
|
+
if (argv === null) return;
|
|
4204
|
+
try {
|
|
4205
|
+
const child = spawn4(argv[0], argv.slice(1), { stdio: "ignore", detached: true });
|
|
4206
|
+
child.on("error", () => {
|
|
4207
|
+
});
|
|
4208
|
+
child.unref();
|
|
4209
|
+
} catch {
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
|
|
4213
|
+
// src/commands/login.ts
|
|
4214
|
+
var loginCommand = new Command38("login").description("log in to the kvbox cloud (or your own control plane) and target it from now on").argument("[url]", `control plane URL (default: ${DEFAULT_CLOUD_URL})`).option("--password", "log in with email and password instead of approving a code in the web app").option("-e, --email <email>", "account email, for a password login (prompted otherwise)").option("--password-stdin", "read the password from the first line of stdin (for scripts)").action(async (urlArg, opts) => {
|
|
4017
4215
|
const url = normalizeUrl(urlArg ?? DEFAULT_CLOUD_URL);
|
|
4018
|
-
const
|
|
4019
|
-
const session = await runLogin(url,
|
|
4216
|
+
const byPassword = opts.password === true || opts.passwordStdin === true || opts.email !== void 0;
|
|
4217
|
+
const session = byPassword ? await runLogin(url, await readCredentials(opts), paths()) : await runDeviceLogin(url, paths());
|
|
4020
4218
|
info(`logged in to ${hostOf(url)} as ${session.user}`);
|
|
4219
|
+
if (envLogin()) info("KVBOX_TOKEN is set: commands keep using that API key until it is unset");
|
|
4021
4220
|
});
|
|
4022
4221
|
async function readCredentials(opts, io = { stdin: process.stdin, isTTY: process.stdin.isTTY === true }) {
|
|
4023
4222
|
const noTerminal = () => new KvboxError("stdin is not a terminal: pass --email and --password-stdin");
|
|
@@ -4034,7 +4233,7 @@ async function readCredentials(opts, io = { stdin: process.stdin, isTTY: process
|
|
|
4034
4233
|
if (password === "") throw new KvboxError("password is empty");
|
|
4035
4234
|
return { email, password };
|
|
4036
4235
|
}
|
|
4037
|
-
async function runLogin(url, creds, p = paths(), hostname =
|
|
4236
|
+
async function runLogin(url, creds, p = paths(), hostname = osHostname2()) {
|
|
4038
4237
|
const publicKey = await ensureSshKey(p, hostname);
|
|
4039
4238
|
const client = new ServerClient({ kind: "cloud", url, token: "" }, { autoStart: false });
|
|
4040
4239
|
let res;
|
|
@@ -4043,6 +4242,9 @@ async function runLogin(url, creds, p = paths(), hostname = osHostname()) {
|
|
|
4043
4242
|
} finally {
|
|
4044
4243
|
await client.close();
|
|
4045
4244
|
}
|
|
4245
|
+
return storeLogin(url, res, p);
|
|
4246
|
+
}
|
|
4247
|
+
async function storeLogin(url, res, p) {
|
|
4046
4248
|
const session = { url, token: res.token, user: res.user.username };
|
|
4047
4249
|
if (res.sshCert !== void 0 && res.sshCertExpires !== void 0) {
|
|
4048
4250
|
await writeCert(res.sshCert, p);
|
|
@@ -4052,21 +4254,47 @@ async function runLogin(url, creds, p = paths(), hostname = osHostname()) {
|
|
|
4052
4254
|
await writeSession(session, p);
|
|
4053
4255
|
return session;
|
|
4054
4256
|
}
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
const
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4257
|
+
var terminalIo = { say: info, sleep: sleep3, open: openBrowser, wait: (message, work) => spin(message, work) };
|
|
4258
|
+
async function runDeviceLogin(url, p = paths(), hostname = osHostname2(), io = terminalIo) {
|
|
4259
|
+
const publicKey = await ensureSshKey(p, hostname);
|
|
4260
|
+
const client = new ServerClient({ kind: "cloud", url, token: "" }, { autoStart: false });
|
|
4261
|
+
try {
|
|
4262
|
+
let start;
|
|
4263
|
+
try {
|
|
4264
|
+
start = await client.startDeviceLogin({ publicKey, hostname });
|
|
4265
|
+
} catch (err) {
|
|
4266
|
+
if (err instanceof KvboxError && err.message.startsWith("no route")) throw new KvboxError(`${hostOf(url)} has no login by code yet: use kvbox login --password`);
|
|
4267
|
+
throw err;
|
|
4268
|
+
}
|
|
4269
|
+
if (!isWebLink(start.verifyUrl)) throw new KvboxError(`${hostOf(url)} answered a link to approve the login that is not https; nothing was opened`);
|
|
4270
|
+
const minutes = Math.round(start.expiresIn / 60);
|
|
4271
|
+
io.say(`To log in, open this link and approve the code ${start.userCode} (good for ${minutes} min):`);
|
|
4272
|
+
io.say(` ${start.verifyUrl}`);
|
|
4273
|
+
io.open(start.verifyUrl);
|
|
4274
|
+
const { deviceCode } = start;
|
|
4275
|
+
let interval = start.interval;
|
|
4276
|
+
let waited = 0;
|
|
4277
|
+
const res = await io.wait("waiting for you to approve it in the browser\u2026", async () => {
|
|
4278
|
+
for (; ; ) {
|
|
4279
|
+
await io.sleep(interval * 1e3);
|
|
4280
|
+
waited += interval;
|
|
4281
|
+
let poll;
|
|
4282
|
+
try {
|
|
4283
|
+
poll = await client.pollDeviceLogin(deviceCode);
|
|
4284
|
+
} catch (err) {
|
|
4285
|
+
if (isUnreachable(err) && waited < start.expiresIn + DEVICE_LOGIN_PICKUP_SEC) continue;
|
|
4286
|
+
throw err;
|
|
4287
|
+
}
|
|
4288
|
+
if (poll.status === "approved") return poll;
|
|
4289
|
+
if (poll.status === "refused") throw new KvboxError("the login was refused in the web app; nothing was stored");
|
|
4290
|
+
if (poll.status === "expired") throw new KvboxError("nobody approved the code in time: run kvbox login again");
|
|
4291
|
+
if (poll.status === "slow_down") interval += 5;
|
|
4292
|
+
}
|
|
4293
|
+
});
|
|
4294
|
+
return await storeLogin(url, res, p);
|
|
4295
|
+
} finally {
|
|
4296
|
+
await client.close();
|
|
4066
4297
|
}
|
|
4067
|
-
if (res.status !== 0) throw new KvboxError(`ssh-keygen failed: ${res.stderr.trim()}`);
|
|
4068
|
-
if (havePrivate) await writeFile3(pubPath, res.stdout.trim() + "\n");
|
|
4069
|
-
return (await readFile4(pubPath, "utf8")).trim();
|
|
4070
4298
|
}
|
|
4071
4299
|
async function prompt(question, io) {
|
|
4072
4300
|
const rl = createInterface2({ input: io.input, output: io.output });
|
|
@@ -4107,6 +4335,7 @@ var logoutCommand = new Command39("logout").description("log out of the control
|
|
|
4107
4335
|
case "cleared":
|
|
4108
4336
|
info(`logged out of ${hostOf(session?.url ?? "")}`);
|
|
4109
4337
|
}
|
|
4338
|
+
if (envLogin()) info("KVBOX_TOKEN is still set: commands keep using that API key. Unset it, or remove the key with: kvbox key rm <name>");
|
|
4110
4339
|
});
|
|
4111
4340
|
async function runLogout(p = paths()) {
|
|
4112
4341
|
let session;
|
|
@@ -4132,10 +4361,19 @@ async function runLogout(p = paths()) {
|
|
|
4132
4361
|
|
|
4133
4362
|
// src/commands/whoami.ts
|
|
4134
4363
|
import { Command as Command40 } from "commander";
|
|
4135
|
-
var whoamiCommand = new Command40("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts) => {
|
|
4364
|
+
var whoamiCommand = new Command40("whoami").description("show which account and control plane commands target (or local mode)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4365
|
+
if (!cmd.optsWithGlobals().local && envLogin()) {
|
|
4366
|
+
const target = await resolveTarget({});
|
|
4367
|
+
if (target.kind !== "cloud") return;
|
|
4368
|
+
if (opts.json) json({ user: target.user ?? null, url: target.url, sshCertExpires: null, apiKey: true });
|
|
4369
|
+
else process.stdout.write(`${target.user} on ${hostOf(target.url)}
|
|
4370
|
+
using the API key in KVBOX_TOKEN
|
|
4371
|
+
`);
|
|
4372
|
+
return;
|
|
4373
|
+
}
|
|
4136
4374
|
const session = await readSession();
|
|
4137
4375
|
if (opts.json) {
|
|
4138
|
-
json(session ? { user: session.user, url: session.url, sshCertExpires: session.sshCertExpires ?? null } : null);
|
|
4376
|
+
json(session ? { user: session.user, url: session.url, sshCertExpires: session.sshCertExpires ?? null, apiKey: false } : null);
|
|
4139
4377
|
return;
|
|
4140
4378
|
}
|
|
4141
4379
|
process.stdout.write(describeSession(session) + "\n");
|
|
@@ -4147,12 +4385,110 @@ function describeSession(session) {
|
|
|
4147
4385
|
return lines.join("\n");
|
|
4148
4386
|
}
|
|
4149
4387
|
|
|
4150
|
-
// src/commands/
|
|
4388
|
+
// src/commands/key/index.ts
|
|
4151
4389
|
import { Command as Command44 } from "commander";
|
|
4152
4390
|
|
|
4153
|
-
// src/commands/
|
|
4391
|
+
// src/commands/key/create.ts
|
|
4154
4392
|
import { Command as Command41 } from "commander";
|
|
4155
|
-
|
|
4393
|
+
|
|
4394
|
+
// src/commands/key/shared.ts
|
|
4395
|
+
async function keyClient(cmd) {
|
|
4396
|
+
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4397
|
+
if (client.target.kind !== "cloud") {
|
|
4398
|
+
await client.close();
|
|
4399
|
+
throw new KvboxError("API keys belong to an account on the kvbox cloud: kvbox login first");
|
|
4400
|
+
}
|
|
4401
|
+
if (client.target.env) {
|
|
4402
|
+
await client.close();
|
|
4403
|
+
throw new KvboxError("KVBOX_TOKEN is set, and an API key cannot manage keys: unset it and use your login (kvbox login)");
|
|
4404
|
+
}
|
|
4405
|
+
return client;
|
|
4406
|
+
}
|
|
4407
|
+
function parseExpires(text2, now = Date.now()) {
|
|
4408
|
+
if (text2.trim().toLowerCase() === "never") return null;
|
|
4409
|
+
const sec = parseDuration(text2);
|
|
4410
|
+
if (sec !== void 0 && sec > 0) {
|
|
4411
|
+
const at = new Date(now + sec * 1e3);
|
|
4412
|
+
if (Number.isNaN(at.getTime()) || at.getUTCFullYear() > 9999) throw new KvboxError(`--expires ${text2} is too far ahead: use never for a key without an end`);
|
|
4413
|
+
return at;
|
|
4414
|
+
}
|
|
4415
|
+
const day3 = /^\d{4}-\d{2}-\d{2}$/.test(text2.trim()) ? /* @__PURE__ */ new Date(`${text2.trim()}T23:59:59.999Z`) : null;
|
|
4416
|
+
if (day3 === null || Number.isNaN(day3.getTime()) || day3.toISOString().slice(0, 10) !== text2.trim()) throw new KvboxError(`--expires takes a duration like 90d, a day like 2027-01-31, or never, not: ${text2}`);
|
|
4417
|
+
if (day3.getTime() <= now) throw new KvboxError(`--expires ${text2} is in the past`);
|
|
4418
|
+
return day3;
|
|
4419
|
+
}
|
|
4420
|
+
function expiryText(expiresAt, now = Date.now()) {
|
|
4421
|
+
if (expiresAt === null) return "never";
|
|
4422
|
+
const left = Date.parse(expiresAt) - now;
|
|
4423
|
+
if (left <= 0) return "expired";
|
|
4424
|
+
const days = Math.floor(left / 864e5);
|
|
4425
|
+
return days === 0 ? "today" : `in ${days} day${days === 1 ? "" : "s"}`;
|
|
4426
|
+
}
|
|
4427
|
+
|
|
4428
|
+
// src/commands/key/create.ts
|
|
4429
|
+
var createCommand3 = new Command41("create").description("make an API key for a program: CI, an agent, the SDK (the key is shown once)").argument("<name>", "what to call the key: lowercase letters, digits, '.', '_' or '-'").option("--expires <when>", `when it stops working: a duration (30d, 12h; m is minutes), a day (2027-01-31), or never; ${DEFAULT_API_KEY_DAYS}d by default`).option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
4430
|
+
const expiresAt = opts.expires === void 0 ? void 0 : parseExpires(opts.expires);
|
|
4431
|
+
const client = await keyClient(cmd);
|
|
4432
|
+
try {
|
|
4433
|
+
const made = await client.createApiKey({ name, ...expiresAt === void 0 ? {} : { expiresAt: expiresAt?.toISOString() ?? null } });
|
|
4434
|
+
if (opts.json) {
|
|
4435
|
+
json(made);
|
|
4436
|
+
return;
|
|
4437
|
+
}
|
|
4438
|
+
info(`${color.green("\u2713")} API key ${color.bold(made.name)} made; it ${made.expiresAt === null ? "never expires" : `expires ${expiryText(made.expiresAt)}`}`);
|
|
4439
|
+
process.stdout.write(made.key + "\n");
|
|
4440
|
+
info(color.dim("\nThe key is shown only now. A program uses it as KVBOX_TOKEN; it can do everything you can, except manage keys."));
|
|
4441
|
+
} finally {
|
|
4442
|
+
await client.close();
|
|
4443
|
+
}
|
|
4444
|
+
});
|
|
4445
|
+
|
|
4446
|
+
// src/commands/key/ls.ts
|
|
4447
|
+
import { Command as Command42 } from "commander";
|
|
4448
|
+
var lsCommand5 = new Command42("ls").alias("list").description("list your API keys (never the keys themselves)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4449
|
+
const client = await keyClient(cmd);
|
|
4450
|
+
try {
|
|
4451
|
+
const keys = await client.listApiKeys();
|
|
4452
|
+
if (opts.json) {
|
|
4453
|
+
json(keys);
|
|
4454
|
+
return;
|
|
4455
|
+
}
|
|
4456
|
+
if (keys.length === 0) {
|
|
4457
|
+
info("no API keys yet; make one with: kvbox key create <name>");
|
|
4458
|
+
return;
|
|
4459
|
+
}
|
|
4460
|
+
table(keys.map((k) => ({ name: k.name, created: age(k.createdAt), "last used": k.lastUsedAt === null ? "never" : age(k.lastUsedAt), expires: expiryText(k.expiresAt) })));
|
|
4461
|
+
} finally {
|
|
4462
|
+
await client.close();
|
|
4463
|
+
}
|
|
4464
|
+
});
|
|
4465
|
+
|
|
4466
|
+
// src/commands/key/rm.ts
|
|
4467
|
+
import { Command as Command43 } from "commander";
|
|
4468
|
+
var rmCommand4 = new Command43("rm").alias("remove").description("remove an API key: whatever uses it stops working").argument("<name>", "the key's name (kvbox key ls)").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
4469
|
+
const client = await keyClient(cmd);
|
|
4470
|
+
try {
|
|
4471
|
+
if (!await confirm(`Remove API key ${name}? Whatever uses it stops working.`, opts.yes ?? false)) {
|
|
4472
|
+
info("cancelled");
|
|
4473
|
+
process.exitCode = 1;
|
|
4474
|
+
return;
|
|
4475
|
+
}
|
|
4476
|
+
await client.deleteApiKey(name);
|
|
4477
|
+
info(`${color.green("\u2713")} API key ${name} removed`);
|
|
4478
|
+
} finally {
|
|
4479
|
+
await client.close();
|
|
4480
|
+
}
|
|
4481
|
+
});
|
|
4482
|
+
|
|
4483
|
+
// src/commands/key/index.ts
|
|
4484
|
+
var keyCommand = new Command44("key").aliases(["keys"]).description("API keys: named tokens a program (CI, an agent, the SDK) uses as KVBOX_TOKEN in place of a login").addCommand(createCommand3).addCommand(lsCommand5).addCommand(rmCommand4);
|
|
4485
|
+
|
|
4486
|
+
// src/commands/snapshots/index.ts
|
|
4487
|
+
import { Command as Command48 } from "commander";
|
|
4488
|
+
|
|
4489
|
+
// src/commands/snapshots/ls.ts
|
|
4490
|
+
import { Command as Command45 } from "commander";
|
|
4491
|
+
var lsCommand6 = new Command45("ls").description("list snapshots (yours and your orgs'; --org <slug> for one org)").option("-a, --all", "every snapshot on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4156
4492
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4157
4493
|
try {
|
|
4158
4494
|
const cloud = client.target.kind === "cloud";
|
|
@@ -4183,8 +4519,8 @@ var lsCommand5 = new Command41("ls").description("list snapshots (yours and your
|
|
|
4183
4519
|
});
|
|
4184
4520
|
|
|
4185
4521
|
// src/commands/snapshots/new.ts
|
|
4186
|
-
import { Command as
|
|
4187
|
-
var newCommand2 = new
|
|
4522
|
+
import { Command as Command46 } from "commander";
|
|
4523
|
+
var newCommand2 = new Command46("new").description("freeze a running box (memory + disk) into a snapshot; the box keeps running").argument("<box>", "box name").argument("<name>", "snapshot name").option("--replace", "retake a snapshot that exists under this name; the old one stays until the new one is complete").option("--json", "print the snapshot as JSON").action(async (box, name, opts, cmd) => {
|
|
4188
4524
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
4189
4525
|
try {
|
|
4190
4526
|
const req = { box, name, ...opts.replace ? { replace: true } : {} };
|
|
@@ -4197,8 +4533,8 @@ var newCommand2 = new Command42("new").description("freeze a running box (memory
|
|
|
4197
4533
|
});
|
|
4198
4534
|
|
|
4199
4535
|
// src/commands/snapshots/rm.ts
|
|
4200
|
-
import { Command as
|
|
4201
|
-
var
|
|
4536
|
+
import { Command as Command47 } from "commander";
|
|
4537
|
+
var rmCommand5 = new Command47("rm").description("delete a snapshot (boxes made from it are not affected)").argument("<name>", "snapshot name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
4202
4538
|
if (!await confirm(`Delete snapshot ${name}?`, opts.yes ?? false)) {
|
|
4203
4539
|
info("cancelled");
|
|
4204
4540
|
process.exitCode = 1;
|
|
@@ -4214,34 +4550,34 @@ var rmCommand4 = new Command43("rm").description("delete a snapshot (boxes made
|
|
|
4214
4550
|
});
|
|
4215
4551
|
|
|
4216
4552
|
// src/commands/snapshots/index.ts
|
|
4217
|
-
var snapshotsCommand = new
|
|
4553
|
+
var snapshotsCommand = new Command48("snapshots").aliases(["snapshot", "snap"]).description("freeze running boxes into snapshots and manage them").addCommand(newCommand2).addCommand(lsCommand6).addCommand(rmCommand5);
|
|
4218
4554
|
for (const cmd of snapshotsCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
4219
4555
|
|
|
4220
4556
|
// src/commands/org/index.ts
|
|
4221
|
-
import { Command as
|
|
4557
|
+
import { Command as Command54 } from "commander";
|
|
4222
4558
|
|
|
4223
4559
|
// src/commands/org/ls.ts
|
|
4224
|
-
import { Command as
|
|
4560
|
+
import { Command as Command49 } from "commander";
|
|
4225
4561
|
|
|
4226
4562
|
// src/commands/org/context.ts
|
|
4227
|
-
var
|
|
4563
|
+
var NOT_LOGGED_IN2 = "orgs live on the control plane: kvbox login first";
|
|
4228
4564
|
async function cloudClientFor(opts) {
|
|
4229
4565
|
const client = await clientFor(opts, { autoStart: false });
|
|
4230
4566
|
if (client.target.kind === "local") {
|
|
4231
4567
|
await client.close();
|
|
4232
|
-
throw new KvboxError(
|
|
4568
|
+
throw new KvboxError(NOT_LOGGED_IN2);
|
|
4233
4569
|
}
|
|
4234
4570
|
return client;
|
|
4235
4571
|
}
|
|
4236
4572
|
function orgFor(opts, target) {
|
|
4237
|
-
if (target.kind === "local") throw new KvboxError(
|
|
4573
|
+
if (target.kind === "local") throw new KvboxError(NOT_LOGGED_IN2);
|
|
4238
4574
|
const slug = opts.org ?? target.org;
|
|
4239
4575
|
if (slug === void 0) throw new KvboxError("no org: pass --org <slug>");
|
|
4240
4576
|
return slug;
|
|
4241
4577
|
}
|
|
4242
4578
|
|
|
4243
4579
|
// src/commands/org/ls.ts
|
|
4244
|
-
var
|
|
4580
|
+
var lsCommand7 = new Command49("ls").description("list the orgs you belong to and your role in each").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4245
4581
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
4246
4582
|
try {
|
|
4247
4583
|
const orgs = await client.listOrgs();
|
|
@@ -4263,8 +4599,8 @@ function orgRows(orgs) {
|
|
|
4263
4599
|
}
|
|
4264
4600
|
|
|
4265
4601
|
// src/commands/org/members.ts
|
|
4266
|
-
import { Command as
|
|
4267
|
-
var
|
|
4602
|
+
import { Command as Command50, Option as Option4 } from "commander";
|
|
4603
|
+
var lsCommand8 = new Command50("ls").description("list an org's members and their roles").option("-o, --org <slug>", "the org (or --org before the command)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4268
4604
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
4269
4605
|
try {
|
|
4270
4606
|
const org = await client.getOrg(orgFor(opts, client.target));
|
|
@@ -4278,7 +4614,7 @@ var lsCommand7 = new Command46("ls").description("list an org's members and thei
|
|
|
4278
4614
|
await client.close();
|
|
4279
4615
|
}
|
|
4280
4616
|
});
|
|
4281
|
-
var addCommand2 = new
|
|
4617
|
+
var addCommand2 = new Command50("add").description("add a user to an org (admins and owners; only an owner can add an owner)").argument("<user>", "their username").addOption(new Option4("-r, --role <role>", "their role").choices(ORG_ROLES).default("member")).option("-o, --org <slug>", "the org (or --org before the command)").action(async (user, opts, cmd) => {
|
|
4282
4618
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
4283
4619
|
try {
|
|
4284
4620
|
const slug = orgFor(opts, client.target);
|
|
@@ -4288,7 +4624,7 @@ var addCommand2 = new Command46("add").description("add a user to an org (admins
|
|
|
4288
4624
|
await client.close();
|
|
4289
4625
|
}
|
|
4290
4626
|
});
|
|
4291
|
-
var
|
|
4627
|
+
var rmCommand6 = new Command50("rm").description("remove a member (or leave: remove yourself)").argument("<user>", "their username").option("-o, --org <slug>", "the org (or --org before the command)").option("-y, --yes", "do not ask for confirmation").action(async (user, opts, cmd) => {
|
|
4292
4628
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
4293
4629
|
try {
|
|
4294
4630
|
const slug = orgFor(opts, client.target);
|
|
@@ -4304,11 +4640,11 @@ var rmCommand5 = new Command46("rm").description("remove a member (or leave: rem
|
|
|
4304
4640
|
await client.close();
|
|
4305
4641
|
}
|
|
4306
4642
|
});
|
|
4307
|
-
var membersCommand = new
|
|
4643
|
+
var membersCommand = new Command50("members").description("who is in an org and what they may do").addCommand(lsCommand8).addCommand(addCommand2).addCommand(rmCommand6);
|
|
4308
4644
|
|
|
4309
4645
|
// src/commands/org/new.ts
|
|
4310
|
-
import { Command as
|
|
4311
|
-
var newCommand3 = new
|
|
4646
|
+
import { Command as Command51 } from "commander";
|
|
4647
|
+
var newCommand3 = new Command51("new").description("create an org; you become its owner (the slug is permanent, the name is not)").argument("<slug>", "the org's slug: lowercase, like a username (acme)").option("-n, --name <name>", "display name (default: the slug)").option("--json", "print the org as JSON").action(async (slug, opts, cmd) => {
|
|
4312
4648
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
4313
4649
|
try {
|
|
4314
4650
|
const org = await client.createOrg({ slug, name: opts.name ?? slug });
|
|
@@ -4324,8 +4660,8 @@ var newCommand3 = new Command47("new").description("create an org; you become it
|
|
|
4324
4660
|
});
|
|
4325
4661
|
|
|
4326
4662
|
// src/commands/org/rm.ts
|
|
4327
|
-
import { Command as
|
|
4328
|
-
var
|
|
4663
|
+
import { Command as Command52 } from "commander";
|
|
4664
|
+
var rmCommand7 = new Command52("rm").description("delete an org (owners only; remove its boxes and snapshots first)").argument("<slug>", "the org").option("-y, --yes", "do not ask for confirmation").action(async (slug, opts, cmd) => {
|
|
4329
4665
|
if (!await confirm(`Delete org ${slug}? Its members lose access; its slug stays taken.`, opts.yes ?? false)) {
|
|
4330
4666
|
info("cancelled");
|
|
4331
4667
|
process.exitCode = 1;
|
|
@@ -4341,8 +4677,8 @@ var rmCommand6 = new Command48("rm").description("delete an org (owners only; re
|
|
|
4341
4677
|
});
|
|
4342
4678
|
|
|
4343
4679
|
// src/commands/org/role.ts
|
|
4344
|
-
import { Argument, Command as
|
|
4345
|
-
var roleCommand = new
|
|
4680
|
+
import { Argument, Command as Command53 } from "commander";
|
|
4681
|
+
var roleCommand = new Command53("role").description("change a member's role (owners only)").argument("<user>", "their username").addArgument(new Argument("<role>", "owner, admin or member").choices(ORG_ROLES)).option("-o, --org <slug>", "the org (default: the current context)").action(async (user, role, opts, cmd) => {
|
|
4346
4682
|
const client = await cloudClientFor(cmd.optsWithGlobals());
|
|
4347
4683
|
try {
|
|
4348
4684
|
const slug = orgFor(opts, client.target);
|
|
@@ -4354,11 +4690,11 @@ var roleCommand = new Command49("role").description("change a member's role (own
|
|
|
4354
4690
|
});
|
|
4355
4691
|
|
|
4356
4692
|
// src/commands/org/index.ts
|
|
4357
|
-
var orgCommand = new
|
|
4693
|
+
var orgCommand = new Command54("org").description("orgs: shared slugs that own boxes, with owners, admins and members").addCommand(lsCommand7).addCommand(newCommand3).addCommand(membersCommand).addCommand(roleCommand).addCommand(rmCommand7);
|
|
4358
4694
|
|
|
4359
4695
|
// src/commands/usage.ts
|
|
4360
|
-
import { Command as
|
|
4361
|
-
var usageCommand2 = new
|
|
4696
|
+
import { Command as Command55 } from "commander";
|
|
4697
|
+
var usageCommand2 = new Command55("usage").description("what your boxes and volumes used this month (or --since/--until): running time, vCPU-h, RAM and disk GiB-h, cost").option("--since <date>", "count from this date, e.g. 2026-10-01 (default: the 1st of this month)").option("--until <date>", "count up to this date (default: now)").option("--org <slug>", "one org's boxes only").option("-a, --all", "every box on the platform (platform admins only)").option("--by-user", "one line per user who made the boxes (e.g. who spent what in --org)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4362
4698
|
for (const [name, value] of [
|
|
4363
4699
|
["since", opts.since],
|
|
4364
4700
|
["until", opts.until]
|
|
@@ -4540,8 +4876,8 @@ function userRows(r) {
|
|
|
4540
4876
|
}
|
|
4541
4877
|
|
|
4542
4878
|
// src/commands/credit.ts
|
|
4543
|
-
import { Command as
|
|
4544
|
-
var creditCommand = new
|
|
4879
|
+
import { Command as Command56 } from "commander";
|
|
4880
|
+
var creditCommand = new Command56("credit").description("the prepaid credit left on your account and on each of your orgs").option("--org <slug>", "one org only").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
4545
4881
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4546
4882
|
try {
|
|
4547
4883
|
if (client.target.kind === "local") throw new KvboxError("credit lives on the control plane: kvbox login first");
|
|
@@ -4570,8 +4906,8 @@ function creditRow(b, me2) {
|
|
|
4570
4906
|
}
|
|
4571
4907
|
|
|
4572
4908
|
// src/commands/redeem.ts
|
|
4573
|
-
import { Command as
|
|
4574
|
-
var redeemCommand = new
|
|
4909
|
+
import { Command as Command57 } from "commander";
|
|
4910
|
+
var redeemCommand = new Command57("redeem").description("redeem a promo code for credit, on your account or (--org) an org you own").argument("<code>", "the code, like KV-7F3K-9QXM-2HBD").option("--org <slug>", "give the credit to this org, which you own; it cannot be moved later").option("--json", "print as JSON").action(async (code, opts, cmd) => {
|
|
4575
4911
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
4576
4912
|
try {
|
|
4577
4913
|
if (client.target.kind === "local") throw new KvboxError("codes are redeemed on the control plane: kvbox login first");
|
|
@@ -4589,17 +4925,17 @@ var redeemCommand = new Command53("redeem").description("redeem a promo code for
|
|
|
4589
4925
|
});
|
|
4590
4926
|
|
|
4591
4927
|
// src/commands/deploy/index.ts
|
|
4592
|
-
import { access as access5, readFile as
|
|
4928
|
+
import { access as access5, readFile as readFile7 } from "fs/promises";
|
|
4593
4929
|
import { basename as basename2, resolve as resolve3 } from "path";
|
|
4594
|
-
import { Command as
|
|
4930
|
+
import { Command as Command58, InvalidArgumentError as InvalidArgumentError2, Option as Option5 } from "commander";
|
|
4595
4931
|
|
|
4596
4932
|
// src/commands/deploy/config.ts
|
|
4597
|
-
import { readFile as
|
|
4933
|
+
import { readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
|
|
4598
4934
|
import { isAbsolute, join as join6, normalize, relative as relative2 } from "path";
|
|
4599
4935
|
import { z as z8 } from "zod";
|
|
4600
4936
|
|
|
4601
4937
|
// src/commands/deploy/templates/docker.ts
|
|
4602
|
-
import { readFile as
|
|
4938
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
4603
4939
|
import { join as join2, relative, sep } from "path";
|
|
4604
4940
|
|
|
4605
4941
|
// src/commands/deploy/templates/server.ts
|
|
@@ -4725,7 +5061,7 @@ var dockerTemplate = {
|
|
|
4725
5061
|
},
|
|
4726
5062
|
/** No local build: the box does it. The Dockerfile is read for its EXPOSE port only. */
|
|
4727
5063
|
async build(ctx) {
|
|
4728
|
-
const dockerfile = await
|
|
5064
|
+
const dockerfile = await readFile4(join2(ctx.dir, "Dockerfile"), "utf8").catch(() => void 0);
|
|
4729
5065
|
if (dockerfile === void 0) throw new KvboxError(`${ctx.dir}: no Dockerfile; the Docker template builds the image from it`);
|
|
4730
5066
|
const containerPort = exposedPort(dockerfile);
|
|
4731
5067
|
if (ctx.context !== void 0 && ctx.context !== ctx.dir) {
|
|
@@ -4901,7 +5237,7 @@ var nodeTemplate = {
|
|
|
4901
5237
|
};
|
|
4902
5238
|
|
|
4903
5239
|
// src/commands/deploy/templates/react.ts
|
|
4904
|
-
import { spawn as
|
|
5240
|
+
import { spawn as spawn5 } from "child_process";
|
|
4905
5241
|
import { access as access2 } from "fs/promises";
|
|
4906
5242
|
import { join as join4 } from "path";
|
|
4907
5243
|
var OUT_DIRS = ["dist", "build"];
|
|
@@ -4909,7 +5245,7 @@ async function runBuild(dir, pm) {
|
|
|
4909
5245
|
const args = runScript(pm, "build");
|
|
4910
5246
|
info(`${color.dim("$")} ${pm} ${args.join(" ")}`);
|
|
4911
5247
|
const status2 = await new Promise((resolve4, reject) => {
|
|
4912
|
-
const child =
|
|
5248
|
+
const child = spawn5(pm, args, { cwd: dir, stdio: ["ignore", process.stderr, process.stderr], shell: process.platform === "win32" });
|
|
4913
5249
|
child.once("error", (err) => reject(new KvboxError(`could not run ${pm}: ${err.message}`)));
|
|
4914
5250
|
child.once("close", (code) => resolve4(code ?? 1));
|
|
4915
5251
|
});
|
|
@@ -5177,7 +5513,7 @@ async function readDeployFile(dir) {
|
|
|
5177
5513
|
const path = join6(dir, CONFIG_FILE);
|
|
5178
5514
|
let raw;
|
|
5179
5515
|
try {
|
|
5180
|
-
raw = await
|
|
5516
|
+
raw = await readFile5(path, "utf8");
|
|
5181
5517
|
} catch (err) {
|
|
5182
5518
|
if (err.code === "ENOENT") return void 0;
|
|
5183
5519
|
throw err;
|
|
@@ -5197,7 +5533,7 @@ async function readDeployFile(dir) {
|
|
|
5197
5533
|
return stack ? { kind: "stack", config: parsed.data } : { kind: "single", config: parsed.data };
|
|
5198
5534
|
}
|
|
5199
5535
|
async function writeConfig(dir, config) {
|
|
5200
|
-
await
|
|
5536
|
+
await writeFile3(join6(dir, CONFIG_FILE), JSON.stringify(config, null, 2) + "\n");
|
|
5201
5537
|
}
|
|
5202
5538
|
function nameFromDir(dirName) {
|
|
5203
5539
|
const slug = dirName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 12).replace(/-+$/, "");
|
|
@@ -5208,7 +5544,7 @@ function subdomainFor(name) {
|
|
|
5208
5544
|
}
|
|
5209
5545
|
|
|
5210
5546
|
// src/commands/deploy/ship.ts
|
|
5211
|
-
import { spawn as
|
|
5547
|
+
import { spawn as spawn6 } from "child_process";
|
|
5212
5548
|
import { readdir, stat as stat2 } from "fs/promises";
|
|
5213
5549
|
import { join as join7 } from "path";
|
|
5214
5550
|
var IMAGE_TOO_OLD = 3;
|
|
@@ -5230,8 +5566,8 @@ async function measure(dir, exclude = []) {
|
|
|
5230
5566
|
return total;
|
|
5231
5567
|
}
|
|
5232
5568
|
async function ship(ep, dir, remote, exclude = []) {
|
|
5233
|
-
const tar =
|
|
5234
|
-
const ssh =
|
|
5569
|
+
const tar = spawn6("tar", ["-cf", "-", ...exclude.map((e) => `--exclude=${e}`), "-C", dir, "."], { stdio: ["ignore", "pipe", "pipe"] });
|
|
5570
|
+
const ssh = spawn6("ssh", [...sshArgs(ep), remote], { stdio: ["pipe", "pipe", "pipe"] });
|
|
5235
5571
|
tar.stdout.pipe(ssh.stdin);
|
|
5236
5572
|
const chunks = [];
|
|
5237
5573
|
ssh.stdout.on("data", (c2) => chunks.push(c2));
|
|
@@ -5259,7 +5595,7 @@ async function ship(ep, dir, remote, exclude = []) {
|
|
|
5259
5595
|
return { status: status2, output: Buffer.concat(chunks).toString("utf8") };
|
|
5260
5596
|
}
|
|
5261
5597
|
async function run(ep, remote) {
|
|
5262
|
-
const ssh =
|
|
5598
|
+
const ssh = spawn6("ssh", [...sshArgs(ep), remote], { stdio: ["ignore", "pipe", "pipe"] });
|
|
5263
5599
|
const chunks = [];
|
|
5264
5600
|
ssh.stdout.on("data", (c2) => chunks.push(c2));
|
|
5265
5601
|
ssh.stderr.on("data", (c2) => chunks.push(c2));
|
|
@@ -5349,11 +5685,11 @@ the app is on box ${ref} but has no address yet: pick another with kvbox deploy
|
|
|
5349
5685
|
}
|
|
5350
5686
|
|
|
5351
5687
|
// src/commands/deploy/stack.ts
|
|
5352
|
-
import { access as access4, readFile as
|
|
5688
|
+
import { access as access4, readFile as readFile6 } from "fs/promises";
|
|
5353
5689
|
import { basename, join as join8, resolve as resolve2 } from "path";
|
|
5354
5690
|
|
|
5355
5691
|
// src/commands/deploy/postgres.ts
|
|
5356
|
-
import { randomBytes } from "crypto";
|
|
5692
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
5357
5693
|
var POSTGRES_USER = "kvbox";
|
|
5358
5694
|
var POSTGRES_DB = "app";
|
|
5359
5695
|
var ENV_MISSING = 6;
|
|
@@ -5366,7 +5702,7 @@ var DB_WAIT_SEC = 90;
|
|
|
5366
5702
|
var AGENT = "/usr/local/sbin/kvbox-agent";
|
|
5367
5703
|
var ENV_WAIT_SEC = 60;
|
|
5368
5704
|
function newPassword() {
|
|
5369
|
-
return
|
|
5705
|
+
return randomBytes2(24).toString("hex");
|
|
5370
5706
|
}
|
|
5371
5707
|
function postgresUrl(password, port) {
|
|
5372
5708
|
return `postgres://${POSTGRES_USER}:${password}@127.0.0.1:${port}/${POSTGRES_DB}`;
|
|
@@ -5640,7 +5976,7 @@ async function exposedPorts(dir, stack) {
|
|
|
5640
5976
|
const ports = /* @__PURE__ */ new Map();
|
|
5641
5977
|
for (const [key, s] of Object.entries(stack.services)) {
|
|
5642
5978
|
if (s.template !== "docker" || s.port !== void 0 || s.dir === void 0) continue;
|
|
5643
|
-
const text2 = await
|
|
5979
|
+
const text2 = await readFile6(resolve2(dir, s.dir, "Dockerfile"), "utf8").catch(() => void 0);
|
|
5644
5980
|
const port = text2 !== void 0 ? exposedPort(text2) : void 0;
|
|
5645
5981
|
if (port !== void 0) ports.set(key, port);
|
|
5646
5982
|
}
|
|
@@ -5848,7 +6184,7 @@ function volumeNameFor(box, taken, account = /* @__PURE__ */ new Set()) {
|
|
|
5848
6184
|
}
|
|
5849
6185
|
async function readPackageJson(dir) {
|
|
5850
6186
|
try {
|
|
5851
|
-
return JSON.parse(await
|
|
6187
|
+
return JSON.parse(await readFile6(join8(dir, "package.json"), "utf8"));
|
|
5852
6188
|
} catch (err) {
|
|
5853
6189
|
if (err.code === "ENOENT") return void 0;
|
|
5854
6190
|
throw new KvboxError(`${join8(dir, "package.json")}: ${err.message}`);
|
|
@@ -5856,7 +6192,7 @@ async function readPackageJson(dir) {
|
|
|
5856
6192
|
}
|
|
5857
6193
|
|
|
5858
6194
|
// src/commands/deploy/index.ts
|
|
5859
|
-
var deployCommand = new
|
|
6195
|
+
var deployCommand = new Command58("deploy").description("put the app in this directory (React, Next.js, a Node server, a Dockerfile or a static site) on a box with its own HTTPS address; redeploy by running it again").argument("[dir]", "the app's directory (default: the current one)").addOption(new Option5("-t, --template <template>", "what kind of app it is (detected from package.json and the directory when not given)").choices(TEMPLATE_IDS)).option("-n, --name <name>", "the box's name (default: the directory's name)").option("--sub <subdomain>", "its HTTPS name, https://<subdomain>.kvbox.app (default: the box's name)").addOption(new Option5("-s, --size <size>", "size of the box when it has to be made").choices(SIZE_NAMES)).option("--port <port>", "the box port of a Next.js app, Node server or container (default 3000; saved to kvbox.json)", parsePort).option("--only <service>", "with several services in kvbox.json: deploy this one only (repeatable)", (v, all) => [...all ?? [], v]).option("-y, --yes", "ask nothing: take the defaults for whatever the flags and kvbox.json leave open").option("--json", "print the result as JSON").option("--org <slug>", "deploy into this org's boxes (saved to kvbox.json)").action(async (dirArg, opts, cmd) => {
|
|
5860
6196
|
const dir = resolve3(dirArg ?? ".");
|
|
5861
6197
|
const pkg = await readPackageJson2(dir);
|
|
5862
6198
|
const facts = { indexHtml: await exists2(resolve3(dir, "index.html")), dockerfile: await exists2(resolve3(dir, "Dockerfile")) };
|
|
@@ -5930,7 +6266,7 @@ function parsePort(v) {
|
|
|
5930
6266
|
var exists2 = (path) => access5(path).then(() => true, () => false);
|
|
5931
6267
|
async function readPackageJson2(dir) {
|
|
5932
6268
|
try {
|
|
5933
|
-
return JSON.parse(await
|
|
6269
|
+
return JSON.parse(await readFile7(resolve3(dir, "package.json"), "utf8"));
|
|
5934
6270
|
} catch (err) {
|
|
5935
6271
|
if (err.code === "ENOENT") return void 0;
|
|
5936
6272
|
throw new KvboxError(`${resolve3(dir, "package.json")}: ${err.message}`);
|
|
@@ -6013,15 +6349,15 @@ async function settle2(dir, pkg, facts, saved, opts, orgFlag, cloud) {
|
|
|
6013
6349
|
}
|
|
6014
6350
|
|
|
6015
6351
|
// src/commands/volume/index.ts
|
|
6016
|
-
import { Command as
|
|
6352
|
+
import { Command as Command69 } from "commander";
|
|
6017
6353
|
|
|
6018
6354
|
// src/commands/volume/attach.ts
|
|
6019
|
-
import { Command as
|
|
6355
|
+
import { Command as Command59 } from "commander";
|
|
6020
6356
|
function describeMount(machine, volume, box) {
|
|
6021
6357
|
const path = machine.volumes?.find((v) => volume === v.name || volume.endsWith(`/${v.name}`))?.mountPath ?? volumeMountPath(volume.slice(volume.lastIndexOf("/") + 1));
|
|
6022
6358
|
return machine.status === "running" ? ` the box was restarted; the volume is at ${path} inside it` : ` box ${box} is ${machine.status}; the volume is at ${path} once it runs`;
|
|
6023
6359
|
}
|
|
6024
|
-
var attachCommand = new
|
|
6360
|
+
var attachCommand = new Command59("attach").description("attach a volume to a box at /mnt/<volume> (a running box is restarted to take it)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (picked from a list when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
6025
6361
|
if (volumeArg === void 0 || boxArg === void 0) askOrUsage("give the volume and the box: kvbox volume attach <volume> <box>");
|
|
6026
6362
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
6027
6363
|
try {
|
|
@@ -6040,11 +6376,11 @@ var attachCommand = new Command55("attach").description("attach a volume to a bo
|
|
|
6040
6376
|
});
|
|
6041
6377
|
|
|
6042
6378
|
// src/commands/volume/backup/index.ts
|
|
6043
|
-
import { Command as
|
|
6379
|
+
import { Command as Command63 } from "commander";
|
|
6044
6380
|
|
|
6045
6381
|
// src/commands/volume/backup/create.ts
|
|
6046
|
-
import { Command as
|
|
6047
|
-
var
|
|
6382
|
+
import { Command as Command60 } from "commander";
|
|
6383
|
+
var createCommand4 = new Command60("create").description("back up a volume's disk to the kvbox cloud (encrypted)").argument("<volume>", "volume name").option("--wait", "stay until the backup is ready (by default it runs in the background)").option("--json", "print the backup as JSON").action(async (volume, opts, cmd) => {
|
|
6048
6384
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6049
6385
|
try {
|
|
6050
6386
|
requireCloud3(client);
|
|
@@ -6069,8 +6405,8 @@ var createCommand3 = new Command56("create").description("back up a volume's dis
|
|
|
6069
6405
|
});
|
|
6070
6406
|
|
|
6071
6407
|
// src/commands/volume/backup/ls.ts
|
|
6072
|
-
import { Command as
|
|
6073
|
-
var
|
|
6408
|
+
import { Command as Command61 } from "commander";
|
|
6409
|
+
var lsCommand9 = new Command61("ls").alias("list").description("list volume backups: every volume's, or one volume's").argument("[volume]", "volume name (default: every volume)").option("--json", "print as JSON").action(async (volume, opts, cmd) => {
|
|
6074
6410
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6075
6411
|
try {
|
|
6076
6412
|
requireCloud3(client);
|
|
@@ -6103,8 +6439,8 @@ var lsCommand8 = new Command57("ls").alias("list").description("list volume back
|
|
|
6103
6439
|
});
|
|
6104
6440
|
|
|
6105
6441
|
// src/commands/volume/backup/restore.ts
|
|
6106
|
-
import { Command as
|
|
6107
|
-
var restoreCommand2 = new
|
|
6442
|
+
import { Command as Command62 } from "commander";
|
|
6443
|
+
var restoreCommand2 = new Command62("restore").description("put a backup back: the volume's data becomes the backup's (a running box holding it restarts)").argument("<volume>", "volume name").argument("<id>", "the backup's id (kvbox volume backup ls <volume>)").option("-y, --yes", "do not ask for confirmation").option("--json", "print the volume as JSON").action(async (volume, id, opts, cmd) => {
|
|
6108
6444
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
6109
6445
|
try {
|
|
6110
6446
|
requireCloud3(client);
|
|
@@ -6127,11 +6463,11 @@ var restoreCommand2 = new Command58("restore").description("put a backup back: t
|
|
|
6127
6463
|
});
|
|
6128
6464
|
|
|
6129
6465
|
// src/commands/volume/backup/index.ts
|
|
6130
|
-
var backupCommand2 = new
|
|
6466
|
+
var backupCommand2 = new Command63("backup").description("back up a volume's disk to the kvbox cloud, list backups, restore one").addCommand(createCommand4).addCommand(lsCommand9).addCommand(restoreCommand2);
|
|
6131
6467
|
for (const cmd of backupCommand2.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
6132
6468
|
|
|
6133
6469
|
// src/commands/volume/create.ts
|
|
6134
|
-
import { Command as
|
|
6470
|
+
import { Command as Command64 } from "commander";
|
|
6135
6471
|
function parseGib2(text2, label = "--size") {
|
|
6136
6472
|
const mib = parseMib(text2);
|
|
6137
6473
|
if (mib === void 0 || mib % 1024 !== 0) throw new KvboxError(`${label} ${text2}: write whole GB, like 50 or 50GB`);
|
|
@@ -6147,7 +6483,7 @@ function sizeProblem(answer) {
|
|
|
6147
6483
|
return err instanceof KvboxError ? err.message.replace(/^--size \S+: /, "") : String(err);
|
|
6148
6484
|
}
|
|
6149
6485
|
}
|
|
6150
|
-
var
|
|
6486
|
+
var createCommand5 = new Command64("create").alias("new").description("create a volume for a box: an empty disk of its own at /mnt/<name> inside it (a running box is restarted)").argument("[name]", "volume name (1-12 chars; the box mounts it at /mnt/<name>; asked for when left out)").option("--size <gb>", "size in GB, like 50 or 50GB (whole GB; it only occupies what is written)").option("--box <box>", "the box it is for: made on that box's host and attached to it (required on kvbox.sh; optional with --local)").option("--json", "print the volume as JSON").action(async (nameArg, opts, cmd) => {
|
|
6151
6487
|
const ask = interactive();
|
|
6152
6488
|
if (nameArg === void 0 || opts.size === void 0) askOrUsage("give the name and the size: kvbox volume create <name> --size <gb> --box <box>");
|
|
6153
6489
|
const name = nameArg ?? await text("Volume name", { validate: (a) => VOLUME_NAME_RE.test(a) ? void 0 : VOLUME_NAME_RULE });
|
|
@@ -6180,8 +6516,8 @@ var createCommand4 = new Command60("create").alias("new").description("create a
|
|
|
6180
6516
|
});
|
|
6181
6517
|
|
|
6182
6518
|
// src/commands/volume/detach.ts
|
|
6183
|
-
import { Command as
|
|
6184
|
-
var detachCommand = new
|
|
6519
|
+
import { Command as Command65 } from "commander";
|
|
6520
|
+
var detachCommand = new Command65("detach").description("detach a volume from a box; its data is kept (a running box is restarted)").argument("[volume]", "volume name (picked from a list when left out)").argument("[box]", "box name (the one the volume is on when left out)").option("--json", "print the box as JSON").action(async (volumeArg, boxArg, opts, cmd) => {
|
|
6185
6521
|
if (volumeArg === void 0) askOrUsage("give the volume: kvbox volume detach <volume> [box]");
|
|
6186
6522
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
6187
6523
|
try {
|
|
@@ -6206,8 +6542,8 @@ var detachCommand = new Command61("detach").description("detach a volume from a
|
|
|
6206
6542
|
});
|
|
6207
6543
|
|
|
6208
6544
|
// src/commands/volume/grow.ts
|
|
6209
|
-
import { Command as
|
|
6210
|
-
var growCommand = new
|
|
6545
|
+
import { Command as Command66 } from "commander";
|
|
6546
|
+
var growCommand = new Command66("grow").alias("resize").description("make a volume larger (a running box holding it is restarted once)").argument("<volume>", "volume name").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the volume as JSON").action(async (name, size, opts, cmd) => {
|
|
6211
6547
|
const sizeGib = parseGib2(size, "size");
|
|
6212
6548
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
6213
6549
|
try {
|
|
@@ -6220,8 +6556,8 @@ var growCommand = new Command62("grow").alias("resize").description("make a volu
|
|
|
6220
6556
|
});
|
|
6221
6557
|
|
|
6222
6558
|
// src/commands/volume/ls.ts
|
|
6223
|
-
import { Command as
|
|
6224
|
-
var
|
|
6559
|
+
import { Command as Command67 } from "commander";
|
|
6560
|
+
var lsCommand10 = new Command67("ls").alias("list").description("list volumes: size, what they occupy, which box has them").option("-a, --all", "every volume on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
6225
6561
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
6226
6562
|
try {
|
|
6227
6563
|
const cloud = client.target.kind === "cloud";
|
|
@@ -6252,8 +6588,8 @@ var lsCommand9 = new Command63("ls").alias("list").description("list volumes: si
|
|
|
6252
6588
|
});
|
|
6253
6589
|
|
|
6254
6590
|
// src/commands/volume/rm.ts
|
|
6255
|
-
import { Command as
|
|
6256
|
-
var
|
|
6591
|
+
import { Command as Command68 } from "commander";
|
|
6592
|
+
var rmCommand8 = new Command68("rm").alias("remove").description("delete a volume and everything on it (detach it first)").argument("<name>", "volume name").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
6257
6593
|
if (!await confirm(`Delete volume ${name} and everything on it?`, opts.yes ?? false)) {
|
|
6258
6594
|
info("cancelled");
|
|
6259
6595
|
process.exitCode = 1;
|
|
@@ -6269,15 +6605,15 @@ var rmCommand7 = new Command64("rm").alias("remove").description("delete a volum
|
|
|
6269
6605
|
});
|
|
6270
6606
|
|
|
6271
6607
|
// src/commands/volume/index.ts
|
|
6272
|
-
var volumeCommand = new
|
|
6608
|
+
var volumeCommand = new Command69("volume").aliases(["volumes", "vol"]).description("disks of their own: create one, attach it to a box at /mnt/<name>, move it to another box later").addCommand(createCommand5).addCommand(lsCommand10).addCommand(attachCommand).addCommand(detachCommand).addCommand(growCommand).addCommand(rmCommand8);
|
|
6273
6609
|
for (const cmd of volumeCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal volumes)");
|
|
6274
6610
|
volumeCommand.addCommand(backupCommand2);
|
|
6275
6611
|
|
|
6276
6612
|
// src/commands/bucket/index.ts
|
|
6277
|
-
import { Command as
|
|
6613
|
+
import { Command as Command79 } from "commander";
|
|
6278
6614
|
|
|
6279
6615
|
// src/commands/bucket/create.ts
|
|
6280
|
-
import { Command as
|
|
6616
|
+
import { Command as Command70 } from "commander";
|
|
6281
6617
|
|
|
6282
6618
|
// src/commands/bucket/shared.ts
|
|
6283
6619
|
async function bucketClient(cmd) {
|
|
@@ -6303,7 +6639,7 @@ function printRows(rows2) {
|
|
|
6303
6639
|
}
|
|
6304
6640
|
|
|
6305
6641
|
// src/commands/bucket/create.ts
|
|
6306
|
-
var
|
|
6642
|
+
var createCommand6 = new Command70("create").description("make a bucket (the first one also makes your object storage)").argument("<name>", "bucket name: 3-63 lowercase letters, digits and '-'").option("--size <GB>", "how much your object storage may hold, when this is your first bucket (default 10)").option("--region <region>", "the S3 region of your object storage (ro-west-1, de-center-1), when this is your first bucket").option("--near <box>", "put the object storage on the host of this box, when this is your first bucket").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
6307
6643
|
const sizeGib = opts.size === void 0 ? void 0 : parseGib2(opts.size);
|
|
6308
6644
|
const client = await bucketClient(cmd);
|
|
6309
6645
|
try {
|
|
@@ -6323,8 +6659,8 @@ var createCommand5 = new Command66("create").description("make a bucket (the fir
|
|
|
6323
6659
|
});
|
|
6324
6660
|
|
|
6325
6661
|
// src/commands/bucket/grow.ts
|
|
6326
|
-
import { Command as
|
|
6327
|
-
var growCommand2 = new
|
|
6662
|
+
import { Command as Command71 } from "commander";
|
|
6663
|
+
var growCommand2 = new Command71("grow").description("make your object storage larger (all your buckets share it; it restarts once)").argument("<GB>", "the new size in GB, larger than what it has").option("--json", "print the object storage as JSON").action(async (size, opts, cmd) => {
|
|
6328
6664
|
const sizeGib = parseGib2(size, "size");
|
|
6329
6665
|
const client = await bucketClient(cmd);
|
|
6330
6666
|
try {
|
|
@@ -6337,8 +6673,8 @@ var growCommand2 = new Command67("grow").description("make your object storage l
|
|
|
6337
6673
|
});
|
|
6338
6674
|
|
|
6339
6675
|
// src/commands/bucket/info.ts
|
|
6340
|
-
import { Command as
|
|
6341
|
-
var infoCommand = new
|
|
6676
|
+
import { Command as Command72 } from "commander";
|
|
6677
|
+
var infoCommand = new Command72("info").description("one bucket: its address, what it holds, how full your object storage is").argument("<name>", "bucket name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
6342
6678
|
const client = await bucketClient(cmd);
|
|
6343
6679
|
try {
|
|
6344
6680
|
const b = await client.getBucket(name);
|
|
@@ -6367,11 +6703,11 @@ with the AWS CLI: aws s3 ls s3://${b.name} --endpoint-url ${b.endpoint}`));
|
|
|
6367
6703
|
});
|
|
6368
6704
|
|
|
6369
6705
|
// src/commands/bucket/key/index.ts
|
|
6370
|
-
import { Command as
|
|
6706
|
+
import { Command as Command76 } from "commander";
|
|
6371
6707
|
|
|
6372
6708
|
// src/commands/bucket/key/create.ts
|
|
6373
|
-
import { Command as
|
|
6374
|
-
var
|
|
6709
|
+
import { Command as Command73 } from "commander";
|
|
6710
|
+
var createCommand7 = new Command73("create").description("make an access key for a bucket (the secret is shown once)").argument("<bucket>", "bucket name").option("--name <label>", "what to call the key, to tell it from the others").option("--read-only", "the key reads the bucket but cannot write to it").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
|
|
6375
6711
|
const client = await bucketClient(cmd);
|
|
6376
6712
|
try {
|
|
6377
6713
|
const key = await client.createBucketKey(bucket, { ...opts.name !== void 0 ? { name: opts.name } : {}, ...opts.readOnly ? { readOnly: true } : {} });
|
|
@@ -6394,8 +6730,8 @@ var createCommand6 = new Command69("create").description("make an access key for
|
|
|
6394
6730
|
});
|
|
6395
6731
|
|
|
6396
6732
|
// src/commands/bucket/key/ls.ts
|
|
6397
|
-
import { Command as
|
|
6398
|
-
var
|
|
6733
|
+
import { Command as Command74 } from "commander";
|
|
6734
|
+
var lsCommand11 = new Command74("ls").alias("list").description("list a bucket's access keys (never their secrets)").argument("<bucket>", "bucket name").option("--json", "print as JSON").action(async (bucket, opts, cmd) => {
|
|
6399
6735
|
const client = await bucketClient(cmd);
|
|
6400
6736
|
try {
|
|
6401
6737
|
const keys = await client.listBucketKeys(bucket);
|
|
@@ -6414,8 +6750,8 @@ var lsCommand10 = new Command70("ls").alias("list").description("list a bucket's
|
|
|
6414
6750
|
});
|
|
6415
6751
|
|
|
6416
6752
|
// src/commands/bucket/key/rm.ts
|
|
6417
|
-
import { Command as
|
|
6418
|
-
var
|
|
6753
|
+
import { Command as Command75 } from "commander";
|
|
6754
|
+
var rmCommand9 = new Command75("rm").alias("remove").description("delete an access key: whatever uses it stops reaching the bucket").argument("<bucket>", "bucket name").argument("<access-key>", "the access key id (kvbox bucket key ls)").option("-y, --yes", "do not ask for confirmation").action(async (bucket, id, opts, cmd) => {
|
|
6419
6755
|
const client = await bucketClient(cmd);
|
|
6420
6756
|
try {
|
|
6421
6757
|
if (!await confirm(`Delete key ${id} of bucket ${bucket}? Whatever uses it stops working.`, opts.yes ?? false)) {
|
|
@@ -6431,11 +6767,11 @@ var rmCommand8 = new Command71("rm").alias("remove").description("delete an acce
|
|
|
6431
6767
|
});
|
|
6432
6768
|
|
|
6433
6769
|
// src/commands/bucket/key/index.ts
|
|
6434
|
-
var
|
|
6770
|
+
var keyCommand2 = new Command76("key").aliases(["keys"]).description("access keys of a bucket: what your app signs in with").addCommand(createCommand7).addCommand(lsCommand11).addCommand(rmCommand9);
|
|
6435
6771
|
|
|
6436
6772
|
// src/commands/bucket/ls.ts
|
|
6437
|
-
import { Command as
|
|
6438
|
-
var
|
|
6773
|
+
import { Command as Command77 } from "commander";
|
|
6774
|
+
var lsCommand12 = new Command77("ls").alias("list").description("list buckets, and the object storage they are in").option("-a, --all", "every bucket on the platform (platform admins only)").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
6439
6775
|
const client = await bucketClient(cmd);
|
|
6440
6776
|
try {
|
|
6441
6777
|
const buckets = await client.listBuckets({ all: opts.all });
|
|
@@ -6465,8 +6801,8 @@ var lsCommand11 = new Command73("ls").alias("list").description("list buckets, a
|
|
|
6465
6801
|
});
|
|
6466
6802
|
|
|
6467
6803
|
// src/commands/bucket/rm.ts
|
|
6468
|
-
import { Command as
|
|
6469
|
-
var
|
|
6804
|
+
import { Command as Command78 } from "commander";
|
|
6805
|
+
var rmCommand10 = new Command78("rm").alias("remove").description("delete an empty bucket and its keys (the last one takes your object storage with it)").argument("<name>", "bucket name").option("--force", "your last bucket only: delete it with everything in it").option("-y, --yes", "do not ask for confirmation").action(async (name, opts, cmd) => {
|
|
6470
6806
|
const client = await bucketClient(cmd);
|
|
6471
6807
|
try {
|
|
6472
6808
|
const question = opts.force ? `Delete bucket ${name} with everything in it, and the object storage it is in?` : `Delete bucket ${name} and its keys?`;
|
|
@@ -6485,18 +6821,18 @@ var rmCommand9 = new Command74("rm").alias("remove").description("delete an empt
|
|
|
6485
6821
|
});
|
|
6486
6822
|
|
|
6487
6823
|
// src/commands/bucket/index.ts
|
|
6488
|
-
var bucketCommand = new
|
|
6824
|
+
var bucketCommand = new Command79("bucket").aliases(["buckets"]).description("object storage: S3 buckets for your files, and the access keys your apps use").addCommand(createCommand6).addCommand(lsCommand12).addCommand(infoCommand).addCommand(growCommand2).addCommand(rmCommand10).addCommand(keyCommand2);
|
|
6489
6825
|
var withOrg = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal buckets)");
|
|
6490
6826
|
for (const cmd of bucketCommand.commands) {
|
|
6491
|
-
if (cmd ===
|
|
6827
|
+
if (cmd === keyCommand2) cmd.commands.forEach(withOrg);
|
|
6492
6828
|
else withOrg(cmd);
|
|
6493
6829
|
}
|
|
6494
6830
|
|
|
6495
6831
|
// src/commands/cron/index.ts
|
|
6496
|
-
import { Command as
|
|
6832
|
+
import { Command as Command92 } from "commander";
|
|
6497
6833
|
|
|
6498
6834
|
// src/commands/cron/create.ts
|
|
6499
|
-
import { Command as
|
|
6835
|
+
import { Command as Command80 } from "commander";
|
|
6500
6836
|
|
|
6501
6837
|
// src/commands/cron/shared.ts
|
|
6502
6838
|
async function cronClient(cmd) {
|
|
@@ -6557,7 +6893,7 @@ function printRows2(rows2) {
|
|
|
6557
6893
|
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>")`);
|
|
6558
6894
|
|
|
6559
6895
|
// src/commands/cron/create.ts
|
|
6560
|
-
var
|
|
6896
|
+
var createCommand8 = new Command80("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) => {
|
|
6561
6897
|
const client = await cronClient(cmd);
|
|
6562
6898
|
try {
|
|
6563
6899
|
const service = await client.createCronService(name);
|
|
@@ -6574,8 +6910,8 @@ var createCommand7 = new Command76("create").description("make a cron service: a
|
|
|
6574
6910
|
});
|
|
6575
6911
|
|
|
6576
6912
|
// src/commands/cron/info.ts
|
|
6577
|
-
import { Command as
|
|
6578
|
-
var infoCommand2 = new
|
|
6913
|
+
import { Command as Command81 } from "commander";
|
|
6914
|
+
var infoCommand2 = new Command81("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) => {
|
|
6579
6915
|
const client = await cronClient(cmd);
|
|
6580
6916
|
try {
|
|
6581
6917
|
const service = await client.getCronService(name);
|
|
@@ -6599,8 +6935,8 @@ var infoCommand2 = new Command77("info").alias("get").description("show a cron s
|
|
|
6599
6935
|
});
|
|
6600
6936
|
|
|
6601
6937
|
// src/commands/cron/ls.ts
|
|
6602
|
-
import { Command as
|
|
6603
|
-
var
|
|
6938
|
+
import { Command as Command82 } from "commander";
|
|
6939
|
+
var lsCommand13 = new Command82("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) => {
|
|
6604
6940
|
const client = await cronClient(cmd);
|
|
6605
6941
|
try {
|
|
6606
6942
|
const services = await client.listCronServices({ all: opts.all });
|
|
@@ -6620,8 +6956,8 @@ var lsCommand12 = new Command78("ls").alias("list").description("list cron servi
|
|
|
6620
6956
|
});
|
|
6621
6957
|
|
|
6622
6958
|
// src/commands/cron/rm.ts
|
|
6623
|
-
import { Command as
|
|
6624
|
-
var
|
|
6959
|
+
import { Command as Command83 } from "commander";
|
|
6960
|
+
var rmCommand11 = new Command83("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) => {
|
|
6625
6961
|
const client = await cronClient(cmd);
|
|
6626
6962
|
try {
|
|
6627
6963
|
if (!await confirm(`Delete cron service ${name}? Its triggers stop firing and their run history is deleted.`, opts.yes ?? false)) {
|
|
@@ -6637,10 +6973,10 @@ var rmCommand10 = new Command79("rm").alias("remove").description("delete a cron
|
|
|
6637
6973
|
});
|
|
6638
6974
|
|
|
6639
6975
|
// src/commands/cron/trigger/index.ts
|
|
6640
|
-
import { Command as
|
|
6976
|
+
import { Command as Command91 } from "commander";
|
|
6641
6977
|
|
|
6642
6978
|
// src/commands/cron/trigger/add.ts
|
|
6643
|
-
import { Command as
|
|
6979
|
+
import { Command as Command84 } from "commander";
|
|
6644
6980
|
function portOf(value) {
|
|
6645
6981
|
const n = Number(value);
|
|
6646
6982
|
if (!Number.isInteger(n) || n < 1 || n > 65535) throw new KvboxError(`--port ${value}: a port is a number from 1 to 65535`);
|
|
@@ -6660,7 +6996,7 @@ function timeoutOf(value) {
|
|
|
6660
6996
|
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`);
|
|
6661
6997
|
return sec;
|
|
6662
6998
|
}
|
|
6663
|
-
var addCommand3 = new
|
|
6999
|
+
var addCommand3 = new Command84("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, box, expr, opts, cmd) => {
|
|
6664
7000
|
let action;
|
|
6665
7001
|
if (opts.run !== void 0) {
|
|
6666
7002
|
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");
|
|
@@ -6687,8 +7023,8 @@ var addCommand3 = new Command80("add").description("add a trigger: on a schedule
|
|
|
6687
7023
|
});
|
|
6688
7024
|
|
|
6689
7025
|
// src/commands/cron/trigger/ls.ts
|
|
6690
|
-
import { Command as
|
|
6691
|
-
var
|
|
7026
|
+
import { Command as Command85 } from "commander";
|
|
7027
|
+
var lsCommand14 = new Command85("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) => {
|
|
6692
7028
|
const client = await cronClient(cmd);
|
|
6693
7029
|
try {
|
|
6694
7030
|
const triggers = await client.listCronTriggers(service);
|
|
@@ -6704,8 +7040,8 @@ var lsCommand13 = new Command81("ls").alias("list").description("list a cron ser
|
|
|
6704
7040
|
});
|
|
6705
7041
|
|
|
6706
7042
|
// src/commands/cron/trigger/pause.ts
|
|
6707
|
-
import { Command as
|
|
6708
|
-
var pauseCommand2 = new
|
|
7043
|
+
import { Command as Command86 } from "commander";
|
|
7044
|
+
var pauseCommand2 = new Command86("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) => {
|
|
6709
7045
|
const client = await cronClient(cmd);
|
|
6710
7046
|
try {
|
|
6711
7047
|
const trigger = await client.setCronTriggerEnabled(service, id, false);
|
|
@@ -6720,8 +7056,8 @@ var pauseCommand2 = new Command82("pause").description("stop a trigger from firi
|
|
|
6720
7056
|
});
|
|
6721
7057
|
|
|
6722
7058
|
// src/commands/cron/trigger/resume.ts
|
|
6723
|
-
import { Command as
|
|
6724
|
-
var resumeCommand2 = new
|
|
7059
|
+
import { Command as Command87 } from "commander";
|
|
7060
|
+
var resumeCommand2 = new Command87("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) => {
|
|
6725
7061
|
const client = await cronClient(cmd);
|
|
6726
7062
|
try {
|
|
6727
7063
|
const trigger = await client.setCronTriggerEnabled(service, id, true);
|
|
@@ -6736,8 +7072,8 @@ var resumeCommand2 = new Command83("resume").description("let a paused trigger f
|
|
|
6736
7072
|
});
|
|
6737
7073
|
|
|
6738
7074
|
// src/commands/cron/trigger/rm.ts
|
|
6739
|
-
import { Command as
|
|
6740
|
-
var
|
|
7075
|
+
import { Command as Command88 } from "commander";
|
|
7076
|
+
var rmCommand12 = new Command88("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) => {
|
|
6741
7077
|
const client = await cronClient(cmd);
|
|
6742
7078
|
try {
|
|
6743
7079
|
if (!await confirm(`Delete trigger ${id} of cron service ${service}? Its run history is deleted too.`, opts.yes ?? false)) {
|
|
@@ -6753,8 +7089,8 @@ var rmCommand11 = new Command84("rm").alias("remove").description("delete a trig
|
|
|
6753
7089
|
});
|
|
6754
7090
|
|
|
6755
7091
|
// src/commands/cron/trigger/run.ts
|
|
6756
|
-
import { Command as
|
|
6757
|
-
var runCommand = new
|
|
7092
|
+
import { Command as Command89 } from "commander";
|
|
7093
|
+
var runCommand = new Command89("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) => {
|
|
6758
7094
|
const client = await cronClient(cmd);
|
|
6759
7095
|
try {
|
|
6760
7096
|
const trigger = await client.runCronTrigger(service, id);
|
|
@@ -6770,13 +7106,13 @@ var runCommand = new Command85("run").description("fire a trigger now, once, bes
|
|
|
6770
7106
|
});
|
|
6771
7107
|
|
|
6772
7108
|
// src/commands/cron/trigger/runs.ts
|
|
6773
|
-
import { Command as
|
|
7109
|
+
import { Command as Command90 } from "commander";
|
|
6774
7110
|
function limitOf(value) {
|
|
6775
7111
|
const n = Number(value);
|
|
6776
7112
|
if (!Number.isInteger(n) || n < 1) throw new KvboxError(`-n ${value}: a number of runs, 1 or more`);
|
|
6777
7113
|
return n;
|
|
6778
7114
|
}
|
|
6779
|
-
var runsCommand = new
|
|
7115
|
+
var runsCommand = new Command90("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) => {
|
|
6780
7116
|
const limit = limitOf(opts.limit);
|
|
6781
7117
|
const client = await cronClient(cmd);
|
|
6782
7118
|
try {
|
|
@@ -6806,10 +7142,10 @@ var runsCommand = new Command86("runs").aliases(["logs"]).description("show how
|
|
|
6806
7142
|
});
|
|
6807
7143
|
|
|
6808
7144
|
// src/commands/cron/trigger/index.ts
|
|
6809
|
-
var triggerCommand = new
|
|
7145
|
+
var triggerCommand = new Command91("trigger").aliases(["triggers"]).description("a cron service's triggers: a schedule and the request it sends to a box").addCommand(addCommand3).addCommand(lsCommand14).addCommand(runsCommand).addCommand(runCommand).addCommand(pauseCommand2).addCommand(resumeCommand2).addCommand(rmCommand12);
|
|
6810
7146
|
|
|
6811
7147
|
// src/commands/cron/index.ts
|
|
6812
|
-
var cronCommand = new
|
|
7148
|
+
var cronCommand = new Command92("cron").description("cron: call a box on a schedule, waking it first if it sleeps").addCommand(createCommand8).addCommand(lsCommand13).addCommand(infoCommand2).addCommand(rmCommand11).addCommand(triggerCommand);
|
|
6813
7149
|
var withOrg2 = (cmd) => cmd.option("--org <slug>", "act in this org (- for your personal cron services)");
|
|
6814
7150
|
for (const cmd of cronCommand.commands) {
|
|
6815
7151
|
if (cmd === triggerCommand) cmd.commands.forEach(withOrg2);
|
|
@@ -6817,11 +7153,11 @@ for (const cmd of cronCommand.commands) {
|
|
|
6817
7153
|
}
|
|
6818
7154
|
|
|
6819
7155
|
// src/commands/managed/kind.ts
|
|
6820
|
-
import { Command as
|
|
7156
|
+
import { Command as Command105 } from "commander";
|
|
6821
7157
|
|
|
6822
7158
|
// src/commands/managed/create.ts
|
|
6823
|
-
import { Command as
|
|
6824
|
-
import { setTimeout as
|
|
7159
|
+
import { Command as Command94 } from "commander";
|
|
7160
|
+
import { setTimeout as sleep4 } from "timers/promises";
|
|
6825
7161
|
|
|
6826
7162
|
// src/commands/managed/shared.ts
|
|
6827
7163
|
import "commander";
|
|
@@ -6906,8 +7242,8 @@ function parseStorage(text2, flag) {
|
|
|
6906
7242
|
// src/commands/managed/create.ts
|
|
6907
7243
|
var READY_WAIT_MS = 9e4;
|
|
6908
7244
|
var READY_STEP_MS = 2e3;
|
|
6909
|
-
var
|
|
6910
|
-
const command = new
|
|
7245
|
+
var createCommand9 = (spec) => {
|
|
7246
|
+
const command = new Command94("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");
|
|
6911
7247
|
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
6912
7248
|
return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
|
|
6913
7249
|
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
@@ -6923,7 +7259,7 @@ var createCommand8 = (spec) => {
|
|
|
6923
7259
|
const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
|
|
6924
7260
|
const shown = shownName3(made, me(client));
|
|
6925
7261
|
const ready = await spin(`starting ${spec.title}\u2026`, async () => {
|
|
6926
|
-
for (const until2 = Date.now() + READY_WAIT_MS; Date.now() < until2; await
|
|
7262
|
+
for (const until2 = Date.now() + READY_WAIT_MS; Date.now() < until2; await sleep4(READY_STEP_MS)) {
|
|
6927
7263
|
const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
|
|
6928
7264
|
if (now?.health?.ready && now.health.accepting) return true;
|
|
6929
7265
|
}
|
|
@@ -6948,8 +7284,8 @@ var createCommand8 = (spec) => {
|
|
|
6948
7284
|
};
|
|
6949
7285
|
|
|
6950
7286
|
// src/commands/managed/grow.ts
|
|
6951
|
-
import { Command as
|
|
6952
|
-
var growCommand3 = (spec) => new
|
|
7287
|
+
import { Command as Command95 } from "commander";
|
|
7288
|
+
var growCommand3 = (spec) => new Command95("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) => {
|
|
6953
7289
|
const storageGib = parseStorage(size, "size");
|
|
6954
7290
|
const client = await managedClient(cmd);
|
|
6955
7291
|
try {
|
|
@@ -6962,8 +7298,8 @@ var growCommand3 = (spec) => new Command91("grow").description("give a database
|
|
|
6962
7298
|
});
|
|
6963
7299
|
|
|
6964
7300
|
// src/commands/managed/info.ts
|
|
6965
|
-
import { Command as
|
|
6966
|
-
var infoCommand3 = (spec) => new
|
|
7301
|
+
import { Command as Command96 } from "commander";
|
|
7302
|
+
var infoCommand3 = (spec) => new Command96("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) => {
|
|
6967
7303
|
const client = await managedClient(cmd);
|
|
6968
7304
|
try {
|
|
6969
7305
|
const m = await client.getManaged(spec.kind, name);
|
|
@@ -6975,8 +7311,8 @@ var infoCommand3 = (spec) => new Command92("info").alias("get").description("sho
|
|
|
6975
7311
|
});
|
|
6976
7312
|
|
|
6977
7313
|
// src/commands/managed/link.ts
|
|
6978
|
-
import { Command as
|
|
6979
|
-
var linkCommand2 = (spec) => new
|
|
7314
|
+
import { Command as Command97 } from "commander";
|
|
7315
|
+
var linkCommand2 = (spec) => new Command97("link").description("let a box reach a database privately (same host)").argument("<db>", "the database").argument("<box>", "the box that connects to it").option("--json", "print as JSON").action(async (name, box, opts, cmd) => {
|
|
6980
7316
|
const client = await managedClient(cmd);
|
|
6981
7317
|
try {
|
|
6982
7318
|
const m = await spin(`linking ${box} to ${name}\u2026`, client.linkManaged(spec.kind, name, box));
|
|
@@ -6992,7 +7328,7 @@ var linkCommand2 = (spec) => new Command93("link").description("let a box reach
|
|
|
6992
7328
|
});
|
|
6993
7329
|
|
|
6994
7330
|
// src/commands/managed/ls.ts
|
|
6995
|
-
import { Command as
|
|
7331
|
+
import { Command as Command98 } from "commander";
|
|
6996
7332
|
function listRows(items, user, kindColumn) {
|
|
6997
7333
|
return items.map((m) => ({
|
|
6998
7334
|
owner: m.owner === user ? "private" : m.owner,
|
|
@@ -7006,7 +7342,7 @@ function listRows(items, user, kindColumn) {
|
|
|
7006
7342
|
created: age(m.createdAt)
|
|
7007
7343
|
}));
|
|
7008
7344
|
}
|
|
7009
|
-
var
|
|
7345
|
+
var lsCommand15 = (spec) => new Command98("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) => {
|
|
7010
7346
|
const client = await managedClient(cmd);
|
|
7011
7347
|
try {
|
|
7012
7348
|
const items = await client.listManaged(spec?.kind, { all: opts.all });
|
|
@@ -7026,8 +7362,8 @@ var lsCommand14 = (spec) => new Command94("ls").alias("list").description(spec ?
|
|
|
7026
7362
|
});
|
|
7027
7363
|
|
|
7028
7364
|
// src/commands/managed/password.ts
|
|
7029
|
-
import { Command as
|
|
7030
|
-
var passwordCommand = (spec) => new
|
|
7365
|
+
import { Command as Command99 } from "commander";
|
|
7366
|
+
var passwordCommand = (spec) => new Command99("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) => {
|
|
7031
7367
|
const client = await managedClient(cmd);
|
|
7032
7368
|
try {
|
|
7033
7369
|
const secret = opts.reset ? await spin(`setting a new password on ${name}\u2026`, client.resetManagedPassword(spec.kind, name)) : await client.managedPassword(spec.kind, name);
|
|
@@ -7043,8 +7379,8 @@ var passwordCommand = (spec) => new Command95("password").description("show a da
|
|
|
7043
7379
|
});
|
|
7044
7380
|
|
|
7045
7381
|
// src/commands/managed/public.ts
|
|
7046
|
-
import { Command as
|
|
7047
|
-
var publicCommand = (spec) => new
|
|
7382
|
+
import { Command as Command100 } from "commander";
|
|
7383
|
+
var publicCommand = (spec) => new Command100("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) => {
|
|
7048
7384
|
if (state !== "on" && state !== "off") throw new KvboxError(`write on or off: kvbox ${spec.command} public ${name} on`);
|
|
7049
7385
|
const client = await managedClient(cmd);
|
|
7050
7386
|
try {
|
|
@@ -7065,8 +7401,8 @@ var publicCommand = (spec) => new Command96("public").description("open a databa
|
|
|
7065
7401
|
});
|
|
7066
7402
|
|
|
7067
7403
|
// src/commands/managed/rm.ts
|
|
7068
|
-
import { Command as
|
|
7069
|
-
var
|
|
7404
|
+
import { Command as Command101 } from "commander";
|
|
7405
|
+
var rmCommand13 = (spec) => new Command101("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) => {
|
|
7070
7406
|
const client = await managedClient(cmd);
|
|
7071
7407
|
try {
|
|
7072
7408
|
if (!await confirm(`Delete database ${name} and all its data? There is no backup.`, opts.yes ?? false)) {
|
|
@@ -7082,8 +7418,8 @@ var rmCommand12 = (spec) => new Command97("rm").alias("remove").description("del
|
|
|
7082
7418
|
});
|
|
7083
7419
|
|
|
7084
7420
|
// src/commands/managed/start.ts
|
|
7085
|
-
import { Command as
|
|
7086
|
-
var startCommand2 = (spec) => new
|
|
7421
|
+
import { Command as Command102 } from "commander";
|
|
7422
|
+
var startCommand2 = (spec) => new Command102("start").description("run a stopped database again").argument("<db>", "its name").option("--json", "print as JSON").action(async (name, opts, cmd) => {
|
|
7087
7423
|
const client = await managedClient(cmd);
|
|
7088
7424
|
try {
|
|
7089
7425
|
const m = await spin(`starting ${name}\u2026`, client.startManaged(spec.kind, name));
|
|
@@ -7095,8 +7431,8 @@ var startCommand2 = (spec) => new Command98("start").description("run a stopped
|
|
|
7095
7431
|
});
|
|
7096
7432
|
|
|
7097
7433
|
// src/commands/managed/stop.ts
|
|
7098
|
-
import { Command as
|
|
7099
|
-
var stopCommand2 = (spec) => new
|
|
7434
|
+
import { Command as Command103 } from "commander";
|
|
7435
|
+
var stopCommand2 = (spec) => new Command103("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) => {
|
|
7100
7436
|
const client = await managedClient(cmd);
|
|
7101
7437
|
try {
|
|
7102
7438
|
const m = await spin(`stopping ${name}\u2026`, client.stopManaged(spec.kind, name));
|
|
@@ -7108,8 +7444,8 @@ var stopCommand2 = (spec) => new Command99("stop").description("shut a database
|
|
|
7108
7444
|
});
|
|
7109
7445
|
|
|
7110
7446
|
// src/commands/managed/unlink.ts
|
|
7111
|
-
import { Command as
|
|
7112
|
-
var unlinkCommand2 = (spec) => new
|
|
7447
|
+
import { Command as Command104 } from "commander";
|
|
7448
|
+
var unlinkCommand2 = (spec) => new Command104("unlink").description("stop a box from reaching a database").argument("<db>", "the database").argument("<box>", "the box that was linked to it").option("--json", "print as JSON").action(async (name, box, opts, cmd) => {
|
|
7113
7449
|
const client = await managedClient(cmd);
|
|
7114
7450
|
try {
|
|
7115
7451
|
const m = await spin(`unlinking ${box} from ${name}\u2026`, client.unlinkManaged(spec.kind, name, box));
|
|
@@ -7122,8 +7458,8 @@ var unlinkCommand2 = (spec) => new Command100("unlink").description("stop a box
|
|
|
7122
7458
|
|
|
7123
7459
|
// src/commands/managed/kind.ts
|
|
7124
7460
|
function kindCommand(spec, description) {
|
|
7125
|
-
const command = new
|
|
7126
|
-
for (const make of [
|
|
7461
|
+
const command = new Command105(spec.command).aliases(spec.aliases).description(description);
|
|
7462
|
+
for (const make of [createCommand9, lsCommand15, infoCommand3, passwordCommand, publicCommand, linkCommand2, unlinkCommand2, growCommand3, stopCommand2, startCommand2, rmCommand13]) {
|
|
7127
7463
|
command.addCommand(make(spec).option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
7128
7464
|
}
|
|
7129
7465
|
return command;
|
|
@@ -7136,14 +7472,14 @@ var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox run
|
|
|
7136
7472
|
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
7137
7473
|
|
|
7138
7474
|
// src/commands/managed/index.ts
|
|
7139
|
-
import { Command as
|
|
7140
|
-
var managedCommand = new
|
|
7475
|
+
import { Command as Command106 } from "commander";
|
|
7476
|
+
var managedCommand = new Command106("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand15().option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
7141
7477
|
|
|
7142
7478
|
// src/commands/env/index.ts
|
|
7143
|
-
import { Command as
|
|
7479
|
+
import { Command as Command110 } from "commander";
|
|
7144
7480
|
|
|
7145
7481
|
// src/commands/env/ls.ts
|
|
7146
|
-
import { Command as
|
|
7482
|
+
import { Command as Command107 } from "commander";
|
|
7147
7483
|
|
|
7148
7484
|
// src/commands/env/shared.ts
|
|
7149
7485
|
function requireCloud4(client) {
|
|
@@ -7170,7 +7506,7 @@ function firstBootHint(box, name) {
|
|
|
7170
7506
|
}
|
|
7171
7507
|
|
|
7172
7508
|
// src/commands/env/ls.ts
|
|
7173
|
-
var
|
|
7509
|
+
var lsCommand16 = new Command107("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) => {
|
|
7174
7510
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7175
7511
|
try {
|
|
7176
7512
|
if (opts.box !== void 0) {
|
|
@@ -7209,8 +7545,8 @@ var lsCommand15 = new Command103("ls").alias("list").description("list the varia
|
|
|
7209
7545
|
});
|
|
7210
7546
|
|
|
7211
7547
|
// src/commands/env/rm.ts
|
|
7212
|
-
import { Command as
|
|
7213
|
-
var
|
|
7548
|
+
import { Command as Command108 } from "commander";
|
|
7549
|
+
var rmCommand14 = new Command108("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) => {
|
|
7214
7550
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7215
7551
|
try {
|
|
7216
7552
|
const target = opts.box === void 0 ? void 0 : await findBox2(client, opts.box);
|
|
@@ -7247,8 +7583,8 @@ var rmCommand13 = new Command104("rm").alias("remove").description("remove varia
|
|
|
7247
7583
|
});
|
|
7248
7584
|
|
|
7249
7585
|
// src/commands/env/set.ts
|
|
7250
|
-
import { Command as
|
|
7251
|
-
var setCommand2 = new
|
|
7586
|
+
import { Command as Command109 } from "commander";
|
|
7587
|
+
var setCommand2 = new Command109("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) => {
|
|
7252
7588
|
const client = await clientFor(cmd.optsWithGlobals(), { autoStart: false });
|
|
7253
7589
|
try {
|
|
7254
7590
|
const owner = opts.box === void 0 ? requireCloud4(client) : void 0;
|
|
@@ -7285,14 +7621,14 @@ var setCommand2 = new Command105("set").description("add or change a variable; b
|
|
|
7285
7621
|
});
|
|
7286
7622
|
|
|
7287
7623
|
// src/commands/env/index.ts
|
|
7288
|
-
var envCommand = new
|
|
7624
|
+
var envCommand = new Command110("env").description("environment variables every box of yours gets when it starts (secrets too)").addCommand(lsCommand16, { isDefault: true }).addCommand(setCommand2).addCommand(rmCommand14);
|
|
7289
7625
|
for (const cmd of envCommand.commands) cmd.option("--org <slug>", "the org's variables instead of yours");
|
|
7290
7626
|
|
|
7291
7627
|
// src/commands/domain/index.ts
|
|
7292
|
-
import { Command as
|
|
7628
|
+
import { Command as Command114 } from "commander";
|
|
7293
7629
|
|
|
7294
7630
|
// src/commands/domain/add.ts
|
|
7295
|
-
import { Command as
|
|
7631
|
+
import { Command as Command111 } from "commander";
|
|
7296
7632
|
|
|
7297
7633
|
// src/commands/domain/shared.ts
|
|
7298
7634
|
function requireCloud5(client) {
|
|
@@ -7312,7 +7648,7 @@ function hostIn(name, zone) {
|
|
|
7312
7648
|
}
|
|
7313
7649
|
|
|
7314
7650
|
// src/commands/domain/add.ts
|
|
7315
|
-
var addCommand4 = new
|
|
7651
|
+
var addCommand4 = new Command111("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) => {
|
|
7316
7652
|
const domain = assertDomain(domainArg.trim().toLowerCase());
|
|
7317
7653
|
const port = opts.port === void 0 ? void 0 : parsePorts([opts.port])[0];
|
|
7318
7654
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
@@ -7348,8 +7684,8 @@ kvbox checks every minute; ${domain} is served at ${d.url} once its records are
|
|
|
7348
7684
|
});
|
|
7349
7685
|
|
|
7350
7686
|
// src/commands/domain/ls.ts
|
|
7351
|
-
import { Command as
|
|
7352
|
-
var
|
|
7687
|
+
import { Command as Command112 } from "commander";
|
|
7688
|
+
var lsCommand17 = new Command112("ls").alias("list").description("list your custom domains and whether they are live").option("--json", "print as JSON").action(async (opts, cmd) => {
|
|
7353
7689
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7354
7690
|
try {
|
|
7355
7691
|
requireCloud5(client);
|
|
@@ -7378,8 +7714,8 @@ var lsCommand16 = new Command108("ls").alias("list").description("list your cust
|
|
|
7378
7714
|
});
|
|
7379
7715
|
|
|
7380
7716
|
// src/commands/domain/rm.ts
|
|
7381
|
-
import { Command as
|
|
7382
|
-
var
|
|
7717
|
+
import { Command as Command113 } from "commander";
|
|
7718
|
+
var rmCommand15 = new Command113("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) => {
|
|
7383
7719
|
const domain = domainArg.trim().toLowerCase();
|
|
7384
7720
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
7385
7721
|
try {
|
|
@@ -7400,15 +7736,15 @@ var rmCommand14 = new Command109("rm").alias("remove").description("stop serving
|
|
|
7400
7736
|
});
|
|
7401
7737
|
|
|
7402
7738
|
// src/commands/domain/index.ts
|
|
7403
|
-
var domainCommand = new
|
|
7739
|
+
var domainCommand = new Command114("domain").alias("domains").description("serve a box at a domain of your own").addCommand(addCommand4).addCommand(lsCommand17).addCommand(rmCommand15);
|
|
7404
7740
|
for (const cmd of domainCommand.commands) cmd.option("--org <slug>", "act in this org (- for your personal boxes)");
|
|
7405
7741
|
|
|
7406
7742
|
// src/commands/update.ts
|
|
7407
|
-
import { spawn as
|
|
7743
|
+
import { spawn as spawn7 } from "child_process";
|
|
7408
7744
|
import { mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
7409
7745
|
import { tmpdir } from "os";
|
|
7410
7746
|
import { join as join9 } from "path";
|
|
7411
|
-
import { Command as
|
|
7747
|
+
import { Command as Command115 } from "commander";
|
|
7412
7748
|
|
|
7413
7749
|
// src/update.ts
|
|
7414
7750
|
import { mkdirSync, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
@@ -7522,12 +7858,12 @@ async function download(url) {
|
|
|
7522
7858
|
}
|
|
7523
7859
|
function run2(cmd, args) {
|
|
7524
7860
|
return new Promise((resolve4, reject) => {
|
|
7525
|
-
const child =
|
|
7861
|
+
const child = spawn7(cmd, args, { stdio: "inherit" });
|
|
7526
7862
|
child.on("error", (err) => reject(new KvboxError(`could not run ${cmd}: ${err.message}`)));
|
|
7527
7863
|
child.on("exit", (code, signal) => resolve4(code ?? (signal ? 1 : 0)));
|
|
7528
7864
|
});
|
|
7529
7865
|
}
|
|
7530
|
-
var selfUpdateCommand = new
|
|
7866
|
+
var selfUpdateCommand = new Command115("update").description("update kvbox to the latest version (reruns the installer from kvbox.sh, agent skill included)").action(async () => {
|
|
7531
7867
|
suppressUpdateNotice();
|
|
7532
7868
|
const inst = installerFor(process.platform, process.env["KVBOX_INSTALL_URL"] || INSTALL_BASE);
|
|
7533
7869
|
let code;
|
|
@@ -7606,6 +7942,7 @@ var HELP_GROUPS = [
|
|
|
7606
7942
|
["login", "log in to the kvbox cloud or your own control plane"],
|
|
7607
7943
|
["logout", "log out; commands target this machine again"],
|
|
7608
7944
|
["whoami", "show the account and control plane in use"],
|
|
7945
|
+
["key", "API keys for programs: CI, agents, the SDK"],
|
|
7609
7946
|
["org", "shared slugs that own boxes, with owners, admins and members"],
|
|
7610
7947
|
["usage", "what your boxes and volumes used, and what it cost"],
|
|
7611
7948
|
["credit", "the prepaid credit left on your account and orgs"],
|
|
@@ -7653,7 +7990,7 @@ function installRootHelp(program) {
|
|
|
7653
7990
|
|
|
7654
7991
|
// src/program.ts
|
|
7655
7992
|
function buildProgram() {
|
|
7656
|
-
const program = new
|
|
7993
|
+
const program = new Command116("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();
|
|
7657
7994
|
program.addCommand(vmCommand);
|
|
7658
7995
|
program.addCommand(snapshotsCommand);
|
|
7659
7996
|
program.addCommand(volumeCommand);
|
|
@@ -7667,6 +8004,7 @@ function buildProgram() {
|
|
|
7667
8004
|
program.addCommand(loginCommand);
|
|
7668
8005
|
program.addCommand(logoutCommand);
|
|
7669
8006
|
program.addCommand(whoamiCommand);
|
|
8007
|
+
program.addCommand(keyCommand);
|
|
7670
8008
|
program.addCommand(orgCommand);
|
|
7671
8009
|
program.addCommand(usageCommand2);
|
|
7672
8010
|
program.addCommand(creditCommand);
|