@keyboxed/cli 0.2.0 → 0.2.1
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/keybox.js +235 -85
- package/package.json +1 -1
package/dist/keybox.js
CHANGED
|
@@ -401,6 +401,7 @@ var init_ui = __esm({
|
|
|
401
401
|
var prompt_exports = {};
|
|
402
402
|
__export(prompt_exports, {
|
|
403
403
|
ask: () => ask,
|
|
404
|
+
checklist: () => checklist,
|
|
404
405
|
choose: () => choose,
|
|
405
406
|
confirm: () => confirm,
|
|
406
407
|
readSecret: () => readSecret,
|
|
@@ -537,49 +538,152 @@ async function ask(question, def = "") {
|
|
|
537
538
|
rl.close();
|
|
538
539
|
return answer || def;
|
|
539
540
|
}
|
|
540
|
-
|
|
541
|
-
|
|
541
|
+
function keysOf(s) {
|
|
542
|
+
const keys = [];
|
|
543
|
+
for (let i = 0; i < s.length; ) {
|
|
544
|
+
const m = s[i] === "\x1B" ? /^\x1b(\[[0-9;?]*[A-Za-z~]|O[A-Za-z])/.exec(s.slice(i)) : null;
|
|
545
|
+
const k = m ? m[0] : s[i];
|
|
546
|
+
keys.push(k);
|
|
547
|
+
i += k.length;
|
|
548
|
+
}
|
|
549
|
+
return keys;
|
|
550
|
+
}
|
|
551
|
+
function list(question, options, o) {
|
|
542
552
|
const out2 = process.stderr;
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
553
|
+
const filterable = !o.multi && options.length > 9;
|
|
554
|
+
const checked = o.checked;
|
|
555
|
+
let query = "";
|
|
556
|
+
let shown = options.map((_, k) => k);
|
|
557
|
+
let cur = Math.min(o.def, options.length - 1);
|
|
558
|
+
let top = 0;
|
|
559
|
+
let drawn = 0;
|
|
560
|
+
const cols = () => Math.max(24, (out2.columns ?? 80) - 1);
|
|
561
|
+
const rows = () => Math.max(3, Math.min(12, (out2.rows ?? 24) - 6, options.length));
|
|
562
|
+
const help2 = () => {
|
|
563
|
+
const pos = shown.length > rows() ? `${cur + 1}/${shown.length} \xB7 ` : "";
|
|
564
|
+
if (o.multi) return `${pos}\u2191\u2193 move \xB7 space pick \xB7 a all \xB7 n none \xB7 enter done \xB7 ${checked.size} picked`;
|
|
565
|
+
return `${pos}\u2191\u2193 move \xB7 ${filterable ? "type to filter \xB7 " : ""}enter choose \xB7 esc cancel`;
|
|
566
|
+
};
|
|
567
|
+
const line = (k, here) => {
|
|
568
|
+
const opt = options[k];
|
|
569
|
+
const on = o.multi ? checked.has(k) : here;
|
|
570
|
+
const room = cols() - 5;
|
|
571
|
+
const label2 = clip(opt.label, room);
|
|
572
|
+
const hint = opt.hint ? clip(opt.hint, room - label2.length - 2) : "";
|
|
573
|
+
const text = here ? c.bold(label2) : on ? label2 : c.dim(label2);
|
|
574
|
+
return ` ${here ? c.accent("\u203A") : " "}${on ? c.accent("\u25A0") : c.dim("\u25A1")} ${text}${hint ? ` ${c.dim(hint)}` : ""}`;
|
|
575
|
+
};
|
|
576
|
+
const draw = () => {
|
|
577
|
+
const n = rows();
|
|
578
|
+
if (cur < top) top = cur;
|
|
579
|
+
if (cur >= top + n) top = cur - n + 1;
|
|
580
|
+
top = Math.max(0, Math.min(top, Math.max(0, shown.length - n)));
|
|
581
|
+
const lines = [];
|
|
582
|
+
if (filterable) lines.push(` ${c.dim("/")} ${query ? clip(query, cols() - 6) : c.dim("type to filter")}`);
|
|
583
|
+
for (let r = 0; r < n; r++) {
|
|
584
|
+
const at = top + r;
|
|
585
|
+
lines.push(at < shown.length ? line(shown[at], at === cur) : !shown.length && r === 0 ? c.dim(" no match") : "");
|
|
551
586
|
}
|
|
587
|
+
lines.push(` ${c.dim(clip(help2(), cols() - 3))}`);
|
|
588
|
+
out2.write(`${drawn ? `\x1B[${drawn}A` : ""}\r\x1B[J${lines.join("\n")}
|
|
589
|
+
`);
|
|
590
|
+
drawn = lines.length;
|
|
591
|
+
};
|
|
592
|
+
const refilter = () => {
|
|
593
|
+
const q = query.toLowerCase();
|
|
594
|
+
shown = options.map((_, k) => k).filter((k) => !q || `${options[k].label} ${options[k].hint ?? ""}`.toLowerCase().includes(q));
|
|
595
|
+
cur = 0;
|
|
596
|
+
top = 0;
|
|
552
597
|
};
|
|
553
598
|
out2.write(`${c.accent("?")} ${question}
|
|
554
599
|
\x1B[?25l`);
|
|
555
|
-
draw(
|
|
556
|
-
process.stdin
|
|
557
|
-
|
|
558
|
-
|
|
600
|
+
draw();
|
|
601
|
+
const stdin = process.stdin;
|
|
602
|
+
stdin.setRawMode(true);
|
|
603
|
+
stdin.resume();
|
|
604
|
+
stdin.setEncoding("utf8");
|
|
559
605
|
return new Promise((resolve, reject) => {
|
|
606
|
+
let over = false;
|
|
560
607
|
const finish = (err) => {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
608
|
+
over = true;
|
|
609
|
+
stdin.setRawMode(false);
|
|
610
|
+
stdin.pause();
|
|
611
|
+
stdin.off("data", on);
|
|
612
|
+
out2.write(`\x1B[${drawn}A\r\x1B[J\x1B[?25h`);
|
|
565
613
|
if (err) return reject(err);
|
|
566
|
-
|
|
614
|
+
if (o.multi) {
|
|
615
|
+
const picked = [...checked].sort((a, b) => a - b);
|
|
616
|
+
const names = picked.map((k) => options[k].label).join(", ");
|
|
617
|
+
out2.write(` ${c.accent("\u25A0")} ${picked.length ? clip(`${picked.length} picked: ${names}`, cols() - 4) : c.dim("none")}
|
|
618
|
+
`);
|
|
619
|
+
resolve(picked);
|
|
620
|
+
} else {
|
|
621
|
+
out2.write(` ${c.accent("\u25A0")} ${options[shown[cur]].label}
|
|
567
622
|
`);
|
|
568
|
-
|
|
623
|
+
resolve([shown[cur]]);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
const move = (d, wrap = true) => {
|
|
627
|
+
if (!shown.length) return;
|
|
628
|
+
const next = cur + d;
|
|
629
|
+
cur = wrap ? (next + shown.length) % shown.length : Math.max(0, Math.min(shown.length - 1, next));
|
|
569
630
|
};
|
|
570
|
-
const on = (
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
631
|
+
const on = (chunk) => {
|
|
632
|
+
for (const k of keysOf(chunk)) {
|
|
633
|
+
if (over) return;
|
|
634
|
+
if (k === "") return finish(new UserError("Cancelled."));
|
|
635
|
+
if (k === "\x1B") {
|
|
636
|
+
if (query) {
|
|
637
|
+
query = "";
|
|
638
|
+
refilter();
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
return finish(new UserError("Cancelled."));
|
|
642
|
+
}
|
|
643
|
+
if (k === "\r" || k === "\n") {
|
|
644
|
+
if (o.multi || shown.length) return finish();
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (k === "\x1B[A" || k === "" || !filterable && k === "k") move(-1);
|
|
648
|
+
else if (k === "\x1B[B" || k === "" || k === " " || !filterable && k === "j") move(1);
|
|
649
|
+
else if (k === "\x1B[5~") move(-rows(), false);
|
|
650
|
+
else if (k === "\x1B[6~") move(rows(), false);
|
|
651
|
+
else if (k === "\x1B[H" || k === "\x1B[1~" || k === "\x1BOH") cur = 0;
|
|
652
|
+
else if (k === "\x1B[F" || k === "\x1B[4~" || k === "\x1BOF") cur = Math.max(0, shown.length - 1);
|
|
653
|
+
else if (o.multi && k === " ") {
|
|
654
|
+
const at = shown[cur];
|
|
655
|
+
checked.has(at) ? checked.delete(at) : checked.add(at);
|
|
656
|
+
move(1, false);
|
|
657
|
+
} else if (o.multi && k === "a") shown.forEach((x) => checked.add(x));
|
|
658
|
+
else if (o.multi && k === "n") checked.clear();
|
|
659
|
+
else if (filterable && (k === "\x7F" || k === "\b")) {
|
|
660
|
+
query = query.slice(0, -1);
|
|
661
|
+
refilter();
|
|
662
|
+
} else if (filterable && k === "") {
|
|
663
|
+
query = "";
|
|
664
|
+
refilter();
|
|
665
|
+
} else if (filterable && k.length === 1 && k >= " ") {
|
|
666
|
+
query += k;
|
|
667
|
+
refilter();
|
|
668
|
+
} else if (!filterable && /^[1-9]$/.test(k) && Number(k) <= shown.length) cur = Number(k) - 1;
|
|
669
|
+
}
|
|
577
670
|
draw();
|
|
578
671
|
};
|
|
579
|
-
|
|
672
|
+
stdin.on("data", on);
|
|
580
673
|
});
|
|
581
674
|
}
|
|
582
|
-
|
|
675
|
+
async function choose(question, options, def = 0) {
|
|
676
|
+
if (!process.stdin.isTTY || !color) return options[def].value;
|
|
677
|
+
const [k] = await list(question, options, { multi: false, def, checked: /* @__PURE__ */ new Set() });
|
|
678
|
+
return options[k].value;
|
|
679
|
+
}
|
|
680
|
+
async function checklist(question, options, preselected) {
|
|
681
|
+
const checked = new Set(options.flatMap((opt, k) => preselected(opt.value) ? [k] : []));
|
|
682
|
+
if (!process.stdin.isTTY || !color || !options.length) return [...checked].map((k) => options[k].value);
|
|
683
|
+
const picked = await list(question, options, { multi: true, def: 0, checked });
|
|
684
|
+
return picked.map((k) => options[k].value);
|
|
685
|
+
}
|
|
686
|
+
var GLYPHS, MAX_DOTS, clip;
|
|
583
687
|
var init_prompt = __esm({
|
|
584
688
|
"src/prompt.ts"() {
|
|
585
689
|
"use strict";
|
|
@@ -588,6 +692,7 @@ var init_prompt = __esm({
|
|
|
588
692
|
init_ui();
|
|
589
693
|
GLYPHS = "\u2591\u2592\u2593\u2588#%&@$";
|
|
590
694
|
MAX_DOTS = 32;
|
|
695
|
+
clip = (s, n) => n <= 0 ? "" : s.length <= n ? s : n === 1 ? "\u2026" : `${s.slice(0, n - 1)}\u2026`;
|
|
591
696
|
}
|
|
592
697
|
});
|
|
593
698
|
|
|
@@ -720,6 +825,45 @@ function classify(found, existing, opts = {}) {
|
|
|
720
825
|
}
|
|
721
826
|
return { plans, skipped, unknown };
|
|
722
827
|
}
|
|
828
|
+
function printSkipped(skipped) {
|
|
829
|
+
const byWhy = /* @__PURE__ */ new Map();
|
|
830
|
+
for (const s of skipped) byWhy.set(s.why, [...byWhy.get(s.why) ?? [], s.name]);
|
|
831
|
+
for (const [why, names] of byWhy) {
|
|
832
|
+
const list2 = names.length > 6 ? `${names.slice(0, 6).join(", ")} +${names.length - 6} more` : names.join(", ");
|
|
833
|
+
process.stderr.write(` ${c.dim(`${why}: ${list2}`)}
|
|
834
|
+
`);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
async function placeUnknown(f, progress, replaces) {
|
|
838
|
+
const pick = await choose(`${c.dim(progress)} Where may ${c.bold(f.name)} be sent?`, [
|
|
839
|
+
{ value: "_custom", label: "A host I will type", hint: "e.g. api.example.com" },
|
|
840
|
+
{ value: "_skip", label: "Skip this one" },
|
|
841
|
+
...PROVIDERS.map((p) => ({ value: p.id, label: p.label, hint: p.hosts[0] }))
|
|
842
|
+
]);
|
|
843
|
+
if (pick === "_skip") return null;
|
|
844
|
+
if (pick !== "_custom") {
|
|
845
|
+
const p = byId(pick);
|
|
846
|
+
return { ...f, provider: p, hosts: p.hosts, header: p.header, format: p.format, flags: ["chosen by you"], replaces };
|
|
847
|
+
}
|
|
848
|
+
let host = "";
|
|
849
|
+
for (let tries = 0; tries < 3 && !host; tries++) {
|
|
850
|
+
const raw = (await ask("Hostname it may be sent to (empty to skip):")).trim().toLowerCase();
|
|
851
|
+
if (!raw) return null;
|
|
852
|
+
const h = raw.replace(/^[a-z]+:\/\//, "").replace(/[/?#].*$/, "").replace(/:\d+$/, "");
|
|
853
|
+
if (/^[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z]{2,63}$/.test(h)) host = h;
|
|
854
|
+
else warn(`${raw} is not a hostname. Example: api.example.com`);
|
|
855
|
+
}
|
|
856
|
+
if (!host) return null;
|
|
857
|
+
const how = await choose(`How does ${host} expect the key?`, [
|
|
858
|
+
{ value: "bearer", label: "Authorization: Bearer <key>", hint: "most APIs" },
|
|
859
|
+
{ value: "x-api-key", label: "x-api-key: <key>" },
|
|
860
|
+
{ value: "header", label: "Another header, raw value" },
|
|
861
|
+
{ value: "basic", label: "Basic auth", hint: "value is user:pass" }
|
|
862
|
+
]);
|
|
863
|
+
const header = how === "x-api-key" ? "x-api-key" : how === "header" ? (await ask("Header name:", "x-api-key")).toLowerCase() : "authorization";
|
|
864
|
+
const format = how === "bearer" ? "bearer" : how === "basic" ? "basic" : "raw";
|
|
865
|
+
return { ...f, hosts: [host], header, format, flags: ["custom host"], replaces };
|
|
866
|
+
}
|
|
723
867
|
function dotenvFiles() {
|
|
724
868
|
try {
|
|
725
869
|
return readdirSync(".").filter((f) => /^\.env(\..+)?$/.test(f) && !/\.(example|sample|template)$/.test(f));
|
|
@@ -761,56 +905,62 @@ async function migrate(opts) {
|
|
|
761
905
|
throw err;
|
|
762
906
|
}
|
|
763
907
|
stop(`${c.accent("\u25A0")} Read ${found.length} entr${found.length === 1 ? "y" : "ies"} from ${source.label} ${c.dim("(names only below; values are never shown)")}`);
|
|
764
|
-
const { plans, skipped, unknown } = classify(found, existing, { only: opts.only });
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
908
|
+
const { plans: matched, skipped, unknown } = classify(found, existing, { only: opts.only });
|
|
909
|
+
const interactive = Boolean(process.stdin.isTTY) && !opts.yes && !opts.dryRun;
|
|
910
|
+
const count = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
911
|
+
const tally = [
|
|
912
|
+
[matched.length, "recognised", "known provider, destination filled in"],
|
|
913
|
+
[unknown.length, "no preset", interactive ? "you pick which to keep and where each may go" : "skipped; add with keybox secrets add NAME --host"],
|
|
914
|
+
[skipped.length, "skipped", "not credentials, placeholders or unsupported"]
|
|
915
|
+
];
|
|
916
|
+
for (const [n, label2, why] of tally) if (n) process.stderr.write(` ${c.bold(String(n).padStart(3))} ${label2.padEnd(11)}${c.dim(why)}
|
|
917
|
+
`);
|
|
918
|
+
printSkipped(skipped);
|
|
919
|
+
process.stderr.write("\n");
|
|
920
|
+
let plans = matched;
|
|
921
|
+
if (interactive && matched.length) {
|
|
922
|
+
const keep = new Set(
|
|
923
|
+
await checklist(
|
|
924
|
+
`Store which of the ${count(matched.length, "recognised key")}?`,
|
|
925
|
+
matched.map((p) => ({ value: p.name, label: p.name, hint: `${p.provider.label} \u2192 ${p.hosts.join(", ")}${p.replaces ? " \xB7 replaces existing" : ""}${p.flags.length ? ` \xB7 ${p.flags.join(", ")}` : ""}` })),
|
|
926
|
+
() => true
|
|
927
|
+
)
|
|
928
|
+
);
|
|
929
|
+
plans = matched.filter((p) => keep.has(p.name));
|
|
930
|
+
}
|
|
931
|
+
const later = [];
|
|
932
|
+
if (unknown.length && !interactive) for (const f of unknown) later.push({ name: f.name, why: "no preset; add it with --host" });
|
|
933
|
+
if (unknown.length && interactive) {
|
|
934
|
+
const pick = new Set(
|
|
935
|
+
await checklist(
|
|
936
|
+
`${count(unknown.length, "key has", "keys have")} no preset. Pick the ones to set up now (the rest are skipped):`,
|
|
937
|
+
unknown.map((f) => ({ value: f.name, label: f.name, hint: f.origin })),
|
|
938
|
+
() => false
|
|
939
|
+
)
|
|
940
|
+
);
|
|
941
|
+
const chosen = unknown.filter((f) => pick.has(f.name));
|
|
942
|
+
for (const f of unknown) if (!pick.has(f.name)) later.push({ name: f.name, why: "not picked" });
|
|
943
|
+
for (const [n, f] of chosen.entries()) {
|
|
944
|
+
const plan = await placeUnknown(f, `(${n + 1}/${chosen.length})`, existing.has(f.name));
|
|
945
|
+
if (plan) plans.push(plan);
|
|
946
|
+
else later.push({ name: f.name, why: "skipped by you" });
|
|
791
947
|
}
|
|
792
948
|
}
|
|
793
949
|
if (plans.length) {
|
|
794
950
|
process.stdout.write(
|
|
795
951
|
headed([
|
|
796
952
|
["NAME", "PROVIDER", "ONLY SENT TO", ""],
|
|
797
|
-
...plans.map((p) => [
|
|
798
|
-
p.name,
|
|
799
|
-
p.provider?.label ?? "Custom",
|
|
800
|
-
p.hosts.join(","),
|
|
801
|
-
[p.replaces ? "replaces existing" : "new", ...p.flags].join(", ")
|
|
802
|
-
])
|
|
953
|
+
...plans.map((p) => [p.name, p.provider?.label ?? "Custom", p.hosts.join(","), [p.replaces ? "replaces existing" : "new", ...p.flags].join(", ")])
|
|
803
954
|
])
|
|
804
955
|
);
|
|
805
956
|
}
|
|
806
|
-
|
|
807
|
-
`);
|
|
957
|
+
if (!interactive) printSkipped(later);
|
|
808
958
|
for (const p of plans.filter((p2) => p2.flags.includes("admin-grade"))) {
|
|
809
959
|
warn(`${p.name} is an admin-grade key. ${p.provider?.adminHint ?? ""} Keybox blocks key-minting calls either way.`);
|
|
810
960
|
}
|
|
811
961
|
if (!plans.length) return note(`Nothing to migrate from ${source.label}.`);
|
|
812
962
|
if (opts.dryRun) return note("Dry run. Nothing was stored.");
|
|
813
|
-
if (!opts.yes && !await confirm(`Store ${plans.length
|
|
963
|
+
if (!opts.yes && !await confirm(`Store ${count(plans.length, "key")} in Keybox?`, true)) {
|
|
814
964
|
throw new UserError("Cancelled. Re-run with --yes to skip the prompt.");
|
|
815
965
|
}
|
|
816
966
|
let stored = 0;
|
|
@@ -990,9 +1140,9 @@ var init_migrate = __esm({
|
|
|
990
1140
|
usage: "keybox migrate --from gcp [--project my-project]",
|
|
991
1141
|
async fetch(_arg, o) {
|
|
992
1142
|
const p = o.project ? ["--project", o.project] : [];
|
|
993
|
-
const
|
|
1143
|
+
const list2 = json(await capture("gcloud", ["secrets", "list", "--format=json", ...p]));
|
|
994
1144
|
const out2 = [];
|
|
995
|
-
for (const s of
|
|
1145
|
+
for (const s of list2) {
|
|
996
1146
|
const id = s.name.split("/").at(-1);
|
|
997
1147
|
const value = (await capture("gcloud", ["secrets", "versions", "access", "latest", `--secret=${id}`, ...p])).replace(/\n$/, "");
|
|
998
1148
|
out2.push({ name: toSecretName(id), value, origin: `gcp:${id}` });
|
|
@@ -1393,7 +1543,7 @@ var VERSION;
|
|
|
1393
1543
|
var init_version = __esm({
|
|
1394
1544
|
"src/version.ts"() {
|
|
1395
1545
|
"use strict";
|
|
1396
|
-
VERSION = true ? "0.2.
|
|
1546
|
+
VERSION = true ? "0.2.1" : "0.0.0-dev";
|
|
1397
1547
|
}
|
|
1398
1548
|
});
|
|
1399
1549
|
|
|
@@ -1485,25 +1635,25 @@ async function checks(cfg) {
|
|
|
1485
1635
|
}
|
|
1486
1636
|
return out2;
|
|
1487
1637
|
}
|
|
1488
|
-
function printChecks(
|
|
1489
|
-
for (const ch of
|
|
1638
|
+
function printChecks(list2) {
|
|
1639
|
+
for (const ch of list2) {
|
|
1490
1640
|
const mark = ch.ok === true ? c.ok("\u2713") : ch.ok === "warn" ? c.warn("!") : c.bad("\u2717");
|
|
1491
1641
|
process.stderr.write(` ${mark} ${ch.label.padEnd(10)} ${ch.ok === true ? c.dim(ch.detail) : ch.detail}
|
|
1492
1642
|
`);
|
|
1493
1643
|
}
|
|
1494
|
-
return
|
|
1644
|
+
return list2.every((ch) => ch.ok !== false);
|
|
1495
1645
|
}
|
|
1496
1646
|
async function verify(opts) {
|
|
1497
1647
|
const cfg = requireConfig();
|
|
1498
1648
|
const account = await resolveAccount(cfg);
|
|
1499
|
-
const
|
|
1649
|
+
const list2 = await checks(cfg);
|
|
1500
1650
|
if (opts.json) {
|
|
1501
|
-
process.stdout.write(JSON.stringify({ account, worker: cfg.name, ok:
|
|
1502
|
-
if (!
|
|
1651
|
+
process.stdout.write(JSON.stringify({ account, worker: cfg.name, ok: list2.every((c2) => c2.ok !== false), checks: list2 }, null, 2) + "\n");
|
|
1652
|
+
if (!list2.every((c2) => c2.ok !== false)) process.exitCode = 1;
|
|
1503
1653
|
return;
|
|
1504
1654
|
}
|
|
1505
1655
|
step(`Verifying ${c.bold(cfg.name)} in account ${account.slice(0, 8)}\u2026`);
|
|
1506
|
-
const good = printChecks(
|
|
1656
|
+
const good = printChecks(list2);
|
|
1507
1657
|
process.stderr.write("\n");
|
|
1508
1658
|
if (good) {
|
|
1509
1659
|
ok("This Keybox is running exactly the code in this CLI, and nothing else is watching its traffic.");
|
|
@@ -1710,21 +1860,21 @@ ${c.accent("\u25A0")} Keybox is running at ${c.bold(url)}
|
|
|
1710
1860
|
async function verifyStep() {
|
|
1711
1861
|
const cfg = requireConfig();
|
|
1712
1862
|
try {
|
|
1713
|
-
const
|
|
1714
|
-
if (!
|
|
1863
|
+
const list2 = await task("Verify", () => checks(cfg), (l) => l.every((x) => x.ok === true) ? "deployed code matches this CLI" : "see below");
|
|
1864
|
+
if (!list2.every((x) => x.ok === true)) printChecks(list2);
|
|
1715
1865
|
} catch {
|
|
1716
1866
|
note("Could not verify yet; run `keybox verify` in a minute.");
|
|
1717
1867
|
}
|
|
1718
1868
|
}
|
|
1719
1869
|
async function nextSteps() {
|
|
1720
|
-
const
|
|
1870
|
+
const list2 = () => {
|
|
1721
1871
|
process.stderr.write(`
|
|
1722
1872
|
${c.accent("\u25A0")} Next
|
|
1723
1873
|
`);
|
|
1724
1874
|
for (const [cmd, what] of LATER) process.stderr.write(` ${cmd.padEnd(38)} ${c.dim(what)}
|
|
1725
1875
|
`);
|
|
1726
1876
|
};
|
|
1727
|
-
if (!process.stdin.isTTY) return
|
|
1877
|
+
if (!process.stdin.isTTY) return list2();
|
|
1728
1878
|
process.stderr.write("\n");
|
|
1729
1879
|
const pick = await choose("What next?", [
|
|
1730
1880
|
{ value: "migrate", label: "Move my keys in", hint: "keybox migrate" },
|
|
@@ -1732,7 +1882,7 @@ ${c.accent("\u25A0")} Next
|
|
|
1732
1882
|
{ value: "ui", label: "Open the dashboard", hint: "keybox ui" },
|
|
1733
1883
|
{ value: "done", label: "Done for now" }
|
|
1734
1884
|
]);
|
|
1735
|
-
if (pick === "done") return
|
|
1885
|
+
if (pick === "done") return list2();
|
|
1736
1886
|
const args = pick === "migrate" ? ["migrate"] : pick === "skill" ? ["skill", "install"] : ["ui"];
|
|
1737
1887
|
await new Promise((resolve) => {
|
|
1738
1888
|
const child = spawn4(process.execPath, [process.argv[1], ...args], { stdio: "inherit" });
|
|
@@ -2047,8 +2197,8 @@ async function tui(opts = {}) {
|
|
|
2047
2197
|
const rows = () => {
|
|
2048
2198
|
const w = out.columns ?? 80;
|
|
2049
2199
|
if (st.tab === 0) {
|
|
2050
|
-
const
|
|
2051
|
-
return
|
|
2200
|
+
const list2 = st.audit.filter((r) => st.filter === "all" || r.decision !== "allow").slice().reverse();
|
|
2201
|
+
return list2.map((r) => {
|
|
2052
2202
|
const res = r.decision === "allow" ? String(r.status) : r.decision.toUpperCase();
|
|
2053
2203
|
const col = r.decision === "allow" && r.status < 400 ? c.ok(res.padEnd(5)) : c.bad(res.padEnd(5));
|
|
2054
2204
|
const req = `${r.method} ${r.host ?? ""}${r.path ?? ""}`;
|
|
@@ -2285,10 +2435,10 @@ async function updateWorker(opts) {
|
|
|
2285
2435
|
const { deploy: deploy2 } = await Promise.resolve().then(() => (init_deploy(), deploy_exports));
|
|
2286
2436
|
const { checks: checks2, printChecks: printChecks2, resolveAccount: resolveAccount2 } = await Promise.resolve().then(() => (init_verify(), verify_exports));
|
|
2287
2437
|
await resolveAccount2(cfg);
|
|
2288
|
-
const
|
|
2289
|
-
const code =
|
|
2438
|
+
const list2 = await task("Worker", () => checks2(cfg), () => `v${deployedVersion} deployed, this CLI ships v${VERSION}`);
|
|
2439
|
+
const code = list2.find((x) => x.label === "Code");
|
|
2290
2440
|
if (code?.ok === true) {
|
|
2291
|
-
if (!
|
|
2441
|
+
if (!list2.every((x) => x.ok === true)) printChecks2(list2);
|
|
2292
2442
|
return ok(`${"Up to date".padEnd(16)}${c.dim(`Worker matches this CLI (sha256 ${shippedWorkerHash().slice(0, 16)}\u2026)`)}`);
|
|
2293
2443
|
}
|
|
2294
2444
|
if (opts.check) return note("The Worker differs from this CLI. Run `keybox update` (or `keybox deploy`) to replace it.");
|