@theholocron/cli 5.0.0-alpha.567 → 5.0.0-alpha.569
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 +115 -11
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +7 -1
- package/package.json +15 -15
package/dist/cli.mjs
CHANGED
|
@@ -634,7 +634,8 @@ const doctorSecretsEntry = {
|
|
|
634
634
|
"repo",
|
|
635
635
|
"only-secrets",
|
|
636
636
|
"only-variables",
|
|
637
|
-
"allow"
|
|
637
|
+
"allow",
|
|
638
|
+
"ignore-allowed"
|
|
638
639
|
],
|
|
639
640
|
supportsDryRun: false
|
|
640
641
|
};
|
|
@@ -4267,6 +4268,12 @@ var PluginLoader = class extends system.PluginLoader {
|
|
|
4267
4268
|
for (const [provider, plugin] of this.plugins()) if (plugin.revokeToken) found.set(provider, plugin.revokeToken);
|
|
4268
4269
|
return found;
|
|
4269
4270
|
}
|
|
4271
|
+
/** The `readTokenId` each loaded provider offers, by provider name. A provider that cannot say its token's id is left out. */
|
|
4272
|
+
tokenIdReaders() {
|
|
4273
|
+
const found = /* @__PURE__ */ new Map();
|
|
4274
|
+
for (const [provider, plugin] of this.plugins()) if (plugin.readTokenId) found.set(provider, plugin.readTokenId);
|
|
4275
|
+
return found;
|
|
4276
|
+
}
|
|
4270
4277
|
/**
|
|
4271
4278
|
* Loads one provider by name with the given options, whether or not `holocron.config` names it under a capability,
|
|
4272
4279
|
* and returns its `revokeToken` (`undefined` when it cannot delete one), leaving the capability registry alone.
|
|
@@ -18504,7 +18511,7 @@ const BALANCED_REPO_SETTINGS = {
|
|
|
18504
18511
|
allow_update_branch: true,
|
|
18505
18512
|
delete_branch_on_merge: true,
|
|
18506
18513
|
has_issues: true,
|
|
18507
|
-
has_discussions:
|
|
18514
|
+
has_discussions: false,
|
|
18508
18515
|
has_projects: true,
|
|
18509
18516
|
has_wiki: false
|
|
18510
18517
|
};
|
|
@@ -20118,7 +20125,9 @@ function memoVault(vault) {
|
|
|
20118
20125
|
* these maps. The result carries names, never a value or a digest.
|
|
20119
20126
|
*
|
|
20120
20127
|
* Only concealed entries are compared. An empty value is ignored. The same value under two names counts (`A = B`). A pair where either name is in `allow`
|
|
20121
|
-
* (compared without regard to case) is left out
|
|
20128
|
+
* (compared without regard to case) is left out, **except a pair that includes the `agent` layer**: its tokens are made
|
|
20129
|
+
* for agents and must never be a copy of another layer's, so a name that two other layers share on purpose is still
|
|
20130
|
+
* reported when the agent layer holds the same value (spec `tech-agent-secrets`).
|
|
20122
20131
|
*
|
|
20123
20132
|
* @param layers - The layers that were read, in `local, dev, ci, prod` order.
|
|
20124
20133
|
* @param allow - Names shared on purpose.
|
|
@@ -20139,8 +20148,9 @@ function compareLayers(layers, allow) {
|
|
|
20139
20148
|
const pairs = [];
|
|
20140
20149
|
for (let later = 1; later < layers.length; later++) for (let earlier = 0; earlier < later; earlier++) {
|
|
20141
20150
|
const names = /* @__PURE__ */ new Set();
|
|
20151
|
+
const exempt = layers[later].layer !== "agent" && layers[earlier].layer !== "agent";
|
|
20142
20152
|
for (const [digest, laterNames] of digests[later]) for (const a of laterNames) for (const b of digests[earlier].get(digest) ?? []) {
|
|
20143
|
-
if (allowed.has(a.toUpperCase()) || allowed.has(b.toUpperCase())) continue;
|
|
20153
|
+
if (exempt && (allowed.has(a.toUpperCase()) || allowed.has(b.toUpperCase()))) continue;
|
|
20144
20154
|
names.add(a.toUpperCase() === b.toUpperCase() ? a : `${a} = ${b}`);
|
|
20145
20155
|
}
|
|
20146
20156
|
pairs.push({
|
|
@@ -20282,7 +20292,12 @@ async function sharedRows(input) {
|
|
|
20282
20292
|
const read = await readLayers(vault, slug, input.layers);
|
|
20283
20293
|
rows.push(...read.rows);
|
|
20284
20294
|
const allow = [...input.loaded.resolved.doctor.sharedVariables ?? [], ...input.allow];
|
|
20285
|
-
|
|
20295
|
+
const excused = compareLayers(read.layers, allow);
|
|
20296
|
+
const pairs = input.ignoreAllowed ? compareLayers(read.layers, []).map((pair, i) => ({
|
|
20297
|
+
...pair,
|
|
20298
|
+
names: pair.names.map((name) => excused[i].names.includes(name) ? name : `${name} (allowed)`)
|
|
20299
|
+
})) : excused;
|
|
20300
|
+
for (const pair of pairs) {
|
|
20286
20301
|
compared++;
|
|
20287
20302
|
shared += pair.names.length;
|
|
20288
20303
|
const title = `${pair.layer} = ${pair.other}`;
|
|
@@ -20305,7 +20320,7 @@ async function sharedRows(input) {
|
|
|
20305
20320
|
problems: []
|
|
20306
20321
|
});
|
|
20307
20322
|
}
|
|
20308
|
-
const drift = compareVariables(read.layers, allow);
|
|
20323
|
+
const drift = compareVariables(read.layers, input.ignoreAllowed ? [] : allow);
|
|
20309
20324
|
for (const [what, names] of [["missing from dev, present in ci", drift?.missing ?? []], ["differ between ci and dev", drift?.differs ?? []]]) {
|
|
20310
20325
|
if (names.length === 0) continue;
|
|
20311
20326
|
drifted += names.length;
|
|
@@ -20786,7 +20801,8 @@ async function runDoctorSecrets(input) {
|
|
|
20786
20801
|
...input.gitExec ? { gitExec: input.gitExec } : {},
|
|
20787
20802
|
layers,
|
|
20788
20803
|
strict: input.strict === true,
|
|
20789
|
-
allow: input.allow ?? []
|
|
20804
|
+
allow: input.allow ?? [],
|
|
20805
|
+
ignoreAllowed: input.ignoreAllowed === true
|
|
20790
20806
|
});
|
|
20791
20807
|
rows.push(...shared.rows);
|
|
20792
20808
|
notes.push(shared.note);
|
|
@@ -20892,6 +20908,10 @@ const doctorSecretsCommand = {
|
|
|
20892
20908
|
type: "string",
|
|
20893
20909
|
array: true,
|
|
20894
20910
|
describe: "A name shared on purpose with --shared; repeat for more. `doctor.sharedVariables` in the config lists them too"
|
|
20911
|
+
}).option("ignore-allowed", {
|
|
20912
|
+
type: "boolean",
|
|
20913
|
+
default: false,
|
|
20914
|
+
describe: "With --shared, audit without the allow list: report every shared secret and mark the ones `doctor.sharedVariables` or --allow would excuse"
|
|
20895
20915
|
}).option("strict", {
|
|
20896
20916
|
type: "boolean",
|
|
20897
20917
|
default: false,
|
|
@@ -20919,7 +20939,8 @@ const doctorSecretsCommand = {
|
|
|
20919
20939
|
...argv.verify ? { verify: true } : {},
|
|
20920
20940
|
...argv.shared ? {
|
|
20921
20941
|
shared: true,
|
|
20922
|
-
allow: argv.allow ?? []
|
|
20942
|
+
allow: argv.allow ?? [],
|
|
20943
|
+
...argv.ignoreAllowed ? { ignoreAllowed: true } : {}
|
|
20923
20944
|
} : {},
|
|
20924
20945
|
...argv.name ? { name: argv.name } : {}
|
|
20925
20946
|
})).status === "fail") process.exitCode = 1;
|
|
@@ -37618,13 +37639,76 @@ function dueTokens(rows, layers) {
|
|
|
37618
37639
|
}
|
|
37619
37640
|
return due;
|
|
37620
37641
|
}
|
|
37642
|
+
// src/commands/token-id/read-layer-token-id.ts
|
|
37643
|
+
/**
|
|
37644
|
+
* Asks a provider's plugin for the vendor's id of the token one layer holds, the way `holocron doctor tokens` hands a
|
|
37645
|
+
* plugin that token: the layer's Environment is read in memory (`environmentTokens()`, the vault wrapped by
|
|
37646
|
+
* `memoVault()`), the loader is built again with the held token as the provider's `cliToken`, the Environment's plain
|
|
37647
|
+
* values are in `process.env` for the call only (`withEnvironmentValues()`), and the plugin's `readTokenId` answers.
|
|
37648
|
+
*
|
|
37649
|
+
* It fails closed and never guesses: an Environment that cannot be read, a layer that does not hold the token, a
|
|
37650
|
+
* provider with no `readTokenId`, an answer that is not a plain id (what `provider <name> revoke` accepts) or a
|
|
37651
|
+
* throw all come back as a `reason`. The token's value is never returned, and a reason is scrubbed of it.
|
|
37652
|
+
*
|
|
37653
|
+
* @param input - The token to look for and the seams that replace the vault and the plugins in tests.
|
|
37654
|
+
* @returns The id, or the reason it could not be read.
|
|
37655
|
+
*/
|
|
37656
|
+
async function readLayerTokenId(input) {
|
|
37657
|
+
const { provider, layer, envName } = input;
|
|
37658
|
+
let token;
|
|
37659
|
+
let plain;
|
|
37660
|
+
try {
|
|
37661
|
+
/* v8 ignore next -- the real importer reads installed plugin packages, which tests replace with `providerTokens` */
|
|
37662
|
+
const tokens = await (input.providerTokens ?? defaultProviderTokens(input.loaded))(provider);
|
|
37663
|
+
const found = await environmentTokens({
|
|
37664
|
+
provider,
|
|
37665
|
+
environment: layer,
|
|
37666
|
+
repoRoot: input.context.repoRoot,
|
|
37667
|
+
gitExec: input.gitExec,
|
|
37668
|
+
configured: ownerEnvironments(input.loaded.resolved).names,
|
|
37669
|
+
vault: input.loader.has("vault") ? memoVault(input.loader.get("vault")) : void 0,
|
|
37670
|
+
tokens
|
|
37671
|
+
});
|
|
37672
|
+
token = found.held.find((h) => h.envName === envName)?.token;
|
|
37673
|
+
plain = found.plain;
|
|
37674
|
+
} catch (err) {
|
|
37675
|
+
return { reason: `the ${layer} Environment could not be read: ${describeError(err)}` };
|
|
37676
|
+
}
|
|
37677
|
+
if (token === void 0) return { reason: `the ${layer} Environment does not hold ${envName}` };
|
|
37678
|
+
const context = {
|
|
37679
|
+
...input.context,
|
|
37680
|
+
cliTokens: {
|
|
37681
|
+
...input.context.cliTokens,
|
|
37682
|
+
[provider]: token
|
|
37683
|
+
}
|
|
37684
|
+
};
|
|
37685
|
+
/* v8 ignore start -- the real loader imports plugin packages, which tests replace with `makeLoader` */
|
|
37686
|
+
const makeLoader = input.makeLoader ?? ((c) => new PluginLoader(input.loaded.resolved, c, void 0, { extraProviders: input.extraProviders ?? [] }));
|
|
37687
|
+
/* v8 ignore stop */
|
|
37688
|
+
try {
|
|
37689
|
+
const answer = await withEnvironmentValues(plain, async () => {
|
|
37690
|
+
const reloaded = makeLoader(context);
|
|
37691
|
+
await reloaded.load();
|
|
37692
|
+
const read = reloaded.tokenIdReaders().get(provider);
|
|
37693
|
+
return read ? { id: await read() } : void 0;
|
|
37694
|
+
});
|
|
37695
|
+
if (answer === void 0) return { reason: `${provider} cannot say the id of its token` };
|
|
37696
|
+
if (answer.id === void 0) return { reason: `${provider} did not report an id for this token` };
|
|
37697
|
+
if (!TOKEN_ID.test(answer.id)) return { reason: `${provider} reported something that is not a plain token id` };
|
|
37698
|
+
return { id: answer.id };
|
|
37699
|
+
} catch (err) {
|
|
37700
|
+
return { reason: `${provider} could not read the id: ${describeError(err).split(token).join("[redacted]")}` };
|
|
37701
|
+
}
|
|
37702
|
+
}
|
|
37621
37703
|
// src/commands/rotate-tokens/rotate-tokens.ts
|
|
37622
37704
|
/**
|
|
37623
37705
|
* `holocron rotate tokens`: replace the tokens `holocron doctor tokens` reports as due (#2717, spec
|
|
37624
37706
|
* `tech-token-rotation`). It reads the same rows the doctor does, so the two cannot disagree, lists each token that is
|
|
37625
37707
|
* past its declared rotation or near its expiry, and for a provider that can make a token runs `provider <name> token`
|
|
37626
37708
|
* once per token after one question. It revokes nothing and syncs nothing: the CLI cannot write a 1Password Environment,
|
|
37627
|
-
* so it cannot know the import and the sync happened. It
|
|
37709
|
+
* so it cannot know the import and the sync happened. It reads the vendor's id of the token each layer holds now
|
|
37710
|
+
* (`readLayerTokenId()`, the plugin's `readTokenId`, handed that token the way `doctor tokens` hands it) and ends with the
|
|
37711
|
+
* order of what is left for each replaced token, naming the exact `provider <name> revoke <id>` when the id was read.
|
|
37628
37712
|
* No token value is printed, logged or returned.
|
|
37629
37713
|
*/
|
|
37630
37714
|
const row$5 = (id, title, status, detail, problems = []) => ({
|
|
@@ -37634,6 +37718,10 @@ const row$5 = (id, title, status, detail, problems = []) => ({
|
|
|
37634
37718
|
detail,
|
|
37635
37719
|
problems
|
|
37636
37720
|
});
|
|
37721
|
+
/** What the plan says about the id of the token a layer holds now. */
|
|
37722
|
+
const idNote = (found) => "id" in found ? `its id is \`${found.id}\`` : `its id could not be read (${found.reason})`;
|
|
37723
|
+
/** The last step for a replaced token: the exact revoke command when the old id was read, else where to find it. */
|
|
37724
|
+
const revokeStep = (d, found) => "id" in found ? `delete the one it replaces with \`holocron provider ${d.provider} revoke ${found.id}\`` : `delete the one it replaces with \`holocron provider ${d.provider} revoke <old-id>\`; its id could not be read (${found.reason}), so take it from ${d.provider}'s token page`;
|
|
37637
37725
|
const label = (d) => `${d.provider} ${d.envName} (${d.layer})`;
|
|
37638
37726
|
async function runRotateTokens(input) {
|
|
37639
37727
|
const print = input.print ?? ((line) => console.log(line));
|
|
@@ -37682,7 +37770,23 @@ async function runRotateTokens(input) {
|
|
|
37682
37770
|
canMint.push(mint !== void 0);
|
|
37683
37771
|
}
|
|
37684
37772
|
const replaceable = due.filter((_, i) => canMint[i]);
|
|
37685
|
-
|
|
37773
|
+
/* v8 ignore start -- the real read opens the layers' Environments and plugin packages, which tests replace with `readId` */
|
|
37774
|
+
const extras = input.readId ? [] : await workspaceProviders(input.context.repoRoot, input.loaded.resolved);
|
|
37775
|
+
const readId = input.readId ?? ((i) => readLayerTokenId({
|
|
37776
|
+
...i,
|
|
37777
|
+
extraProviders: extras
|
|
37778
|
+
}));
|
|
37779
|
+
/* v8 ignore stop */
|
|
37780
|
+
const ids = /* @__PURE__ */ new Map();
|
|
37781
|
+
for (const d of due) ids.set(d, await readId({
|
|
37782
|
+
loaded: input.loaded,
|
|
37783
|
+
context: input.context,
|
|
37784
|
+
loader,
|
|
37785
|
+
provider: d.provider,
|
|
37786
|
+
layer: d.layer,
|
|
37787
|
+
envName: d.envName
|
|
37788
|
+
}));
|
|
37789
|
+
show(due.map((d, i) => canMint[i] ? row$5(`${d.layer}:${d.provider}:${d.envName}`, label(d), "ok", `due (${d.problems.join("; ")}); will be replaced through ${d.provider}'s API`) : row$5(`${d.layer}:${d.provider}:${d.envName}`, label(d), "fail", `due (${d.problems.join("; ")})`, [`${d.provider} cannot make a token through its API: make one in its dashboard and store it with \`holocron new token ${d.provider} <token>\``, `the token it holds now: ${idNote(ids.get(d))}`])));
|
|
37686
37790
|
if (dryRun || replaceable.length === 0) return finish(dryRun ? "dry-run" : "ok");
|
|
37687
37791
|
if (!input.yes) {
|
|
37688
37792
|
if (!input.confirm) throw new NonInteractiveError("pass --yes to replace tokens without a terminal");
|
|
@@ -37708,7 +37812,7 @@ async function runRotateTokens(input) {
|
|
|
37708
37812
|
print
|
|
37709
37813
|
});
|
|
37710
37814
|
const id = `${d.layer}:${d.provider}:${d.envName}`;
|
|
37711
|
-
if (made.status === "ok") show([row$5(id, label(d), "ok", "a new token was made and handed to the private import file; the old one still works"), row$5(`next:${id}`, "next", "skip", `after the import: \`holocron sync secrets --env ${d.layer}\`, then
|
|
37815
|
+
if (made.status === "ok") show([row$5(id, label(d), "ok", "a new token was made and handed to the private import file; the old one still works"), row$5(`next:${id}`, "next", "skip", `after the import: \`holocron sync secrets --env ${d.layer}\`, then ${revokeStep(d, ids.get(d))}`)]);
|
|
37712
37816
|
else show([row$5(id, label(d), "fail", "the replacement was not made", made.rows.filter((r) => r.status === "fail").map((r) => r.detail))]);
|
|
37713
37817
|
}
|
|
37714
37818
|
return finish("ok");
|