@theholocron/cli 5.0.0-alpha.432 → 5.0.0-alpha.434
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/cli.mjs +176 -85
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +32 -1
- package/dist/index.mjs +88 -2
- package/package.json +10 -10
package/dist/cli.mjs
CHANGED
|
@@ -12288,6 +12288,26 @@ function matrixRows(matrix, manual, strict) {
|
|
|
12288
12288
|
}
|
|
12289
12289
|
return rows;
|
|
12290
12290
|
}
|
|
12291
|
+
// src/commands/doctor-secrets/matrix-summary.ts
|
|
12292
|
+
/**
|
|
12293
|
+
* The line under the table: how many names it lists and how its cells came out, in the words of the legend, so it
|
|
12294
|
+
* counts what the reader sees and not the rows below. `n/a` is not counted; `?` is shown only when a place could not be
|
|
12295
|
+
* read. Checks that failed (the rows with a ✗, for what the table does not show) are added at the end.
|
|
12296
|
+
*
|
|
12297
|
+
* @param matrix - The matrix that was printed.
|
|
12298
|
+
* @param failed - How many rows failed.
|
|
12299
|
+
*/
|
|
12300
|
+
function matrixSummary(matrix, failed) {
|
|
12301
|
+
const rows = [...matrix.secrets, ...matrix.variables];
|
|
12302
|
+
const names = new Set(rows.map((row) => row.name.toUpperCase())).size;
|
|
12303
|
+
const count = (cell) => rows.reduce((total, row) => total + Object.values(row.cells).filter((c) => c === cell).length, 0);
|
|
12304
|
+
const unread = count("?");
|
|
12305
|
+
return [
|
|
12306
|
+
`${names} ${names === 1 ? "name" : "names"}: ${count("ok")} ok, ${count("MISSING")} MISSING, ${count("extra")} extra`,
|
|
12307
|
+
...unread > 0 ? [`, ${unread} not read`] : [],
|
|
12308
|
+
...failed > 0 ? [`; ${failed} ${failed === 1 ? "check" : "checks"} failed`] : []
|
|
12309
|
+
].join("");
|
|
12310
|
+
}
|
|
12291
12311
|
// src/commands/doctor-secrets/memo-vault.ts
|
|
12292
12312
|
/**
|
|
12293
12313
|
* A vault that reads each Environment once. `doctor secrets` asks about the same Environment for several rows and for
|
|
@@ -13018,7 +13038,10 @@ async function runDoctorSecrets(input) {
|
|
|
13018
13038
|
printCheckRows(rows, print);
|
|
13019
13039
|
for (const note of notes) print(note);
|
|
13020
13040
|
const summary = summariseChecks(rows);
|
|
13021
|
-
|
|
13041
|
+
if (matrix && matrix.places.length > 0) {
|
|
13042
|
+
print("");
|
|
13043
|
+
print(style.header(matrixSummary(matrix, summary.fail)));
|
|
13044
|
+
} else printCheckSummary(summary, print);
|
|
13022
13045
|
const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
|
|
13023
13046
|
logger.info({
|
|
13024
13047
|
...summary,
|
|
@@ -19974,15 +19997,15 @@ const newCommand = {
|
|
|
19974
19997
|
* run itself prints only the result.
|
|
19975
19998
|
*/
|
|
19976
19999
|
const TOKEN_PROBE_HELP = [
|
|
19977
|
-
"Probes about a token (for example `holocron probe cloudflare token`) check
|
|
20000
|
+
"Probes about a token (for example `holocron probe cloudflare token`) check a token. The first of these that applies picks it:",
|
|
19978
20001
|
[
|
|
19979
20002
|
"- --token <provider>=<value>: that token (a bare --token <value> goes to every provider).",
|
|
19980
|
-
"- --environment <layer or name>: the provider
|
|
20003
|
+
"- --environment <layer or name>: every token the provider declares that the vault Environment holds, one after another, each under its variable name.",
|
|
19981
20004
|
"- On a terminal, with neither: a question, which asks for the configured token, an Environment or a pasted token.",
|
|
19982
20005
|
"- Otherwise: the token the provider normally resolves."
|
|
19983
20006
|
].join("\n"),
|
|
19984
20007
|
"--environment takes a layer (local, dev, ci or prod, which is this repo's `<org/repo> - <layer>`) or an Environment the config already names; anything else is refused. `local` is read over `dev`, as the CLI reads it.",
|
|
19985
|
-
"A token read from a layer is checked against what that layer's token should carry (the permission table in the tokens docs): what it should have must be there and what it should not have must not be. Any other token is only described.
|
|
20008
|
+
"A token read from a layer is checked against what that layer's token should carry (the permission table in the tokens docs): what it should have must be there and what it should not have must not be. A declared token the Environment does not hold is skipped, and fails when that layer is meant to hold it. Any other token is only described. A token is never printed."
|
|
19986
20009
|
].join("\n\n");
|
|
19987
20010
|
const probeArgs = (y) => y.positional("provider", {
|
|
19988
20011
|
type: "string",
|
|
@@ -20013,7 +20036,7 @@ const probeArgs = (y) => y.positional("provider", {
|
|
|
20013
20036
|
describe: "`1password export-environment`: put the variables on the clipboard instead of a file"
|
|
20014
20037
|
}).option("environment", {
|
|
20015
20038
|
type: "string",
|
|
20016
|
-
describe: "A probe about a token (`cloudflare token`): check the provider
|
|
20039
|
+
describe: "A probe about a token (`cloudflare token`): check every token of the provider held in this vault Environment (a layer such as `ci` or `dev`, or a name)"
|
|
20017
20040
|
}).option("yes", {
|
|
20018
20041
|
type: "boolean",
|
|
20019
20042
|
default: false,
|
|
@@ -20040,6 +20063,43 @@ function ownerEnvironments(config) {
|
|
|
20040
20063
|
instances
|
|
20041
20064
|
};
|
|
20042
20065
|
}
|
|
20066
|
+
// src/commands/token-rotation/token-rotation.ts
|
|
20067
|
+
/** The rotation policy of a token that declares none: a token is due after 90 days, and an expiry is flagged 14 days ahead. */
|
|
20068
|
+
const DEFAULT_TOKEN_ROTATION = {
|
|
20069
|
+
maxAgeDays: 90,
|
|
20070
|
+
warnDays: 14
|
|
20071
|
+
};
|
|
20072
|
+
// src/commands/token-expectations/token-expectations.ts
|
|
20073
|
+
/**
|
|
20074
|
+
* Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
|
|
20075
|
+
* order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
|
|
20076
|
+
* walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
|
|
20077
|
+
*/
|
|
20078
|
+
function tokenExpectations(tokens, filter = {}) {
|
|
20079
|
+
const found = [];
|
|
20080
|
+
for (const token of tokens) {
|
|
20081
|
+
if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
|
|
20082
|
+
const { layers = [], permissions = {} } = token.expect;
|
|
20083
|
+
for (const layer of ENVIRONMENT_LAYERS) {
|
|
20084
|
+
if (filter.layer !== void 0 && filter.layer !== layer) continue;
|
|
20085
|
+
const rules = permissions[layer];
|
|
20086
|
+
if (!rules && !layers.includes(layer)) continue;
|
|
20087
|
+
const entries = Object.entries(rules ?? {});
|
|
20088
|
+
found.push({
|
|
20089
|
+
envName: token.envName,
|
|
20090
|
+
layer,
|
|
20091
|
+
rules: rules ?? {},
|
|
20092
|
+
required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
|
|
20093
|
+
absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name),
|
|
20094
|
+
rotation: {
|
|
20095
|
+
...DEFAULT_TOKEN_ROTATION,
|
|
20096
|
+
...token.expect.rotation
|
|
20097
|
+
}
|
|
20098
|
+
});
|
|
20099
|
+
}
|
|
20100
|
+
}
|
|
20101
|
+
return found;
|
|
20102
|
+
}
|
|
20043
20103
|
// src/commands/probe/app-vault.ts
|
|
20044
20104
|
/**
|
|
20045
20105
|
* The vault of an app that carries its own `holocron.config` (`apps/comlink`, `apps/sentinel`): those configs govern where
|
|
@@ -20823,33 +20883,6 @@ function realDocsPresenceIo(repoRoot) {
|
|
|
20823
20883
|
};
|
|
20824
20884
|
/* v8 ignore stop */
|
|
20825
20885
|
}
|
|
20826
|
-
// src/commands/token-expectations/token-expectations.ts
|
|
20827
|
-
/**
|
|
20828
|
-
* Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
|
|
20829
|
-
* order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
|
|
20830
|
-
* walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
|
|
20831
|
-
*/
|
|
20832
|
-
function tokenExpectations(tokens, filter = {}) {
|
|
20833
|
-
const found = [];
|
|
20834
|
-
for (const token of tokens) {
|
|
20835
|
-
if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
|
|
20836
|
-
const { layers = [], permissions = {} } = token.expect;
|
|
20837
|
-
for (const layer of ENVIRONMENT_LAYERS) {
|
|
20838
|
-
if (filter.layer !== void 0 && filter.layer !== layer) continue;
|
|
20839
|
-
const rules = permissions[layer];
|
|
20840
|
-
if (!rules && !layers.includes(layer)) continue;
|
|
20841
|
-
const entries = Object.entries(rules ?? {});
|
|
20842
|
-
found.push({
|
|
20843
|
-
envName: token.envName,
|
|
20844
|
-
layer,
|
|
20845
|
-
rules: rules ?? {},
|
|
20846
|
-
required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
|
|
20847
|
-
absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name)
|
|
20848
|
-
});
|
|
20849
|
-
}
|
|
20850
|
-
}
|
|
20851
|
-
return found;
|
|
20852
|
-
}
|
|
20853
20886
|
// src/commands/probe/docs-tokens/compare-permissions/compare-permissions.ts
|
|
20854
20887
|
const mentions = (heading, name) => heading.toLowerCase().includes(name.toLowerCase());
|
|
20855
20888
|
/**
|
|
@@ -21763,20 +21796,21 @@ async function resolveEnvironmentId(id, input) {
|
|
|
21763
21796
|
if (!isEnvironmentLayer(id)) return id;
|
|
21764
21797
|
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
21765
21798
|
}
|
|
21766
|
-
// src/commands/probe/probe-token/environment-
|
|
21799
|
+
// src/commands/probe/probe-token/environment-tokens.ts
|
|
21767
21800
|
/**
|
|
21768
|
-
*
|
|
21801
|
+
* Every token the provider declares that one vault Environment holds, read in memory. Only an Environment this repo uses is
|
|
21769
21802
|
* read: a layer word (`local`, `dev`, `ci`, `prod`) is this repo's `<org/repo> - <layer>`, and any other text must be a
|
|
21770
21803
|
* name the config already names (`configured`), so a probe cannot be pointed at an Environment the repo has nothing to
|
|
21771
21804
|
* do with. `local` reads the way the CLI does, `- local` over `- dev`, and `- local` may be absent.
|
|
21772
21805
|
*
|
|
21773
|
-
*
|
|
21774
|
-
* `
|
|
21806
|
+
* Each token the provider's plugin lists is looked for under its own variable (`HOLOCRON_SENTRY_TOKEN`), then the
|
|
21807
|
+
* vendor's (`vendorEnvName`); the first that holds a value is that token's. A token the Environment does not hold is in
|
|
21808
|
+
* `missing`, so the caller can report it by name.
|
|
21775
21809
|
*
|
|
21776
|
-
* @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured,
|
|
21777
|
-
* Environment holds none of
|
|
21810
|
+
* @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured, the plugin
|
|
21811
|
+
* lists no token, or the Environment holds none of them.
|
|
21778
21812
|
*/
|
|
21779
|
-
async function
|
|
21813
|
+
async function environmentTokens(input) {
|
|
21780
21814
|
if (!isEnvironmentLayer(input.environment) && !input.configured.includes(input.environment)) {
|
|
21781
21815
|
const known = [...ENVIRONMENT_LAYERS, ...input.configured];
|
|
21782
21816
|
throw new Error(`${input.environment} is not an Environment this repo's config names; use one of: ${known.join(", ")}`);
|
|
@@ -21797,17 +21831,27 @@ async function environmentToken(input) {
|
|
|
21797
21831
|
...local
|
|
21798
21832
|
};
|
|
21799
21833
|
} else values = await read(environment);
|
|
21800
|
-
|
|
21801
|
-
|
|
21802
|
-
|
|
21803
|
-
|
|
21804
|
-
|
|
21805
|
-
|
|
21806
|
-
|
|
21807
|
-
variable
|
|
21808
|
-
|
|
21834
|
+
if (input.tokens.length === 0) throw new Error(`the ${input.provider} plugin lists no token to look for`);
|
|
21835
|
+
const held = [];
|
|
21836
|
+
const missing = [];
|
|
21837
|
+
for (const declared of input.tokens) {
|
|
21838
|
+
const variable = [declared.envName, ...declared.vendorEnvName ? [declared.vendorEnvName] : []].find((v) => values[v]);
|
|
21839
|
+
if (variable) held.push({
|
|
21840
|
+
token: values[variable],
|
|
21841
|
+
variable,
|
|
21842
|
+
envName: declared.envName
|
|
21843
|
+
});
|
|
21844
|
+
else missing.push(declared.envName);
|
|
21845
|
+
}
|
|
21846
|
+
if (held.length === 0) {
|
|
21847
|
+
const names = input.tokens.flatMap((t) => [t.envName, ...t.vendorEnvName ? [t.vendorEnvName] : []]);
|
|
21848
|
+
throw new Error(`${environment} holds none of ${names.join(", ")}`);
|
|
21809
21849
|
}
|
|
21810
|
-
|
|
21850
|
+
return {
|
|
21851
|
+
environment,
|
|
21852
|
+
held,
|
|
21853
|
+
missing
|
|
21854
|
+
};
|
|
21811
21855
|
}
|
|
21812
21856
|
// src/commands/probe/references/clone-org.ts
|
|
21813
21857
|
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
@@ -22039,6 +22083,10 @@ async function runProbe(input) {
|
|
|
22039
22083
|
if (clean.status === "heading") print(`\n ${style.header(clean.label)}`);
|
|
22040
22084
|
else print(statusRow(clean.status === "info" ? "skip" : clean.status, [clean.label, clean.detail ?? ""]));
|
|
22041
22085
|
};
|
|
22086
|
+
if (input.heading) emit({
|
|
22087
|
+
status: "heading",
|
|
22088
|
+
label: input.heading
|
|
22089
|
+
});
|
|
22042
22090
|
if (input.probe.writes && !input.dryRun && !input.yes) {
|
|
22043
22091
|
if (!(input.interactive ?? Boolean(process.stdin.isTTY))) throw new NonInteractiveError(`\`${input.name}\` changes things on ${input.provider} (${input.probe.summary}); pass --yes to run it without asking`);
|
|
22044
22092
|
if (!await (input.confirm ?? ((message) => confirm({
|
|
@@ -22428,63 +22476,106 @@ async function runProbeCommand(input) {
|
|
|
22428
22476
|
for (const line of listProbes(/* @__PURE__ */ new Map([[input.provider, probes]]))) print(line);
|
|
22429
22477
|
return { status: "listed" };
|
|
22430
22478
|
}
|
|
22431
|
-
|
|
22479
|
+
const probe = probes[input.probe];
|
|
22432
22480
|
if (!probe) {
|
|
22433
22481
|
print(statusRow("fail", [`\`${input.provider}\` has no probe \`${input.probe}\``, `try: ${Object.keys(probes).sort().join(", ")}`]));
|
|
22434
22482
|
return { status: "fail" };
|
|
22435
22483
|
}
|
|
22436
|
-
let context = input.context;
|
|
22437
22484
|
let layer;
|
|
22485
|
+
const steps = [{
|
|
22486
|
+
context: input.context,
|
|
22487
|
+
args: []
|
|
22488
|
+
}];
|
|
22489
|
+
const notHeld = [];
|
|
22438
22490
|
if (probe.acceptsToken) {
|
|
22439
|
-
const given = context.cliTokens?.[input.provider] ?? context.cliToken;
|
|
22491
|
+
const given = input.context.cliTokens?.[input.provider] ?? input.context.cliToken;
|
|
22440
22492
|
const chosen = input.environment ? { environment: input.environment } : given === void 0 ? await input.chooseToken?.(input.provider) : void 0;
|
|
22441
|
-
let override;
|
|
22442
22493
|
try {
|
|
22443
22494
|
if (chosen?.environment) {
|
|
22444
|
-
|
|
22495
|
+
/* v8 ignore next -- the real importer reads installed plugin packages, which tests replace with `providerTokens` */
|
|
22496
|
+
const declared = await (input.providerTokens ?? defaultProviderTokens(input.loaded))(input.provider);
|
|
22497
|
+
const found = await environmentTokens({
|
|
22445
22498
|
provider: input.provider,
|
|
22446
22499
|
environment: chosen.environment,
|
|
22447
|
-
repoRoot: context.repoRoot,
|
|
22500
|
+
repoRoot: input.context.repoRoot,
|
|
22448
22501
|
configured: ownerEnvironments(input.loaded.resolved).names,
|
|
22449
22502
|
vault: loader.has("vault") ? loader.get("vault") : void 0,
|
|
22450
|
-
|
|
22451
|
-
|
|
22452
|
-
})).token;
|
|
22503
|
+
tokens: declared
|
|
22504
|
+
});
|
|
22453
22505
|
if (isEnvironmentLayer(chosen.environment)) layer = chosen.environment;
|
|
22454
|
-
|
|
22506
|
+
steps.length = 0;
|
|
22507
|
+
for (const held of found.held) steps.push({
|
|
22508
|
+
context: {
|
|
22509
|
+
...input.context,
|
|
22510
|
+
cliTokens: {
|
|
22511
|
+
...input.context.cliTokens,
|
|
22512
|
+
[input.provider]: held.token
|
|
22513
|
+
}
|
|
22514
|
+
},
|
|
22515
|
+
heading: held.envName,
|
|
22516
|
+
args: ["--token-name", held.envName]
|
|
22517
|
+
});
|
|
22518
|
+
for (const name of found.missing) notHeld.push({
|
|
22519
|
+
name,
|
|
22520
|
+
fails: layer !== void 0 && tokenExpectations(declared, {
|
|
22521
|
+
layer,
|
|
22522
|
+
envName: name
|
|
22523
|
+
}).length > 0,
|
|
22524
|
+
environment: found.environment
|
|
22525
|
+
});
|
|
22526
|
+
} else if (chosen?.token) steps[0] = {
|
|
22527
|
+
context: {
|
|
22528
|
+
...input.context,
|
|
22529
|
+
cliTokens: {
|
|
22530
|
+
...input.context.cliTokens,
|
|
22531
|
+
[input.provider]: chosen.token
|
|
22532
|
+
}
|
|
22533
|
+
},
|
|
22534
|
+
args: []
|
|
22535
|
+
};
|
|
22455
22536
|
} catch (err) {
|
|
22456
22537
|
print(statusRow("fail", [`\`${input.provider} ${input.probe}\``, commandFailureMessage(err)]));
|
|
22457
22538
|
return { status: "fail" };
|
|
22458
22539
|
}
|
|
22459
|
-
|
|
22460
|
-
|
|
22461
|
-
|
|
22462
|
-
|
|
22463
|
-
|
|
22464
|
-
|
|
22465
|
-
|
|
22466
|
-
};
|
|
22467
|
-
const reloaded = makeLoader(context);
|
|
22540
|
+
}
|
|
22541
|
+
const out = input.print ?? (probe.reportsTo === "stderr" ? (line) => console.error(line) : print);
|
|
22542
|
+
const statuses = [];
|
|
22543
|
+
for (const step of steps) {
|
|
22544
|
+
let stepProbe = probe;
|
|
22545
|
+
if (step.context !== input.context) {
|
|
22546
|
+
const reloaded = makeLoader(step.context);
|
|
22468
22547
|
await reloaded.load();
|
|
22469
|
-
|
|
22548
|
+
stepProbe = reloaded.probes().get(input.provider)?.[input.probe] ?? probe;
|
|
22470
22549
|
}
|
|
22550
|
+
const tokens = [step.context.cliToken, ...Object.values(step.context.cliTokens ?? {})].filter((t) => typeof t === "string");
|
|
22551
|
+
const report = await runProbe({
|
|
22552
|
+
name: `${input.provider} ${input.probe}`,
|
|
22553
|
+
provider: input.provider,
|
|
22554
|
+
probeName: input.probe,
|
|
22555
|
+
args: [
|
|
22556
|
+
...input.args ?? [],
|
|
22557
|
+
...layer ? ["--layer", layer] : [],
|
|
22558
|
+
...step.args
|
|
22559
|
+
],
|
|
22560
|
+
...step.heading ? { heading: step.heading } : {},
|
|
22561
|
+
...input.lcov ? { lcov: input.lcov } : {},
|
|
22562
|
+
probe: stepProbe,
|
|
22563
|
+
dryRun: input.dryRun ?? false,
|
|
22564
|
+
yes: input.yes ?? false,
|
|
22565
|
+
secrets: tokens,
|
|
22566
|
+
print: out,
|
|
22567
|
+
...input.interactive !== void 0 ? { interactive: input.interactive } : {},
|
|
22568
|
+
...input.confirm ? { confirm: input.confirm } : {},
|
|
22569
|
+
...input.onInterrupt ? { onInterrupt: input.onInterrupt } : {}
|
|
22570
|
+
});
|
|
22571
|
+
statuses.push(report.status);
|
|
22471
22572
|
}
|
|
22472
|
-
const
|
|
22473
|
-
|
|
22474
|
-
|
|
22475
|
-
|
|
22476
|
-
|
|
22477
|
-
|
|
22478
|
-
...input.lcov ? { lcov: input.lcov } : {},
|
|
22479
|
-
probe,
|
|
22480
|
-
dryRun: input.dryRun ?? false,
|
|
22481
|
-
yes: input.yes ?? false,
|
|
22482
|
-
secrets: tokens,
|
|
22483
|
-
print: input.print ?? (probe.reportsTo === "stderr" ? (line) => console.error(line) : print),
|
|
22484
|
-
...input.interactive !== void 0 ? { interactive: input.interactive } : {},
|
|
22485
|
-
...input.confirm ? { confirm: input.confirm } : {},
|
|
22486
|
-
...input.onInterrupt ? { onInterrupt: input.onInterrupt } : {}
|
|
22487
|
-
})).status };
|
|
22573
|
+
for (const missing of notHeld) {
|
|
22574
|
+
out(`\n ${style.header(missing.name)}`);
|
|
22575
|
+
out(statusRow(missing.fails ? "fail" : "skip", [`not held in ${missing.environment}`]));
|
|
22576
|
+
if (missing.fails) statuses.push("fail");
|
|
22577
|
+
}
|
|
22578
|
+
return { status: ["fail", "cancelled"].find((s) => statuses.includes(s)) ?? "ok" };
|
|
22488
22579
|
}
|
|
22489
22580
|
// src/commands/probe/probe.command.ts
|
|
22490
22581
|
const probeCommand = {
|