@theholocron/cli 5.0.0-alpha.440 → 5.0.0-alpha.441
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/README.md +1 -0
- package/dist/cli.mjs +880 -638
- package/dist/cli.mjs.map +1 -1
- package/package.json +13 -13
package/dist/cli.mjs
CHANGED
|
@@ -312,6 +312,13 @@ const doctorSecretsEntry = {
|
|
|
312
312
|
],
|
|
313
313
|
supportsDryRun: false
|
|
314
314
|
};
|
|
315
|
+
// src/commands/doctor-tokens/doctor-tokens.entry.ts
|
|
316
|
+
const doctorTokensEntry = {
|
|
317
|
+
name: "doctor tokens",
|
|
318
|
+
description: "Check every token the plugins declare for a layer has the permissions it should, no more, and is not due for rotation (read-only, goes online)",
|
|
319
|
+
positionals: [],
|
|
320
|
+
supportsDryRun: false
|
|
321
|
+
};
|
|
315
322
|
// src/commands/github-app-create/github-app-create.entry.ts
|
|
316
323
|
const githubAppCreateEntry = {
|
|
317
324
|
name: "new github-app",
|
|
@@ -854,6 +861,7 @@ const registry = createCommandRegistry([
|
|
|
854
861
|
doctorDnsEntry,
|
|
855
862
|
doctorRepoEntry,
|
|
856
863
|
doctorSecretsEntry,
|
|
864
|
+
doctorTokensEntry,
|
|
857
865
|
doctorCiEntry,
|
|
858
866
|
notificationsSetupEntry,
|
|
859
867
|
notificationsCreateServerEntry,
|
|
@@ -2365,6 +2373,7 @@ const COMMAND_CONTEXTS = {
|
|
|
2365
2373
|
"doctor dns": "workspace",
|
|
2366
2374
|
"doctor repo": "workspace",
|
|
2367
2375
|
"doctor secrets": "workspace",
|
|
2376
|
+
"doctor tokens": "workspace",
|
|
2368
2377
|
"doctor monitoring": "workspace",
|
|
2369
2378
|
"doctor ci": "repo-aware",
|
|
2370
2379
|
probe: "workspace",
|
|
@@ -6823,7 +6832,7 @@ async function runDoctorDns(input) {
|
|
|
6823
6832
|
});
|
|
6824
6833
|
else if (!loader.has("dns")) {
|
|
6825
6834
|
const why = whyMissing(loader, "dns", "no `dns` provider to check them with");
|
|
6826
|
-
for (const zone of zones) rows.push(row$
|
|
6835
|
+
for (const zone of zones) rows.push(row$15(zone, "skip", why));
|
|
6827
6836
|
for (const { hostname } of domains) rows.push(domainRow(hostname, "skip", why));
|
|
6828
6837
|
} else {
|
|
6829
6838
|
const dns = loader.get("dns");
|
|
@@ -6845,7 +6854,7 @@ async function runDoctorDns(input) {
|
|
|
6845
6854
|
...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
|
|
6846
6855
|
};
|
|
6847
6856
|
}
|
|
6848
|
-
function row$
|
|
6857
|
+
function row$15(zone, status, detail, problems = []) {
|
|
6849
6858
|
return {
|
|
6850
6859
|
id: `dns-${zone}`,
|
|
6851
6860
|
title: `${zone} records exist`,
|
|
@@ -6874,7 +6883,7 @@ async function checkDomain(dns, deploy, project, hostname) {
|
|
|
6874
6883
|
return noToken !== void 0 ? domainRow(hostname, "skip", noToken) : domainRow(hostname, "fail", errorMessage(err));
|
|
6875
6884
|
}
|
|
6876
6885
|
}
|
|
6877
|
-
async function checkZone(dns, zone, wanted, rowOf = (...args) => row$
|
|
6886
|
+
async function checkZone(dns, zone, wanted, rowOf = (...args) => row$15(zone, ...args)) {
|
|
6878
6887
|
try {
|
|
6879
6888
|
const have = await dns.listRecords(zone);
|
|
6880
6889
|
const problems = declaredVsActual(new Map(wanted.map((w) => [keyOf(w), w])), new Map(have.map((h) => [keyOf(h), h])), {
|
|
@@ -7009,7 +7018,7 @@ function installationSettingsUrl(account, id) {
|
|
|
7009
7018
|
return `https://github.com/settings/installations/${id}`;
|
|
7010
7019
|
}
|
|
7011
7020
|
// src/commands/doctor-github-app/app-rows.ts
|
|
7012
|
-
const row$
|
|
7021
|
+
const row$14 = (name, what, problems, ok) => ({
|
|
7013
7022
|
id: `${name}:${what}`,
|
|
7014
7023
|
title: `${name}: ${what}`,
|
|
7015
7024
|
status: problems.length > 0 ? "fail" : "ok",
|
|
@@ -7036,9 +7045,9 @@ function appRows(name, manifest, app, installations) {
|
|
|
7036
7045
|
return [`${who} has not accepted the current App: ${gaps.join("; ")}`, `fix: ${who} accepts the update at ${url}`];
|
|
7037
7046
|
});
|
|
7038
7047
|
return [
|
|
7039
|
-
row$
|
|
7040
|
-
row$
|
|
7041
|
-
row$
|
|
7048
|
+
row$14(name, "events", eventProblems.length > 0 ? [...eventProblems, fix] : [], `all ${manifest.events.length} subscribed${extrasNote("extra event(s)", extraEvents)}`),
|
|
7049
|
+
row$14(name, "permissions", permissionProblems.length > 0 ? [...permissionProblems, fix] : [], `all ${Object.keys(manifest.permissions).length} granted${extrasNote("extra permission(s)", extraPermissions)}`),
|
|
7050
|
+
row$14(name, "installations", installationProblems, `${installations.length} installation(s) up to date`)
|
|
7042
7051
|
];
|
|
7043
7052
|
}
|
|
7044
7053
|
// src/commands/doctor-github-app/parse-manifest.ts
|
|
@@ -7096,7 +7105,7 @@ async function runDoctorGitHubApp(input) {
|
|
|
7096
7105
|
assertPluginsResolvable$1(loader, "doctor github-app");
|
|
7097
7106
|
}
|
|
7098
7107
|
const rows = [];
|
|
7099
|
-
if (instances.length === 0) rows.push(row$
|
|
7108
|
+
if (instances.length === 0) rows.push(row$13("github-app", "reachable", "skip", "no `githubApps` are declared in holocron.config.ts"));
|
|
7100
7109
|
for (const instance of instances) rows.push(...await checkInstance(instance, loader, input));
|
|
7101
7110
|
printCheckRows(rows, print);
|
|
7102
7111
|
const summary = summariseChecks(rows);
|
|
@@ -7113,7 +7122,7 @@ async function runDoctorGitHubApp(input) {
|
|
|
7113
7122
|
...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
|
|
7114
7123
|
};
|
|
7115
7124
|
}
|
|
7116
|
-
function row$
|
|
7125
|
+
function row$13(name, what, status, detail) {
|
|
7117
7126
|
return {
|
|
7118
7127
|
id: `${name}:${what}`,
|
|
7119
7128
|
title: `${name}: ${what}`,
|
|
@@ -7154,19 +7163,19 @@ async function checkInstance(instance, loader, input) {
|
|
|
7154
7163
|
try {
|
|
7155
7164
|
manifest = parseManifest(readManifest(instance.manifest));
|
|
7156
7165
|
} catch (err) {
|
|
7157
|
-
return [row$
|
|
7166
|
+
return [row$13(name, "manifest", "fail", `cannot read ${instance.manifest}: ${errorMessage(err)}`)];
|
|
7158
7167
|
}
|
|
7159
7168
|
const read = await readCredentials(instance, loader);
|
|
7160
|
-
if ("reason" in read) return [row$
|
|
7169
|
+
if ("reason" in read) return [row$13(name, "reachable", "skip", read.reason)];
|
|
7161
7170
|
const api = input.api ?? defaultApi;
|
|
7162
7171
|
const secrets = [read.creds.privateKey];
|
|
7163
7172
|
try {
|
|
7164
7173
|
const app = await api.getApp(read.creds);
|
|
7165
7174
|
const installations = await api.listAppInstallations(read.creds);
|
|
7166
7175
|
const owner = app.owner ? `, owned by ${app.owner.login}` : "";
|
|
7167
|
-
return [row$
|
|
7176
|
+
return [row$13(name, "reachable", "ok", `${app.slug}${owner}, settings: ${appSettingsUrl(app)}`), ...appRows(name, manifest, app, installations)];
|
|
7168
7177
|
} catch (err) {
|
|
7169
|
-
return [row$
|
|
7178
|
+
return [row$13(name, "reachable", "fail", `cannot call GitHub as the App: ${scrubbed$1(err, secrets)}`)];
|
|
7170
7179
|
}
|
|
7171
7180
|
}
|
|
7172
7181
|
// src/commands/doctor-github-app/doctor-github-app.command.ts
|
|
@@ -7233,7 +7242,7 @@ function datasetTargets(config) {
|
|
|
7233
7242
|
* dataset, shared by every environment in it). Only a dataset the provider says is missing, or a token it refuses, fails;
|
|
7234
7243
|
* a name, a token or a response that cannot be read is a skip with the reason.
|
|
7235
7244
|
*/
|
|
7236
|
-
const row$
|
|
7245
|
+
const row$12 = (id, title, status, detail, problems = []) => ({
|
|
7237
7246
|
id,
|
|
7238
7247
|
title,
|
|
7239
7248
|
status,
|
|
@@ -7250,7 +7259,7 @@ async function runDoctorLogs(input) {
|
|
|
7250
7259
|
if (!loader.has("logs")) {
|
|
7251
7260
|
const failure = loader.loadFailures().find((f) => f.key === "logs");
|
|
7252
7261
|
const why = failure ? `\`${failure.provider}\` failed to load: ${describeError(failure.error)}` : "no `logs` provider is configured in holocron.config.ts";
|
|
7253
|
-
rows.push(row$
|
|
7262
|
+
rows.push(row$12("logs", "logs", "skip", why));
|
|
7254
7263
|
} else rows.push(...await checkLogs(loader.get("logs"), datasetTargets(input.loaded.resolved)));
|
|
7255
7264
|
printCheckRows(rows, print);
|
|
7256
7265
|
const summary = summariseChecks(rows);
|
|
@@ -7274,38 +7283,38 @@ async function checkLogs(logs, targets) {
|
|
|
7274
7283
|
for (const target of targets) {
|
|
7275
7284
|
const id = `logs:dataset:${target.id}`;
|
|
7276
7285
|
const title = `dataset for ${target.label}`;
|
|
7277
|
-
if (!target.name) rows.push(row$
|
|
7278
|
-
else if (!token.usable) rows.push(row$
|
|
7279
|
-
else if (!logs.readDataset) rows.push(row$
|
|
7286
|
+
if (!target.name) rows.push(row$12(id, title, "skip", `${target.variable} is not set here, so there is no name to look for`));
|
|
7287
|
+
else if (!token.usable) rows.push(row$12(id, title, "skip", `${target.name}: not checked, the token is not usable`));
|
|
7288
|
+
else if (!logs.readDataset) rows.push(row$12(id, title, "skip", `${logs.providerName} cannot read a dataset`));
|
|
7280
7289
|
else rows.push(...await checkDataset(logs, target, target.name, id, title));
|
|
7281
7290
|
}
|
|
7282
7291
|
const org = resolveValue$2(["AXIOM_ORG"], void 0, { prefix: PREFIX });
|
|
7283
|
-
rows.push(org ? row$
|
|
7292
|
+
rows.push(org ? row$12("logs:org", "organization", "ok", `${PREFIX}_AXIOM_ORG (or AXIOM_ORG) is set`) : row$12("logs:org", "organization", "skip", `${PREFIX}_AXIOM_ORG (or AXIOM_ORG) is not set here; Sentinel's log links and check-dispatched need it`));
|
|
7284
7293
|
return rows;
|
|
7285
7294
|
}
|
|
7286
7295
|
/** Whether the provider accepts the token. `usable` is false when it was refused or could not be tried. */
|
|
7287
7296
|
async function checkToken$1(logs) {
|
|
7288
7297
|
const title = "token is accepted";
|
|
7289
7298
|
if (!logs.checkToken) return {
|
|
7290
|
-
row: row$
|
|
7299
|
+
row: row$12("logs:token", title, "skip", `${logs.providerName} cannot check a token`),
|
|
7291
7300
|
usable: true
|
|
7292
7301
|
};
|
|
7293
7302
|
try {
|
|
7294
7303
|
const result = await logs.checkToken();
|
|
7295
7304
|
if (result.ok) return {
|
|
7296
|
-
row: row$
|
|
7305
|
+
row: row$12("logs:token", title, "ok", `${logs.providerName} accepts the token`),
|
|
7297
7306
|
usable: true
|
|
7298
7307
|
};
|
|
7299
7308
|
const reason = result.reason ?? `${logs.providerName} refused the token`;
|
|
7300
7309
|
return {
|
|
7301
|
-
row: row$
|
|
7310
|
+
row: row$12("logs:token", title, "fail", reason, [reason]),
|
|
7302
7311
|
usable: false
|
|
7303
7312
|
};
|
|
7304
7313
|
} catch (err) {
|
|
7305
7314
|
const noToken = missingTokenReason(err);
|
|
7306
7315
|
const detail = noToken ?? `could not check the token: ${describeError(err)}`;
|
|
7307
7316
|
return {
|
|
7308
|
-
row: row$
|
|
7317
|
+
row: row$12("logs:token", title, "skip", detail),
|
|
7309
7318
|
usable: noToken === void 0
|
|
7310
7319
|
};
|
|
7311
7320
|
}
|
|
@@ -7315,13 +7324,13 @@ async function checkDataset(logs, target, name, id, title) {
|
|
|
7315
7324
|
const found = await logs.readDataset(name);
|
|
7316
7325
|
if (!found.exists) {
|
|
7317
7326
|
const problem = `dataset ${name} does not exist (${target.variable}); ${target.fix}`;
|
|
7318
|
-
return [row$
|
|
7327
|
+
return [row$12(id, title, "fail", `${name} does not exist`, [problem])];
|
|
7319
7328
|
}
|
|
7320
7329
|
const retention = found.retentionDays === void 0 ? `retention: ${logs.providerName} did not report one for ${name}` : `retention: ${found.retentionDays} days for ${name}`;
|
|
7321
|
-
return [row$
|
|
7330
|
+
return [row$12(id, title, "ok", `${name} exists`), row$12(`logs:retention:${target.id}`, `retention of ${name}`, "skip", `info: ${retention}; one setting shared by every environment in the dataset (ADR-0019)`)];
|
|
7322
7331
|
} catch (err) {
|
|
7323
7332
|
const detail = missingTokenReason(err) ?? `could not read ${name}: ${describeError(err)}`;
|
|
7324
|
-
return [row$
|
|
7333
|
+
return [row$12(id, title, "skip", detail)];
|
|
7325
7334
|
}
|
|
7326
7335
|
}
|
|
7327
7336
|
// src/commands/doctor-logs/doctor-logs.command.ts
|
|
@@ -10263,7 +10272,7 @@ const info = (id, title, noun, extras) => ({
|
|
|
10263
10272
|
detail: `info: ${extras.length} ${noun} not in the template (never deleted)`,
|
|
10264
10273
|
problems: extras
|
|
10265
10274
|
});
|
|
10266
|
-
const row$
|
|
10275
|
+
const row$11 = (id, title, problems, ok) => ({
|
|
10267
10276
|
id,
|
|
10268
10277
|
title,
|
|
10269
10278
|
status: problems.length > 0 ? "fail" : "ok",
|
|
@@ -10299,19 +10308,19 @@ function viewProblems(want, found) {
|
|
|
10299
10308
|
function boardRows(boardName, template, state) {
|
|
10300
10309
|
const id = `project:${boardName}`;
|
|
10301
10310
|
const rows = [];
|
|
10302
|
-
rows.push(row$
|
|
10311
|
+
rows.push(row$11(`${id}:statuses`, `${boardName}: statuses`, listProblems("status", "statuses", template.statuses.map((s) => s.name), state.statuses), `${template.statuses.length} in order`));
|
|
10303
10312
|
const extraStatuses = state.statuses.filter((s) => !template.statuses.some((t) => t.name === s));
|
|
10304
10313
|
if (extraStatuses.length > 0) rows.push(info(`${id}:extra-statuses`, `${boardName}: extra statuses`, "status(es)", extraStatuses));
|
|
10305
|
-
for (const want of template.fields) rows.push(row$
|
|
10314
|
+
for (const want of template.fields) rows.push(row$11(`${id}:field:${want.name}`, `${boardName}: field ${want.name}`, fieldProblems(want, state.fields.find((f) => f.name === want.name)), want.options ? `${want.options.length} options in order` : want.type));
|
|
10306
10315
|
const extraFields = state.fields.filter((f) => !template.fields.some((t) => t.name === f.name));
|
|
10307
10316
|
if (extraFields.length > 0) rows.push(info(`${id}:extra-fields`, `${boardName}: extra fields`, "field(s)", extraFields.map((f) => f.name)));
|
|
10308
|
-
for (const want of template.views) rows.push(row$
|
|
10317
|
+
for (const want of template.views) rows.push(row$11(`${id}:view:${want.name}`, `${boardName}: view ${want.name}`, viewProblems(want, state.views.find((v) => v.name === want.name)), `${want.layout}${want.filter ? `, ${want.filter}` : ""}`));
|
|
10309
10318
|
const extraViews = state.views.filter((v) => !template.views.some((t) => t.name === v.name));
|
|
10310
10319
|
if (extraViews.length > 0) rows.push(info(`${id}:extra-views`, `${boardName}: extra views`, "view(s)", extraViews.map((v) => v.name)));
|
|
10311
10320
|
for (const name of template.rules ?? []) {
|
|
10312
10321
|
const found = state.rules.find((r) => r.name === name);
|
|
10313
10322
|
const problems = !found ? [`missing rule ${name}`] : found.enabled ? [] : [`rule ${name} is off`];
|
|
10314
|
-
rows.push(row$
|
|
10323
|
+
rows.push(row$11(`${id}:rule:${name}`, `${boardName}: rule ${name}`, problems, "on"));
|
|
10315
10324
|
}
|
|
10316
10325
|
return rows;
|
|
10317
10326
|
}
|
|
@@ -10371,7 +10380,7 @@ function itemRows(boardName, items) {
|
|
|
10371
10380
|
* never fail the run. A template file that does not read is a failure naming the file. `--post [channel]` shares the
|
|
10372
10381
|
* failing rows through the `notifications` provider's bot, like `doctor notifications --post`.
|
|
10373
10382
|
*/
|
|
10374
|
-
const row$
|
|
10383
|
+
const row$10 = (id, title, status, detail, problems = []) => ({
|
|
10375
10384
|
id,
|
|
10376
10385
|
title,
|
|
10377
10386
|
status,
|
|
@@ -10425,14 +10434,14 @@ async function checkBoards(input, loader) {
|
|
|
10425
10434
|
loader,
|
|
10426
10435
|
...input.io ? { io: input.io } : {}
|
|
10427
10436
|
});
|
|
10428
|
-
if (!opened.ok) return [row$
|
|
10437
|
+
if (!opened.ok) return [row$10("project", "project", opened.kind, opened.reason, opened.problems)];
|
|
10429
10438
|
const { projects, owner, boards, templates, templateProblems } = opened.context;
|
|
10430
10439
|
const rows = templateProblems.map((problem) => {
|
|
10431
10440
|
/* v8 ignore next -- split always returns at least one element; the fallback only satisfies noUncheckedIndexedAccess */
|
|
10432
10441
|
const file = problem.split(": ")[0] ?? problem;
|
|
10433
|
-
return row$
|
|
10442
|
+
return row$10(`project:template:${file}`, `template file ${file}`, "fail", problem);
|
|
10434
10443
|
});
|
|
10435
|
-
if (boards.length === 0) return [...rows, row$
|
|
10444
|
+
if (boards.length === 0) return [...rows, row$10("project", "project", "skip", "no boards are declared in `providers.projects.boards`")];
|
|
10436
10445
|
for (const declared of boards) {
|
|
10437
10446
|
const template = templates[declared.template];
|
|
10438
10447
|
const title = `${declared.name}: board exists and is open`;
|
|
@@ -10440,18 +10449,18 @@ async function checkBoards(input, loader) {
|
|
|
10440
10449
|
const board = await projects.find(owner, declared.name);
|
|
10441
10450
|
if (!board) {
|
|
10442
10451
|
const closed = (await projects.list(owner)).some((b) => b.name === declared.name && b.closed);
|
|
10443
|
-
rows.push(row$
|
|
10452
|
+
rows.push(row$10(`project:${declared.name}`, title, "fail", closed ? "the board is closed" : "no open board has this name", [closed ? "reopen it, or run `holocron setup project` to make a new one" : "run `holocron setup project`"]));
|
|
10444
10453
|
continue;
|
|
10445
10454
|
}
|
|
10446
|
-
rows.push(row$
|
|
10455
|
+
rows.push(row$10(`project:${declared.name}`, title, "ok", board.url));
|
|
10447
10456
|
if (!template) {
|
|
10448
|
-
rows.push(row$
|
|
10457
|
+
rows.push(row$10(`project:${declared.name}:template`, `${declared.name}: template ${declared.template}`, "fail", "no built-in or file template has this name"));
|
|
10449
10458
|
continue;
|
|
10450
10459
|
}
|
|
10451
10460
|
rows.push(...boardRows(declared.name, template, await projects.read(owner, board)));
|
|
10452
|
-
rows.push(...projects.items ? itemRows(declared.name, await projects.items(owner, board, template)) : [row$
|
|
10461
|
+
rows.push(...projects.items ? itemRows(declared.name, await projects.items(owner, board, template)) : [row$10(`project:${declared.name}:items`, `${declared.name}: items`, "skip", "the provider cannot list a board's items")]);
|
|
10453
10462
|
} catch (err) {
|
|
10454
|
-
rows.push(row$
|
|
10463
|
+
rows.push(row$10(`project:${declared.name}`, title, "fail", describeError(err)));
|
|
10455
10464
|
}
|
|
10456
10465
|
}
|
|
10457
10466
|
return rows;
|
|
@@ -11125,19 +11134,19 @@ async function runDoctorRepo(input) {
|
|
|
11125
11134
|
const rows = [];
|
|
11126
11135
|
if (!loader.has("source")) {
|
|
11127
11136
|
const why = whyMissing(loader, "source", "no `source` provider to read the repository with");
|
|
11128
|
-
for (const check of checks) rows.push(row$
|
|
11137
|
+
for (const check of checks) rows.push(row$9(check, { skip: why }));
|
|
11129
11138
|
} else {
|
|
11130
11139
|
const source = loader.get("source");
|
|
11131
11140
|
for (const check of checks) {
|
|
11132
11141
|
if (typeof source[check.needs] !== "function") {
|
|
11133
|
-
rows.push(row$
|
|
11142
|
+
rows.push(row$9(check, { skip: `provider does not implement ${check.needs}` }));
|
|
11134
11143
|
continue;
|
|
11135
11144
|
}
|
|
11136
11145
|
try {
|
|
11137
|
-
rows.push(row$
|
|
11146
|
+
rows.push(row$9(check, await check.run(source)));
|
|
11138
11147
|
} catch (err) {
|
|
11139
11148
|
const noToken = missingTokenReason(err);
|
|
11140
|
-
if (noToken !== void 0) rows.push(row$
|
|
11149
|
+
if (noToken !== void 0) rows.push(row$9(check, { skip: noToken }));
|
|
11141
11150
|
else rows.push({
|
|
11142
11151
|
id: check.id,
|
|
11143
11152
|
title: check.title,
|
|
@@ -11163,7 +11172,7 @@ async function runDoctorRepo(input) {
|
|
|
11163
11172
|
...status === "skip" ? { reason: rows.map((r) => r.detail).join("; ") } : {}
|
|
11164
11173
|
};
|
|
11165
11174
|
}
|
|
11166
|
-
function row$
|
|
11175
|
+
function row$9(check, result) {
|
|
11167
11176
|
const { id, title } = check;
|
|
11168
11177
|
if ("skip" in result) return {
|
|
11169
11178
|
id,
|
|
@@ -11686,7 +11695,7 @@ function providerGroup(providerName) {
|
|
|
11686
11695
|
}
|
|
11687
11696
|
// src/commands/doctor-secrets/credentials-rows.ts
|
|
11688
11697
|
/** A row for the provider as a whole, or for one of its variables when `name` is given. */
|
|
11689
|
-
function row$
|
|
11698
|
+
function row$8(provider, status, detail, name) {
|
|
11690
11699
|
return name === void 0 ? {
|
|
11691
11700
|
id: provider,
|
|
11692
11701
|
title: provider,
|
|
@@ -11711,10 +11720,10 @@ async function credentialsRows(input) {
|
|
|
11711
11720
|
const { loader } = input;
|
|
11712
11721
|
const { resolved } = input.loaded;
|
|
11713
11722
|
if (!resolved.providers.credentials) return {
|
|
11714
|
-
rows: input.asked ? [row$
|
|
11723
|
+
rows: input.asked ? [row$8("credentials", "skip", "no `credentials` provider is configured")] : [],
|
|
11715
11724
|
places: []
|
|
11716
11725
|
};
|
|
11717
|
-
const rows = loader.loadFailures().filter((f) => f.key === "credentials").map((f) => row$
|
|
11726
|
+
const rows = loader.loadFailures().filter((f) => f.key === "credentials").map((f) => row$8(f.provider, "fail", `failed to load: ${errorMessage(f.error)}`));
|
|
11718
11727
|
const places = [];
|
|
11719
11728
|
if (!loader.has("credentials")) return {
|
|
11720
11729
|
rows,
|
|
@@ -11726,7 +11735,7 @@ async function credentialsRows(input) {
|
|
|
11726
11735
|
const tuple = tuples.find((t) => t.provider === impl.providerName);
|
|
11727
11736
|
const explicit = tuple && credentialsEnvironment(tuple, resolved);
|
|
11728
11737
|
if (!explicit && !derivesEnvironment(impl.providerName)) {
|
|
11729
|
-
rows.push(row$
|
|
11738
|
+
rows.push(row$8(impl.providerName, "skip", "no `environment` option and `credentials.environment` is not set"));
|
|
11730
11739
|
continue;
|
|
11731
11740
|
}
|
|
11732
11741
|
try {
|
|
@@ -11738,7 +11747,7 @@ async function credentialsRows(input) {
|
|
|
11738
11747
|
rows.push(...checked.rows);
|
|
11739
11748
|
places.push(...checked.places);
|
|
11740
11749
|
} catch (err) {
|
|
11741
|
-
rows.push(row$
|
|
11750
|
+
rows.push(row$8(impl.providerName, "fail", errorMessage(err)));
|
|
11742
11751
|
}
|
|
11743
11752
|
}
|
|
11744
11753
|
return {
|
|
@@ -11754,17 +11763,17 @@ async function credentialsRows(input) {
|
|
|
11754
11763
|
async function checkProvider(impl, candidates, expected, synced) {
|
|
11755
11764
|
const provider = impl.providerName;
|
|
11756
11765
|
if (!impl.inspect) return {
|
|
11757
|
-
rows: [row$
|
|
11766
|
+
rows: [row$8(provider, "skip", "cannot list the variables without reading their values")],
|
|
11758
11767
|
places: []
|
|
11759
11768
|
};
|
|
11760
11769
|
if (expected.length === 0) return {
|
|
11761
|
-
rows: [row$
|
|
11770
|
+
rows: [row$8(provider, "skip", "no configured plugin lists the tokens it takes")],
|
|
11762
11771
|
places: []
|
|
11763
11772
|
};
|
|
11764
11773
|
const inspect = impl.inspect.bind(impl);
|
|
11765
11774
|
try {
|
|
11766
11775
|
const { found, missing } = await tryEnvironments(candidates, inspect);
|
|
11767
|
-
const rows = missing.map((name) => row$
|
|
11776
|
+
const rows = missing.map((name) => row$8(provider, "fail", `${provider} has no Environment named "${name}"`));
|
|
11768
11777
|
const group = providerGroup(provider);
|
|
11769
11778
|
const unreadPlaces = missing.map((name) => ({
|
|
11770
11779
|
column: {
|
|
@@ -11787,9 +11796,9 @@ async function checkProvider(impl, candidates, expected, synced) {
|
|
|
11787
11796
|
const have = (name) => found.some((f) => f.result.names.includes(name));
|
|
11788
11797
|
let present = 0;
|
|
11789
11798
|
for (const { name, optional } of expected) if (have(name)) present++;
|
|
11790
|
-
else if (optional) rows.push(row$
|
|
11791
|
-
else rows.push(row$
|
|
11792
|
-
if (present > 0) rows.push(row$
|
|
11799
|
+
else if (optional) rows.push(row$8(provider, "skip", `optional, not set in ${where}`, name));
|
|
11800
|
+
else rows.push(row$8(provider, "fail", `missing from ${where}`, name));
|
|
11801
|
+
if (present > 0) rows.push(row$8(provider, "ok", `${present} of ${expected.length} tokens present in ${where}`, "tokens"));
|
|
11793
11802
|
const names = new Set(expected.map((e) => e.name));
|
|
11794
11803
|
const places = [];
|
|
11795
11804
|
const missingRequired = expected.filter((e) => !e.optional && !have(e.name)).map((e) => e.name);
|
|
@@ -11828,7 +11837,7 @@ async function checkProvider(impl, candidates, expected, synced) {
|
|
|
11828
11837
|
};
|
|
11829
11838
|
} catch (err) {
|
|
11830
11839
|
return {
|
|
11831
|
-
rows: [row$
|
|
11840
|
+
rows: [row$8(provider, "fail", errorMessage(err))],
|
|
11832
11841
|
places: []
|
|
11833
11842
|
};
|
|
11834
11843
|
}
|
|
@@ -12702,7 +12711,7 @@ async function variableRows(loader, config, org) {
|
|
|
12702
12711
|
if (!loader.has("source")) {
|
|
12703
12712
|
const why = whyMissing(loader, "source", "no `source` provider to read them with");
|
|
12704
12713
|
for (const check of checks) {
|
|
12705
|
-
rows.push(row$
|
|
12714
|
+
rows.push(row$7(check, { skip: why }));
|
|
12706
12715
|
observations.push({
|
|
12707
12716
|
scope: check.scope,
|
|
12708
12717
|
unread: why
|
|
@@ -12712,7 +12721,7 @@ async function variableRows(loader, config, org) {
|
|
|
12712
12721
|
const source = loader.get("source");
|
|
12713
12722
|
for (const check of checks) try {
|
|
12714
12723
|
const result = await check.run(source);
|
|
12715
|
-
rows.push(row$
|
|
12724
|
+
rows.push(row$7(check, result));
|
|
12716
12725
|
observations.push("skip" in result ? {
|
|
12717
12726
|
scope: check.scope,
|
|
12718
12727
|
unread: result.skip
|
|
@@ -12723,7 +12732,7 @@ async function variableRows(loader, config, org) {
|
|
|
12723
12732
|
} catch (err) {
|
|
12724
12733
|
const noToken = missingTokenReason(err);
|
|
12725
12734
|
if (noToken !== void 0) {
|
|
12726
|
-
rows.push(row$
|
|
12735
|
+
rows.push(row$7(check, { skip: noToken }));
|
|
12727
12736
|
observations.push({
|
|
12728
12737
|
scope: check.scope,
|
|
12729
12738
|
unread: noToken
|
|
@@ -12749,7 +12758,7 @@ async function variableRows(loader, config, org) {
|
|
|
12749
12758
|
observations
|
|
12750
12759
|
};
|
|
12751
12760
|
}
|
|
12752
|
-
function row$
|
|
12761
|
+
function row$7(check, result) {
|
|
12753
12762
|
const { id, title } = check;
|
|
12754
12763
|
if ("skip" in result) return {
|
|
12755
12764
|
id,
|
|
@@ -12839,7 +12848,7 @@ function describeExpiry(expiresAt, now) {
|
|
|
12839
12848
|
*
|
|
12840
12849
|
* What a token may do is not checked: GitHub does not return a fine-grained token's permissions.
|
|
12841
12850
|
*/
|
|
12842
|
-
function row$
|
|
12851
|
+
function row$6(id, status, detail) {
|
|
12843
12852
|
return {
|
|
12844
12853
|
id: `verify:${id}`,
|
|
12845
12854
|
title: `verify ${id}`,
|
|
@@ -12867,12 +12876,12 @@ async function verifyRows(input) {
|
|
|
12867
12876
|
try {
|
|
12868
12877
|
module = await importer(pkg);
|
|
12869
12878
|
} catch (err) {
|
|
12870
|
-
rows.push(row$
|
|
12879
|
+
rows.push(row$6(pkg, "skip", `cannot load the plugin: ${errorMessage(err)}`));
|
|
12871
12880
|
continue;
|
|
12872
12881
|
}
|
|
12873
12882
|
for (const token of module.tokens ?? []) rows.push(await checkToken(token, module, env, readToken, now()));
|
|
12874
12883
|
}
|
|
12875
|
-
if (rows.length === 0) rows.push(row$
|
|
12884
|
+
if (rows.length === 0) rows.push(row$6("tokens", "skip", "no configured plugin lists the tokens it takes"));
|
|
12876
12885
|
return rows;
|
|
12877
12886
|
}
|
|
12878
12887
|
/**
|
|
@@ -12885,30 +12894,30 @@ async function loadCredentials(input) {
|
|
|
12885
12894
|
try {
|
|
12886
12895
|
await input.loader.load();
|
|
12887
12896
|
} catch (err) {
|
|
12888
|
-
return [row$
|
|
12897
|
+
return [row$6("credentials", "skip", `could not load the credentials providers: ${errorMessage(err)}`)];
|
|
12889
12898
|
}
|
|
12890
|
-
return input.loader.loadFailures().filter((failure) => failure.key === "credentials").map((failure) => row$
|
|
12899
|
+
return input.loader.loadFailures().filter((failure) => failure.key === "credentials").map((failure) => row$6(`credentials ${failure.provider}`, "fail", `could not be read: ${errorMessage(failure.error)}`));
|
|
12891
12900
|
}
|
|
12892
12901
|
async function checkToken(token, module, env, readToken, now) {
|
|
12893
12902
|
const { keyringKey, envName, vendorEnvName } = token;
|
|
12894
12903
|
const fromEnv = env.get(envName) ? envName : vendorEnvName && env.get(vendorEnvName) ? vendorEnvName : void 0;
|
|
12895
12904
|
const stored = fromEnv ? void 0 : findCredential(...vendorEnvName ? [envName, vendorEnvName] : [envName]);
|
|
12896
12905
|
const value = fromEnv ? env.get(fromEnv) : stored?.value ?? readToken(keyringKey);
|
|
12897
|
-
if (!value) return row$
|
|
12906
|
+
if (!value) return row$6(keyringKey, "skip", `not set (${vendorEnvName ? `${envName} / ${vendorEnvName}` : envName}, or \`holocron new token ${keyringKey}\`)`);
|
|
12898
12907
|
const verify = token.verify ?? (token.verifiable === false ? void 0 : module.verifyToken);
|
|
12899
|
-
if (!verify) return row$
|
|
12908
|
+
if (!verify) return row$6(keyringKey, "skip", "set, but its plugin cannot verify it");
|
|
12900
12909
|
const from = fromEnv ?? stored?.source ?? "keyring";
|
|
12901
12910
|
try {
|
|
12902
12911
|
const verified = await verify(value);
|
|
12903
|
-
if (!verified.ok) return row$
|
|
12912
|
+
if (!verified.ok) return row$6(keyringKey, "fail", `rejected (${from}): ${verified.message}`);
|
|
12904
12913
|
const expiry = verified.expiresAt ? describeExpiry(verified.expiresAt, now) : void 0;
|
|
12905
|
-
if (!expiry) return row$
|
|
12914
|
+
if (!expiry) return row$6(keyringKey, "ok", `${verified.subject} (${from})`);
|
|
12906
12915
|
return expiry.soon ? {
|
|
12907
|
-
...row$
|
|
12916
|
+
...row$6(keyringKey, "fail", `${verified.subject} (${from}), ${expiry.text}`),
|
|
12908
12917
|
problems: [`${expiry.text}: renew it`]
|
|
12909
|
-
} : row$
|
|
12918
|
+
} : row$6(keyringKey, "ok", `${verified.subject} (${from}), ${expiry.text}`);
|
|
12910
12919
|
} catch (err) {
|
|
12911
|
-
return row$
|
|
12920
|
+
return row$6(keyringKey, "fail", `could not be verified (${from}): ${errorMessage(err)}`);
|
|
12912
12921
|
}
|
|
12913
12922
|
}
|
|
12914
12923
|
// src/commands/doctor-secrets/doctor-secrets.ts
|
|
@@ -13116,260 +13125,802 @@ function parseEnvList(values) {
|
|
|
13116
13125
|
}
|
|
13117
13126
|
return DOCTOR_ENVIRONMENTS.filter((env) => names.includes(env));
|
|
13118
13127
|
}
|
|
13119
|
-
// src/commands/
|
|
13120
|
-
|
|
13121
|
-
|
|
13122
|
-
|
|
13123
|
-
|
|
13124
|
-
|
|
13125
|
-
|
|
13126
|
-
|
|
13127
|
-
|
|
13128
|
-
|
|
13129
|
-
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
|
|
13134
|
-
|
|
13135
|
-
|
|
13136
|
-
|
|
13137
|
-
|
|
13138
|
-
|
|
13139
|
-
|
|
13140
|
-
|
|
13141
|
-
|
|
13142
|
-
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
|
|
13147
|
-
|
|
13148
|
-
|
|
13149
|
-
|
|
13150
|
-
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
}
|
|
13177
|
-
}
|
|
13178
|
-
},
|
|
13179
|
-
{
|
|
13180
|
-
name: "dns",
|
|
13181
|
-
capability: "dns",
|
|
13182
|
-
command: doctorDnsCommand,
|
|
13183
|
-
async run(input) {
|
|
13184
|
-
const report = await runDoctorDns(input);
|
|
13185
|
-
return {
|
|
13186
|
-
status: report.status,
|
|
13187
|
-
summary: report.summary,
|
|
13188
|
-
...report.reason ? { reason: report.reason } : {}
|
|
13189
|
-
};
|
|
13190
|
-
}
|
|
13191
|
-
},
|
|
13192
|
-
{
|
|
13193
|
-
name: "repo",
|
|
13194
|
-
capability: "source",
|
|
13195
|
-
command: doctorRepoCommand,
|
|
13196
|
-
async run(input) {
|
|
13197
|
-
const report = await runDoctorRepo(input);
|
|
13198
|
-
return {
|
|
13199
|
-
status: report.status,
|
|
13200
|
-
summary: report.summary,
|
|
13201
|
-
...report.reason ? { reason: report.reason } : {}
|
|
13202
|
-
};
|
|
13203
|
-
}
|
|
13204
|
-
},
|
|
13205
|
-
{
|
|
13206
|
-
name: "secrets",
|
|
13207
|
-
capability: "secrets",
|
|
13208
|
-
command: {
|
|
13209
|
-
command: "secrets",
|
|
13210
|
-
describe: "Check the secrets the config says must exist against the ones the provider holds (read-only, names only)",
|
|
13211
|
-
builder: (y) => y.option("env", {
|
|
13212
|
-
type: "string",
|
|
13213
|
-
array: true,
|
|
13214
|
-
describe: "Environments to check: local, dev, ci, test, prod; comma-separated or repeated. Default: every environment the config declares"
|
|
13215
|
-
}).option("only-secrets", {
|
|
13216
|
-
type: "boolean",
|
|
13217
|
-
conflicts: "only-variables",
|
|
13218
|
-
describe: "Show only the secrets block"
|
|
13219
|
-
}).option("only-variables", {
|
|
13220
|
-
type: "boolean",
|
|
13221
|
-
conflicts: "only-secrets",
|
|
13222
|
-
describe: "Show only the variables block"
|
|
13223
|
-
}).option("verify", {
|
|
13224
|
-
type: "boolean",
|
|
13225
|
-
default: false,
|
|
13226
|
-
describe: "Also ask each vendor whether the tokens the plugins take are still accepted (goes online)"
|
|
13227
|
-
}).option("shared", {
|
|
13228
|
-
type: "boolean",
|
|
13229
|
-
default: false,
|
|
13230
|
-
describe: "Compare the layers named by --env (two or more) for a secret that holds the same value in two of them. Values are hashed in memory and never printed"
|
|
13231
|
-
}).option("allow", {
|
|
13232
|
-
type: "string",
|
|
13233
|
-
array: true,
|
|
13234
|
-
describe: "A name shared on purpose with --shared; repeat for more. `doctor.sharedVariables` in the config lists them too"
|
|
13235
|
-
}).option("strict", {
|
|
13236
|
-
type: "boolean",
|
|
13237
|
-
default: false,
|
|
13238
|
-
describe: "Fail (exit 1) when a place holds a name nothing feeds, or with --shared a secret two layers share, instead of reporting it as info"
|
|
13239
|
-
}).option("name", {
|
|
13240
|
-
type: "string",
|
|
13241
|
-
describe: "Print how each place stands for this one name, and why. Informational: exit 0"
|
|
13242
|
-
}),
|
|
13243
|
-
handler: async (argv) => {
|
|
13244
|
-
const environments = parseEnvList(argv.env);
|
|
13245
|
-
const tokens = tokenContext$1(argv.token);
|
|
13246
|
-
if (!tokens) return;
|
|
13247
|
-
const loaded = await loadConfig(argv.cwd);
|
|
13248
|
-
applyResolvedConfig(argv, loaded.resolved);
|
|
13249
|
-
if ((await runDoctorSecrets({
|
|
13250
|
-
loaded,
|
|
13251
|
-
context: {
|
|
13252
|
-
repoRoot: argv.cwd,
|
|
13253
|
-
...tokens,
|
|
13254
|
-
org: resolveOrg(argv, loaded.resolved)
|
|
13255
|
-
},
|
|
13256
|
-
...environments ? { environments } : {},
|
|
13257
|
-
...argv.onlySecrets ? { only: "secrets" } : argv.onlyVariables ? { only: "variables" } : {},
|
|
13258
|
-
strict: argv.strict === true,
|
|
13259
|
-
...argv.verify ? { verify: true } : {},
|
|
13260
|
-
...argv.shared ? {
|
|
13261
|
-
shared: true,
|
|
13262
|
-
allow: argv.allow ?? []
|
|
13263
|
-
} : {},
|
|
13264
|
-
...argv.name ? { name: argv.name } : {}
|
|
13265
|
-
})).status === "fail") process.exitCode = 1;
|
|
13266
|
-
}
|
|
13267
|
-
},
|
|
13268
|
-
async run(input) {
|
|
13269
|
-
const report = await runDoctorSecrets(input);
|
|
13270
|
-
return {
|
|
13271
|
-
status: report.status,
|
|
13272
|
-
summary: report.summary,
|
|
13273
|
-
...report.reason ? { reason: report.reason } : {}
|
|
13274
|
-
};
|
|
13275
|
-
}
|
|
13276
|
-
},
|
|
13277
|
-
{
|
|
13278
|
-
name: "ci",
|
|
13279
|
-
capability: "source",
|
|
13280
|
-
command: doctorCiCommand,
|
|
13281
|
-
async run(input) {
|
|
13282
|
-
const report = await runDoctorCi(input);
|
|
13283
|
-
return {
|
|
13284
|
-
status: report.status,
|
|
13285
|
-
summary: report.summary
|
|
13286
|
-
};
|
|
13287
|
-
}
|
|
13288
|
-
},
|
|
13289
|
-
{
|
|
13290
|
-
name: "github-app",
|
|
13291
|
-
capability: "vault",
|
|
13292
|
-
command: doctorGitHubAppCommand,
|
|
13293
|
-
async run(input) {
|
|
13294
|
-
const report = await runDoctorGitHubApp(input);
|
|
13295
|
-
return {
|
|
13296
|
-
status: report.status,
|
|
13297
|
-
summary: report.summary,
|
|
13298
|
-
...report.reason ? { reason: report.reason } : {}
|
|
13299
|
-
};
|
|
13300
|
-
}
|
|
13301
|
-
},
|
|
13302
|
-
{
|
|
13303
|
-
name: "logs",
|
|
13304
|
-
capability: "logs",
|
|
13305
|
-
command: doctorLogsCommand,
|
|
13306
|
-
async run(input) {
|
|
13307
|
-
const report = await runDoctorLogs(input);
|
|
13308
|
-
return {
|
|
13309
|
-
status: report.status,
|
|
13310
|
-
summary: report.summary,
|
|
13311
|
-
...report.reason ? { reason: report.reason } : {}
|
|
13312
|
-
};
|
|
13313
|
-
}
|
|
13314
|
-
},
|
|
13315
|
-
{
|
|
13316
|
-
name: "project",
|
|
13317
|
-
capability: "projects",
|
|
13318
|
-
command: doctorProjectCommand,
|
|
13319
|
-
async run(input) {
|
|
13320
|
-
const report = await runDoctorProject(input);
|
|
13321
|
-
return {
|
|
13322
|
-
status: report.status,
|
|
13323
|
-
summary: report.summary,
|
|
13324
|
-
...report.reason ? { reason: report.reason } : {}
|
|
13325
|
-
};
|
|
13326
|
-
}
|
|
13128
|
+
// src/commands/doctor-secrets/doctor-secrets.command.ts
|
|
13129
|
+
const doctorSecretsCommand = {
|
|
13130
|
+
command: "secrets",
|
|
13131
|
+
describe: "Check the secrets the config says must exist against the ones the provider holds (read-only, names only)",
|
|
13132
|
+
builder: (y) => y.option("env", {
|
|
13133
|
+
type: "string",
|
|
13134
|
+
array: true,
|
|
13135
|
+
describe: "Environments to check: local, dev, ci, test, prod; comma-separated or repeated. Default: every environment the config declares"
|
|
13136
|
+
}).option("only-secrets", {
|
|
13137
|
+
type: "boolean",
|
|
13138
|
+
conflicts: "only-variables",
|
|
13139
|
+
describe: "Show only the secrets block"
|
|
13140
|
+
}).option("only-variables", {
|
|
13141
|
+
type: "boolean",
|
|
13142
|
+
conflicts: "only-secrets",
|
|
13143
|
+
describe: "Show only the variables block"
|
|
13144
|
+
}).option("verify", {
|
|
13145
|
+
type: "boolean",
|
|
13146
|
+
default: false,
|
|
13147
|
+
describe: "Also ask each vendor whether the tokens the plugins take are still accepted (goes online)"
|
|
13148
|
+
}).option("shared", {
|
|
13149
|
+
type: "boolean",
|
|
13150
|
+
default: false,
|
|
13151
|
+
describe: "Compare the layers named by --env (two or more) for a secret that holds the same value in two of them. Values are hashed in memory and never printed"
|
|
13152
|
+
}).option("allow", {
|
|
13153
|
+
type: "string",
|
|
13154
|
+
array: true,
|
|
13155
|
+
describe: "A name shared on purpose with --shared; repeat for more. `doctor.sharedVariables` in the config lists them too"
|
|
13156
|
+
}).option("strict", {
|
|
13157
|
+
type: "boolean",
|
|
13158
|
+
default: false,
|
|
13159
|
+
describe: "Fail (exit 1) when a place holds a name nothing feeds, or with --shared a secret two layers share, instead of reporting it as info"
|
|
13160
|
+
}).option("name", {
|
|
13161
|
+
type: "string",
|
|
13162
|
+
describe: "Print how each place stands for this one name, and why. Informational: exit 0"
|
|
13163
|
+
}),
|
|
13164
|
+
handler: async (argv) => {
|
|
13165
|
+
const environments = parseEnvList(argv.env);
|
|
13166
|
+
const tokens = tokenContext$1(argv.token);
|
|
13167
|
+
if (!tokens) return;
|
|
13168
|
+
const loaded = await loadConfig(argv.cwd);
|
|
13169
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
13170
|
+
if ((await runDoctorSecrets({
|
|
13171
|
+
loaded,
|
|
13172
|
+
context: {
|
|
13173
|
+
repoRoot: argv.cwd,
|
|
13174
|
+
...tokens,
|
|
13175
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
13176
|
+
},
|
|
13177
|
+
...environments ? { environments } : {},
|
|
13178
|
+
...argv.onlySecrets ? { only: "secrets" } : argv.onlyVariables ? { only: "variables" } : {},
|
|
13179
|
+
strict: argv.strict === true,
|
|
13180
|
+
...argv.verify ? { verify: true } : {},
|
|
13181
|
+
...argv.shared ? {
|
|
13182
|
+
shared: true,
|
|
13183
|
+
allow: argv.allow ?? []
|
|
13184
|
+
} : {},
|
|
13185
|
+
...argv.name ? { name: argv.name } : {}
|
|
13186
|
+
})).status === "fail") process.exitCode = 1;
|
|
13327
13187
|
}
|
|
13328
|
-
|
|
13329
|
-
// src/commands/
|
|
13188
|
+
};
|
|
13189
|
+
// src/commands/owner-environments/owner-environments.ts
|
|
13330
13190
|
/**
|
|
13331
|
-
*
|
|
13332
|
-
*
|
|
13333
|
-
* A check's own steps are not printed (they are what `holocron doctor <name>` is for); a failing row says so.
|
|
13334
|
-
* A check that cannot run because a provider or token is missing is a skip with the reason. Any other error
|
|
13335
|
-
* fails that check alone, and the rest still run. The run fails when any check failed.
|
|
13191
|
+
* The Environments the config names: each `credentials` provider's, `githubApps[].environment`, `dev.environment`
|
|
13192
|
+
* and the one of every `repo.secrets.sync` and `repo.variables.sync` entry.
|
|
13336
13193
|
*/
|
|
13337
|
-
|
|
13338
|
-
const
|
|
13339
|
-
const
|
|
13340
|
-
const
|
|
13341
|
-
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
const
|
|
13345
|
-
|
|
13346
|
-
|
|
13347
|
-
|
|
13348
|
-
...summary,
|
|
13349
|
-
status,
|
|
13350
|
-
checks: rows.map((r) => `${r.id}:${r.status}`)
|
|
13351
|
-
}, "doctor --all");
|
|
13194
|
+
function ownerEnvironments(config) {
|
|
13195
|
+
const names = /* @__PURE__ */ new Set();
|
|
13196
|
+
const entry = config.providers.credentials;
|
|
13197
|
+
for (const tuple of entry?.tuples ?? []) {
|
|
13198
|
+
const named = credentialsEnvironment(tuple, config);
|
|
13199
|
+
if (named !== void 0) names.add(named);
|
|
13200
|
+
}
|
|
13201
|
+
const instances = new Set((config.githubApps ?? []).map(resolvedEnvironment));
|
|
13202
|
+
for (const environment of instances) names.add(environment);
|
|
13203
|
+
if (config.dev?.environment) names.add(config.dev.environment);
|
|
13204
|
+
for (const sync of [...config.repo?.secrets?.sync ?? [], ...config.repo?.variables?.sync ?? []]) names.add(resolvedEnvironment(sync));
|
|
13352
13205
|
return {
|
|
13353
|
-
|
|
13354
|
-
|
|
13355
|
-
summary
|
|
13206
|
+
names: [...names],
|
|
13207
|
+
instances
|
|
13356
13208
|
};
|
|
13357
13209
|
}
|
|
13358
|
-
|
|
13359
|
-
|
|
13360
|
-
|
|
13361
|
-
|
|
13362
|
-
|
|
13363
|
-
|
|
13364
|
-
|
|
13365
|
-
|
|
13366
|
-
|
|
13367
|
-
|
|
13368
|
-
|
|
13369
|
-
|
|
13370
|
-
|
|
13371
|
-
|
|
13372
|
-
|
|
13210
|
+
// src/commands/probe/probe-token/choose-token.ts
|
|
13211
|
+
/**
|
|
13212
|
+
* Asks which token a probe that accepts one should check: the configured one, one from an Environment, or one typed in
|
|
13213
|
+
* (hidden as it is typed). Only called on a terminal when neither `--token` nor `--environment` was given.
|
|
13214
|
+
*/
|
|
13215
|
+
async function chooseToken(provider) {
|
|
13216
|
+
const how = await select({
|
|
13217
|
+
message: `Which ${provider} token should it check?`,
|
|
13218
|
+
choices: [
|
|
13219
|
+
{
|
|
13220
|
+
name: "The one this repo is configured to use",
|
|
13221
|
+
value: "configured"
|
|
13222
|
+
},
|
|
13223
|
+
{
|
|
13224
|
+
name: "One from a vault Environment (a layer such as ci or dev, or a name)",
|
|
13225
|
+
value: "environment"
|
|
13226
|
+
},
|
|
13227
|
+
{
|
|
13228
|
+
name: "Type or paste a token",
|
|
13229
|
+
value: "paste"
|
|
13230
|
+
}
|
|
13231
|
+
]
|
|
13232
|
+
});
|
|
13233
|
+
if (how === "environment") return { environment: (await input({
|
|
13234
|
+
message: "Environment (layer or name):",
|
|
13235
|
+
default: "ci"
|
|
13236
|
+
})).trim() };
|
|
13237
|
+
if (how === "paste") return { token: (await password({
|
|
13238
|
+
message: `${provider} token:`,
|
|
13239
|
+
mask: "*"
|
|
13240
|
+
})).trim() };
|
|
13241
|
+
}
|
|
13242
|
+
// src/commands/probe/probe-token/default-provider-tokens.ts
|
|
13243
|
+
/**
|
|
13244
|
+
* Reads the tokens a provider's plugin lists (its module-level `tokens`), resolving the plugin package from the
|
|
13245
|
+
* directory of the config that was loaded so a `--cwd` run finds the plugins installed there.
|
|
13246
|
+
*/
|
|
13247
|
+
function defaultProviderTokens(loaded, importer = createDefaultImporter(dirname(loaded.filepath))) {
|
|
13248
|
+
return async (provider) => (await importer(resolvePluginPackage$1(provider))).tokens ?? [];
|
|
13249
|
+
}
|
|
13250
|
+
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
13251
|
+
/**
|
|
13252
|
+
* The vault Environment `holocron sync secrets --env <environment>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
13253
|
+
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
13254
|
+
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
13255
|
+
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
13256
|
+
*
|
|
13257
|
+
* @param id - The `--env` value the user gave.
|
|
13258
|
+
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
13259
|
+
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
13260
|
+
*/
|
|
13261
|
+
async function resolveEnvironmentId(id, input) {
|
|
13262
|
+
if (!isEnvironmentLayer(id)) return id;
|
|
13263
|
+
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
13264
|
+
}
|
|
13265
|
+
// src/commands/probe/probe-token/holds-no-token-error.ts
|
|
13266
|
+
/** An Environment that holds none of the tokens a plugin lists. Its message names the variables looked for, never a value. */
|
|
13267
|
+
var HoldsNoTokenError = class extends Error {
|
|
13268
|
+
name = "HoldsNoTokenError";
|
|
13269
|
+
};
|
|
13270
|
+
// src/commands/probe/probe-token/environment-tokens.ts
|
|
13271
|
+
/**
|
|
13272
|
+
* Every token the provider declares that one vault Environment holds, read in memory. Only an Environment this repo uses is
|
|
13273
|
+
* read: a layer word (`local`, `dev`, `ci`, `prod`) is this repo's `<org/repo> - <layer>`, and any other text must be a
|
|
13274
|
+
* name the config already names (`configured`), so a probe cannot be pointed at an Environment the repo has nothing to
|
|
13275
|
+
* do with. `local` reads the way the CLI does, `- local` over `- dev`, and `- local` may be absent.
|
|
13276
|
+
*
|
|
13277
|
+
* Each token the provider's plugin lists is looked for under its own variable (`HOLOCRON_SENTRY_TOKEN`), then the
|
|
13278
|
+
* vendor's (`vendorEnvName`); the first that holds a value is that token's. A token the Environment does not hold is in
|
|
13279
|
+
* `missing`, so the caller can report it by name.
|
|
13280
|
+
*
|
|
13281
|
+
* @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured, the plugin
|
|
13282
|
+
* lists no token, or the Environment holds none of them.
|
|
13283
|
+
*/
|
|
13284
|
+
async function environmentTokens(input) {
|
|
13285
|
+
if (!isEnvironmentLayer(input.environment) && !input.configured.includes(input.environment)) {
|
|
13286
|
+
const known = [...ENVIRONMENT_LAYERS, ...input.configured];
|
|
13287
|
+
throw new Error(`${input.environment} is not an Environment this repo's config names; use one of: ${known.join(", ")}`);
|
|
13288
|
+
}
|
|
13289
|
+
const read = input.vault?.readEnvironment?.bind(input.vault);
|
|
13290
|
+
if (!read) throw new Error("--environment needs a vault provider that can read an Environment (1Password); none is configured");
|
|
13291
|
+
const at = {
|
|
13292
|
+
repoRoot: input.repoRoot,
|
|
13293
|
+
gitExec: input.gitExec
|
|
13294
|
+
};
|
|
13295
|
+
const environment = await resolveEnvironmentId(input.environment, at);
|
|
13296
|
+
let values;
|
|
13297
|
+
if (input.environment === "local") {
|
|
13298
|
+
const dev = await read(await resolveEnvironmentId("dev", at));
|
|
13299
|
+
const local = await read(environment).catch(() => ({}));
|
|
13300
|
+
values = {
|
|
13301
|
+
...dev,
|
|
13302
|
+
...local
|
|
13303
|
+
};
|
|
13304
|
+
} else values = await read(environment);
|
|
13305
|
+
if (input.tokens.length === 0) throw new Error(`the ${input.provider} plugin lists no token to look for`);
|
|
13306
|
+
const held = [];
|
|
13307
|
+
const missing = [];
|
|
13308
|
+
for (const declared of input.tokens) {
|
|
13309
|
+
const variable = [declared.envName, ...declared.vendorEnvName ? [declared.vendorEnvName] : []].find((v) => values[v]);
|
|
13310
|
+
if (variable) held.push({
|
|
13311
|
+
token: values[variable],
|
|
13312
|
+
variable,
|
|
13313
|
+
envName: declared.envName
|
|
13314
|
+
});
|
|
13315
|
+
else missing.push(declared.envName);
|
|
13316
|
+
}
|
|
13317
|
+
if (held.length === 0) throw new HoldsNoTokenError(`${environment} holds none of ${input.tokens.flatMap((t) => [t.envName, ...t.vendorEnvName ? [t.vendorEnvName] : []]).join(", ")}`);
|
|
13318
|
+
return {
|
|
13319
|
+
environment,
|
|
13320
|
+
held,
|
|
13321
|
+
missing
|
|
13322
|
+
};
|
|
13323
|
+
}
|
|
13324
|
+
// src/commands/probe/scrub.ts
|
|
13325
|
+
const HIDDEN = "«hidden»";
|
|
13326
|
+
/** Shapes that are credentials wherever they appear: a Discord webhook URL, a bearer header, a Sentry token. */
|
|
13327
|
+
const SHAPES = [
|
|
13328
|
+
/https:\/\/(?:[\w-]+\.)?discord(?:app)?\.com\/api\/webhooks\/\d+\/[\w-]+/g,
|
|
13329
|
+
/\bBearer\s+[\w.~+/=-]+/gi,
|
|
13330
|
+
/\bsntry[a-z]_[\w+/=-]+/g
|
|
13331
|
+
];
|
|
13332
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13333
|
+
/**
|
|
13334
|
+
* Returns a function that replaces secrets in a line of output: every value the caller gave (a token, a signing secret)
|
|
13335
|
+
* and every string shaped like a credential. Values shorter than 6 characters are left, since replacing `ab` would
|
|
13336
|
+
* mangle ordinary words. `secrets` may grow after this is called; it is read on each use.
|
|
13337
|
+
*/
|
|
13338
|
+
function createScrubber(secrets) {
|
|
13339
|
+
return (text) => {
|
|
13340
|
+
let out = text;
|
|
13341
|
+
const known = [...secrets].filter((s) => s.length >= 6).sort((a, b) => b.length - a.length);
|
|
13342
|
+
for (const secret of known) out = out.replace(new RegExp(escape(secret), "g"), HIDDEN);
|
|
13343
|
+
for (const shape of SHAPES) out = out.replace(shape, HIDDEN);
|
|
13344
|
+
return out;
|
|
13345
|
+
};
|
|
13346
|
+
}
|
|
13347
|
+
// src/commands/probe/run-probe.ts
|
|
13348
|
+
const defaultInterrupt = (handler) => {
|
|
13349
|
+
const listener = () => void handler().finally(() => process.exit(130));
|
|
13350
|
+
process.once("SIGINT", listener);
|
|
13351
|
+
return () => void process.off("SIGINT", listener);
|
|
13352
|
+
};
|
|
13353
|
+
/**
|
|
13354
|
+
* Runs one probe under the rules every probe shares: what it prints is scrubbed, a change goes through `write` (skipped
|
|
13355
|
+
* on `--dry-run`), a probe that writes is asked about first, and what it registered to undo runs whether it succeeded,
|
|
13356
|
+
* failed or was interrupted.
|
|
13357
|
+
*/
|
|
13358
|
+
async function runProbe(input) {
|
|
13359
|
+
const progress = createProgress(input.print ?? ((line) => console.log(line)));
|
|
13360
|
+
const print = progress.print;
|
|
13361
|
+
const secrets = new Set(input.secrets ?? []);
|
|
13362
|
+
const scrub = createScrubber(secrets);
|
|
13363
|
+
const rows = [];
|
|
13364
|
+
const emit = (row) => {
|
|
13365
|
+
const clean = {
|
|
13366
|
+
status: row.status,
|
|
13367
|
+
label: scrub(stripControl(row.label)),
|
|
13368
|
+
...row.detail ? { detail: scrub(sanitizeDetail(row.detail)) } : {}
|
|
13369
|
+
};
|
|
13370
|
+
rows.push(clean);
|
|
13371
|
+
if (clean.status === "heading") print(`\n ${style.header(clean.label)}`);
|
|
13372
|
+
else print(statusRow(clean.status === "info" ? "skip" : clean.status, [clean.label, clean.detail ?? ""]));
|
|
13373
|
+
};
|
|
13374
|
+
if (input.heading) emit({
|
|
13375
|
+
status: "heading",
|
|
13376
|
+
label: input.heading
|
|
13377
|
+
});
|
|
13378
|
+
if (input.probe.writes && !input.dryRun && !input.yes) {
|
|
13379
|
+
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`);
|
|
13380
|
+
if (!await (input.confirm ?? ((message) => confirm({
|
|
13381
|
+
message,
|
|
13382
|
+
default: false
|
|
13383
|
+
})))(`${input.name} changes things on ${input.provider}: ${input.probe.summary}. Continue?`)) {
|
|
13384
|
+
emit({
|
|
13385
|
+
status: "info",
|
|
13386
|
+
label: input.name,
|
|
13387
|
+
detail: "cancelled; nothing was changed"
|
|
13388
|
+
});
|
|
13389
|
+
return {
|
|
13390
|
+
status: "cancelled",
|
|
13391
|
+
rows
|
|
13392
|
+
};
|
|
13393
|
+
}
|
|
13394
|
+
}
|
|
13395
|
+
const undo = [];
|
|
13396
|
+
const runCleanups = async () => {
|
|
13397
|
+
while (undo.length > 0) {
|
|
13398
|
+
const { label, fn } = undo.pop();
|
|
13399
|
+
try {
|
|
13400
|
+
await fn();
|
|
13401
|
+
emit({
|
|
13402
|
+
status: "info",
|
|
13403
|
+
label: `cleaned up ${label}`
|
|
13404
|
+
});
|
|
13405
|
+
} catch (err) {
|
|
13406
|
+
emit({
|
|
13407
|
+
status: "fail",
|
|
13408
|
+
label: `could not clean up ${label}`,
|
|
13409
|
+
detail: commandFailureMessage(err)
|
|
13410
|
+
});
|
|
13411
|
+
}
|
|
13412
|
+
}
|
|
13413
|
+
};
|
|
13414
|
+
const ctx = {
|
|
13415
|
+
dryRun: input.dryRun,
|
|
13416
|
+
args: input.args ?? [],
|
|
13417
|
+
...input.lcov ? { lcov: input.lcov } : {},
|
|
13418
|
+
say: emit,
|
|
13419
|
+
secret: (value) => {
|
|
13420
|
+
if (value) secrets.add(value);
|
|
13421
|
+
},
|
|
13422
|
+
async write(label, fn) {
|
|
13423
|
+
if (!input.probe.writes) throw new Error(`${input.name} is read-only and cannot ${label}`);
|
|
13424
|
+
if (input.dryRun) {
|
|
13425
|
+
emit({
|
|
13426
|
+
status: "info",
|
|
13427
|
+
label: `would ${label}`
|
|
13428
|
+
});
|
|
13429
|
+
return;
|
|
13430
|
+
}
|
|
13431
|
+
return fn();
|
|
13432
|
+
},
|
|
13433
|
+
cleanup(label, fn) {
|
|
13434
|
+
if (!input.dryRun) undo.push({
|
|
13435
|
+
label,
|
|
13436
|
+
fn
|
|
13437
|
+
});
|
|
13438
|
+
}
|
|
13439
|
+
};
|
|
13440
|
+
const stopListening = (input.onInterrupt ?? defaultInterrupt)(runCleanups);
|
|
13441
|
+
try {
|
|
13442
|
+
await progress.run(`${input.name}…`, () => input.probe.run(ctx));
|
|
13443
|
+
} catch (err) {
|
|
13444
|
+
emit({
|
|
13445
|
+
status: "fail",
|
|
13446
|
+
label: input.name,
|
|
13447
|
+
detail: commandFailureMessage(err)
|
|
13448
|
+
});
|
|
13449
|
+
} finally {
|
|
13450
|
+
stopListening();
|
|
13451
|
+
await runCleanups();
|
|
13452
|
+
}
|
|
13453
|
+
const counts = {
|
|
13454
|
+
ok: rows.filter((r) => r.status === "ok").length,
|
|
13455
|
+
fail: rows.filter((r) => r.status === "fail").length
|
|
13456
|
+
};
|
|
13457
|
+
if (counts.ok + counts.fail > 0) print(`\n${counts.ok} ok, ${counts.fail} fail`);
|
|
13458
|
+
return {
|
|
13459
|
+
status: counts.fail > 0 ? "fail" : "ok",
|
|
13460
|
+
rows
|
|
13461
|
+
};
|
|
13462
|
+
}
|
|
13463
|
+
// src/commands/token-rotation/token-rotation.ts
|
|
13464
|
+
/** The rotation policy of a token that declares none: a token is due after 90 days, and an expiry is flagged 14 days ahead. */
|
|
13465
|
+
const DEFAULT_TOKEN_ROTATION = {
|
|
13466
|
+
maxAgeDays: 90,
|
|
13467
|
+
warnDays: 14
|
|
13468
|
+
};
|
|
13469
|
+
// src/commands/token-expectations/token-expectations.ts
|
|
13470
|
+
/**
|
|
13471
|
+
* Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
|
|
13472
|
+
* order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
|
|
13473
|
+
* walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
|
|
13474
|
+
*/
|
|
13475
|
+
function tokenExpectations(tokens, filter = {}) {
|
|
13476
|
+
const found = [];
|
|
13477
|
+
for (const token of tokens) {
|
|
13478
|
+
if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
|
|
13479
|
+
const { layers = [], permissions = {} } = token.expect;
|
|
13480
|
+
for (const layer of ENVIRONMENT_LAYERS) {
|
|
13481
|
+
if (filter.layer !== void 0 && filter.layer !== layer) continue;
|
|
13482
|
+
const rules = permissions[layer];
|
|
13483
|
+
if (!rules && !layers.includes(layer)) continue;
|
|
13484
|
+
const entries = Object.entries(rules ?? {});
|
|
13485
|
+
found.push({
|
|
13486
|
+
envName: token.envName,
|
|
13487
|
+
layer,
|
|
13488
|
+
rules: rules ?? {},
|
|
13489
|
+
required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
|
|
13490
|
+
absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name),
|
|
13491
|
+
rotation: {
|
|
13492
|
+
...DEFAULT_TOKEN_ROTATION,
|
|
13493
|
+
...token.expect.rotation
|
|
13494
|
+
}
|
|
13495
|
+
});
|
|
13496
|
+
}
|
|
13497
|
+
}
|
|
13498
|
+
return found;
|
|
13499
|
+
}
|
|
13500
|
+
// src/commands/doctor-tokens/summarise-probe-rows.ts
|
|
13501
|
+
/**
|
|
13502
|
+
* Folds what one token probe reported into the one row the doctor shows for that token in that layer. A failing probe row
|
|
13503
|
+
* (a permission it must not have, one it lacks, a token past its age or near expiry, a probe that threw) fails the row and
|
|
13504
|
+
* is listed as a problem; `info` rows are counted and never fail. The probe's rows are already scrubbed by `runProbe`.
|
|
13505
|
+
*
|
|
13506
|
+
* @param id - The row id.
|
|
13507
|
+
* @param title - The row title.
|
|
13508
|
+
* @param rows - The rows the probe reported, headings included.
|
|
13509
|
+
*/
|
|
13510
|
+
function summariseProbeRows(id, title, rows) {
|
|
13511
|
+
const checks = rows.filter((r) => r.status !== "heading");
|
|
13512
|
+
const failed = checks.filter((r) => r.status === "fail");
|
|
13513
|
+
const passed = checks.filter((r) => r.status === "ok");
|
|
13514
|
+
const noted = checks.filter((r) => r.status === "info");
|
|
13515
|
+
if (failed.length > 0) return {
|
|
13516
|
+
id,
|
|
13517
|
+
title,
|
|
13518
|
+
status: "fail",
|
|
13519
|
+
detail: `${failed.length} of ${passed.length + failed.length} checks failed`,
|
|
13520
|
+
problems: failed.map((r) => r.detail ? `${r.label}: ${r.detail}` : r.label)
|
|
13521
|
+
};
|
|
13522
|
+
if (passed.length === 0) return {
|
|
13523
|
+
id,
|
|
13524
|
+
title,
|
|
13525
|
+
status: "skip",
|
|
13526
|
+
detail: "the probe reported no check to compare",
|
|
13527
|
+
problems: []
|
|
13528
|
+
};
|
|
13529
|
+
const note = noted.length > 0 ? `, ${noted.length} noted` : "";
|
|
13530
|
+
return {
|
|
13531
|
+
id,
|
|
13532
|
+
title,
|
|
13533
|
+
status: "ok",
|
|
13534
|
+
detail: `${passed.length} ${passed.length === 1 ? "check" : "checks"} passed${note}`,
|
|
13535
|
+
problems: []
|
|
13536
|
+
};
|
|
13537
|
+
}
|
|
13538
|
+
// src/commands/doctor-tokens/doctor-tokens.ts
|
|
13539
|
+
/**
|
|
13540
|
+
* `holocron doctor tokens` — does every token a plugin declares for a layer carry the permissions the declaration says,
|
|
13541
|
+
* and is it still fresh?
|
|
13542
|
+
*
|
|
13543
|
+
* For each layer (`local`, `dev`, `ci`, `prod`) and each token a configured plugin declares for it
|
|
13544
|
+
* (`PluginToken.expect`, read by `tokenExpectations()`), it reads that layer's Environment in memory and runs the
|
|
13545
|
+
* provider's `token` probe against the token it holds there, the same flow as `probe <provider> token --environment <layer>`
|
|
13546
|
+
* (`environmentTokens()`, `runProbe()`). One row per token per layer: it fails for a permission the token must not have,
|
|
13547
|
+
* one it lacks, a token the layer should hold and does not, or a token past its rotation age or near its expiry.
|
|
13548
|
+
*
|
|
13549
|
+
* Read-only. It prints names, counts and dates, never a token: the probes' output is scrubbed of every token in use. A
|
|
13550
|
+
* provider with no `token` probe, no declared layer, or one that cannot be read is a skip with the reason.
|
|
13551
|
+
*/
|
|
13552
|
+
const PROBE = "token";
|
|
13553
|
+
const row$5 = (id, title, status, detail, problems = []) => ({
|
|
13554
|
+
id,
|
|
13555
|
+
title,
|
|
13556
|
+
status,
|
|
13557
|
+
detail,
|
|
13558
|
+
problems
|
|
13559
|
+
});
|
|
13560
|
+
async function runDoctorTokens(input) {
|
|
13561
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
13562
|
+
const logger = input.logger ?? getLogger();
|
|
13563
|
+
const makeLoader = input.makeLoader ?? ((context) => new PluginLoader(input.loaded.resolved, context));
|
|
13564
|
+
const loader = input.loader ?? makeLoader(input.context);
|
|
13565
|
+
await loader.load();
|
|
13566
|
+
assertPluginsResolvable$1(loader, "doctor tokens");
|
|
13567
|
+
const rows = [];
|
|
13568
|
+
const probes = loader.probes();
|
|
13569
|
+
const declared = [];
|
|
13570
|
+
/* v8 ignore next -- the real importer reads installed plugin packages, which tests replace with `providerTokens` */
|
|
13571
|
+
const providerTokens = input.providerTokens ?? defaultProviderTokens(input.loaded);
|
|
13572
|
+
for (const provider of providersOf(input.loaded.resolved.providers)) {
|
|
13573
|
+
let tokens;
|
|
13574
|
+
try {
|
|
13575
|
+
tokens = await providerTokens(provider);
|
|
13576
|
+
} catch (err) {
|
|
13577
|
+
rows.push(row$5(`tokens:${provider}`, provider, "skip", `could not read its tokens: ${describeError(err)}`));
|
|
13578
|
+
continue;
|
|
13579
|
+
}
|
|
13580
|
+
const expectations = tokenExpectations(tokens);
|
|
13581
|
+
if (expectations.length === 0) rows.push(row$5(`tokens:${provider}`, provider, "skip", "info: declares no token layers, nothing to check"));
|
|
13582
|
+
else if (!usableProbe(probes.get(provider))) rows.push(row$5(`tokens:${provider}`, provider, "skip", `info: has no \`${PROBE}\` probe loaded, so its tokens are not checked`));
|
|
13583
|
+
else declared.push({
|
|
13584
|
+
provider,
|
|
13585
|
+
tokens,
|
|
13586
|
+
expectations
|
|
13587
|
+
});
|
|
13588
|
+
}
|
|
13589
|
+
if (declared.length > 0) {
|
|
13590
|
+
const vault = loader.has("vault") ? memoVault(loader.get("vault")) : void 0;
|
|
13591
|
+
for (const layer of ENVIRONMENT_LAYERS) for (const entry of declared) {
|
|
13592
|
+
const wanted = entry.expectations.filter((e) => e.layer === layer);
|
|
13593
|
+
if (wanted.length === 0) continue;
|
|
13594
|
+
rows.push(...await checkLayer({
|
|
13595
|
+
input,
|
|
13596
|
+
makeLoader,
|
|
13597
|
+
probes,
|
|
13598
|
+
vault,
|
|
13599
|
+
entry,
|
|
13600
|
+
layer,
|
|
13601
|
+
wanted
|
|
13602
|
+
}));
|
|
13603
|
+
}
|
|
13604
|
+
}
|
|
13605
|
+
printCheckRows(rows, print);
|
|
13606
|
+
const summary = summariseChecks(rows);
|
|
13607
|
+
printCheckSummary(summary, print);
|
|
13608
|
+
const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
|
|
13609
|
+
logger.info({
|
|
13610
|
+
...summary,
|
|
13611
|
+
status
|
|
13612
|
+
}, "doctor tokens");
|
|
13613
|
+
return {
|
|
13614
|
+
status,
|
|
13615
|
+
rows,
|
|
13616
|
+
summary,
|
|
13617
|
+
...status === "skip" ? { reason: rows.map((r) => r.detail).join("; ") || "no plugin declares a token layer" } : {}
|
|
13618
|
+
};
|
|
13619
|
+
}
|
|
13620
|
+
/** The provider names the config lists, once each. */
|
|
13621
|
+
function providersOf(providers) {
|
|
13622
|
+
const names = Object.values(providers).flatMap((entry) => entry.cardinality === "single" ? [entry.tuple.provider] : entry.tuples.map((t) => t.provider));
|
|
13623
|
+
return [...new Set(names)];
|
|
13624
|
+
}
|
|
13625
|
+
const usableProbe = (probes) => probes?.[PROBE]?.acceptsToken === true;
|
|
13626
|
+
const rowId = (layer, provider, envName) => `tokens:${layer}:${provider}:${envName}`;
|
|
13627
|
+
const rowTitle = (layer, provider, envName) => `${layer}: ${envName} (${provider})`;
|
|
13628
|
+
/** One row per token the provider declares for the layer: read the layer's Environment, then probe each token it holds. */
|
|
13629
|
+
async function checkLayer(c) {
|
|
13630
|
+
const { provider, tokens } = c.entry;
|
|
13631
|
+
const id = (e) => rowId(c.layer, provider, e.envName);
|
|
13632
|
+
const title = (e) => rowTitle(c.layer, provider, e.envName);
|
|
13633
|
+
let held;
|
|
13634
|
+
try {
|
|
13635
|
+
held = await environmentTokens({
|
|
13636
|
+
provider,
|
|
13637
|
+
environment: c.layer,
|
|
13638
|
+
repoRoot: c.input.context.repoRoot,
|
|
13639
|
+
gitExec: c.input.gitExec,
|
|
13640
|
+
configured: ownerEnvironments(c.input.loaded.resolved).names,
|
|
13641
|
+
vault: c.vault,
|
|
13642
|
+
tokens
|
|
13643
|
+
});
|
|
13644
|
+
} catch (err) {
|
|
13645
|
+
if (err instanceof HoldsNoTokenError) return c.wanted.map((e) => row$5(id(e), title(e), "fail", "not held in this layer", [err.message]));
|
|
13646
|
+
return c.wanted.map((e) => row$5(id(e), title(e), "skip", `could not read the Environment: ${describeError(err)}`));
|
|
13647
|
+
}
|
|
13648
|
+
const rows = [];
|
|
13649
|
+
for (const e of c.wanted) {
|
|
13650
|
+
const token = held.held.find((h) => h.envName === e.envName);
|
|
13651
|
+
if (!token) {
|
|
13652
|
+
rows.push(row$5(id(e), title(e), "fail", `not held in ${held.environment}`, [`${e.envName} is declared for ${c.layer}`]));
|
|
13653
|
+
continue;
|
|
13654
|
+
}
|
|
13655
|
+
rows.push(summariseProbeRows(id(e), title(e), await probeToken(c, e, token.token)));
|
|
13656
|
+
}
|
|
13657
|
+
return rows;
|
|
13658
|
+
}
|
|
13659
|
+
/** Runs the provider's token probe against one token, as `probe <provider> token --environment <layer>` does. */
|
|
13660
|
+
async function probeToken(c, e, token) {
|
|
13661
|
+
const provider = c.entry.provider;
|
|
13662
|
+
const context = {
|
|
13663
|
+
...c.input.context,
|
|
13664
|
+
cliTokens: {
|
|
13665
|
+
...c.input.context.cliTokens,
|
|
13666
|
+
[provider]: token
|
|
13667
|
+
}
|
|
13668
|
+
};
|
|
13669
|
+
try {
|
|
13670
|
+
const reloaded = c.makeLoader(context);
|
|
13671
|
+
await reloaded.load();
|
|
13672
|
+
const probe = reloaded.probes().get(provider)?.[PROBE] ?? c.probes.get(provider)[PROBE];
|
|
13673
|
+
return (await runProbe({
|
|
13674
|
+
name: `${provider} ${PROBE}`,
|
|
13675
|
+
provider,
|
|
13676
|
+
probeName: PROBE,
|
|
13677
|
+
args: [
|
|
13678
|
+
"--layer",
|
|
13679
|
+
c.layer,
|
|
13680
|
+
"--token-name",
|
|
13681
|
+
e.envName
|
|
13682
|
+
],
|
|
13683
|
+
probe,
|
|
13684
|
+
dryRun: false,
|
|
13685
|
+
yes: false,
|
|
13686
|
+
interactive: false,
|
|
13687
|
+
secrets: [token, ...Object.values(context.cliTokens)],
|
|
13688
|
+
print: () => {},
|
|
13689
|
+
onInterrupt: () => () => {}
|
|
13690
|
+
})).rows;
|
|
13691
|
+
} catch (err) {
|
|
13692
|
+
return [{
|
|
13693
|
+
status: "fail",
|
|
13694
|
+
label: `${provider} ${PROBE}`,
|
|
13695
|
+
detail: describeError(err).split(token).join("[redacted]")
|
|
13696
|
+
}];
|
|
13697
|
+
}
|
|
13698
|
+
}
|
|
13699
|
+
// src/commands/deep-checks/deep-checks.ts
|
|
13700
|
+
/**
|
|
13701
|
+
* Every `doctor <capability>` deep check, in the order `doctor --all` runs them. Adding one is an entry here
|
|
13702
|
+
* plus its `COMMAND_CONTEXTS` and `COMMAND_REGISTRY` entries; `deep-checks.test.ts` fails without them.
|
|
13703
|
+
*/
|
|
13704
|
+
const DEEP_CHECKS = [
|
|
13705
|
+
{
|
|
13706
|
+
name: "notifications",
|
|
13707
|
+
capability: "notifications",
|
|
13708
|
+
command: doctorNotificationsCommand,
|
|
13709
|
+
async run(input) {
|
|
13710
|
+
const report = await runDoctorNotifications({
|
|
13711
|
+
...input,
|
|
13712
|
+
builtOnly: true
|
|
13713
|
+
});
|
|
13714
|
+
if (report.message) return {
|
|
13715
|
+
status: "skip",
|
|
13716
|
+
summary: {
|
|
13717
|
+
ok: 0,
|
|
13718
|
+
fail: 0,
|
|
13719
|
+
skip: 1
|
|
13720
|
+
},
|
|
13721
|
+
reason: report.message
|
|
13722
|
+
};
|
|
13723
|
+
return {
|
|
13724
|
+
status: report.status,
|
|
13725
|
+
summary: {
|
|
13726
|
+
ok: report.summary.pass,
|
|
13727
|
+
fail: report.summary.fail,
|
|
13728
|
+
skip: report.summary.skip
|
|
13729
|
+
}
|
|
13730
|
+
};
|
|
13731
|
+
}
|
|
13732
|
+
},
|
|
13733
|
+
{
|
|
13734
|
+
name: "environments",
|
|
13735
|
+
capability: "environments",
|
|
13736
|
+
command: doctorEnvironmentsCommand,
|
|
13737
|
+
async run(input) {
|
|
13738
|
+
const report = await runDoctorEnvironments(input);
|
|
13739
|
+
return {
|
|
13740
|
+
status: report.status,
|
|
13741
|
+
summary: report.summary,
|
|
13742
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13743
|
+
};
|
|
13744
|
+
}
|
|
13745
|
+
},
|
|
13746
|
+
{
|
|
13747
|
+
name: "monitoring",
|
|
13748
|
+
capability: "monitoring",
|
|
13749
|
+
command: doctorMonitoringCommand,
|
|
13750
|
+
async run(input) {
|
|
13751
|
+
const report = await runDoctorMonitoring(input);
|
|
13752
|
+
return {
|
|
13753
|
+
status: report.status,
|
|
13754
|
+
summary: report.summary,
|
|
13755
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13756
|
+
};
|
|
13757
|
+
}
|
|
13758
|
+
},
|
|
13759
|
+
{
|
|
13760
|
+
name: "dns",
|
|
13761
|
+
capability: "dns",
|
|
13762
|
+
command: doctorDnsCommand,
|
|
13763
|
+
async run(input) {
|
|
13764
|
+
const report = await runDoctorDns(input);
|
|
13765
|
+
return {
|
|
13766
|
+
status: report.status,
|
|
13767
|
+
summary: report.summary,
|
|
13768
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13769
|
+
};
|
|
13770
|
+
}
|
|
13771
|
+
},
|
|
13772
|
+
{
|
|
13773
|
+
name: "repo",
|
|
13774
|
+
capability: "source",
|
|
13775
|
+
command: doctorRepoCommand,
|
|
13776
|
+
async run(input) {
|
|
13777
|
+
const report = await runDoctorRepo(input);
|
|
13778
|
+
return {
|
|
13779
|
+
status: report.status,
|
|
13780
|
+
summary: report.summary,
|
|
13781
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13782
|
+
};
|
|
13783
|
+
}
|
|
13784
|
+
},
|
|
13785
|
+
{
|
|
13786
|
+
name: "secrets",
|
|
13787
|
+
capability: "secrets",
|
|
13788
|
+
command: doctorSecretsCommand,
|
|
13789
|
+
async run(input) {
|
|
13790
|
+
const report = await runDoctorSecrets(input);
|
|
13791
|
+
return {
|
|
13792
|
+
status: report.status,
|
|
13793
|
+
summary: report.summary,
|
|
13794
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13795
|
+
};
|
|
13796
|
+
}
|
|
13797
|
+
},
|
|
13798
|
+
{
|
|
13799
|
+
name: "tokens",
|
|
13800
|
+
capability: "vault",
|
|
13801
|
+
command: {
|
|
13802
|
+
command: "tokens",
|
|
13803
|
+
describe: "Check every token the plugins declare for a layer has the permissions it should, no more, and is not due for rotation (read-only, goes online)",
|
|
13804
|
+
handler: async (argv) => {
|
|
13805
|
+
const tokens = tokenContext$1(argv.token);
|
|
13806
|
+
if (!tokens) return;
|
|
13807
|
+
const loaded = await loadConfig(argv.cwd);
|
|
13808
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
13809
|
+
if ((await runDoctorTokens({
|
|
13810
|
+
loaded,
|
|
13811
|
+
context: {
|
|
13812
|
+
repoRoot: argv.cwd,
|
|
13813
|
+
...tokens,
|
|
13814
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
13815
|
+
}
|
|
13816
|
+
})).status === "fail") process.exitCode = 1;
|
|
13817
|
+
}
|
|
13818
|
+
},
|
|
13819
|
+
async run(input) {
|
|
13820
|
+
const report = await runDoctorTokens(input);
|
|
13821
|
+
return {
|
|
13822
|
+
status: report.status,
|
|
13823
|
+
summary: report.summary,
|
|
13824
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13825
|
+
};
|
|
13826
|
+
}
|
|
13827
|
+
},
|
|
13828
|
+
{
|
|
13829
|
+
name: "ci",
|
|
13830
|
+
capability: "source",
|
|
13831
|
+
command: doctorCiCommand,
|
|
13832
|
+
async run(input) {
|
|
13833
|
+
const report = await runDoctorCi(input);
|
|
13834
|
+
return {
|
|
13835
|
+
status: report.status,
|
|
13836
|
+
summary: report.summary
|
|
13837
|
+
};
|
|
13838
|
+
}
|
|
13839
|
+
},
|
|
13840
|
+
{
|
|
13841
|
+
name: "github-app",
|
|
13842
|
+
capability: "vault",
|
|
13843
|
+
command: doctorGitHubAppCommand,
|
|
13844
|
+
async run(input) {
|
|
13845
|
+
const report = await runDoctorGitHubApp(input);
|
|
13846
|
+
return {
|
|
13847
|
+
status: report.status,
|
|
13848
|
+
summary: report.summary,
|
|
13849
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13850
|
+
};
|
|
13851
|
+
}
|
|
13852
|
+
},
|
|
13853
|
+
{
|
|
13854
|
+
name: "logs",
|
|
13855
|
+
capability: "logs",
|
|
13856
|
+
command: doctorLogsCommand,
|
|
13857
|
+
async run(input) {
|
|
13858
|
+
const report = await runDoctorLogs(input);
|
|
13859
|
+
return {
|
|
13860
|
+
status: report.status,
|
|
13861
|
+
summary: report.summary,
|
|
13862
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13863
|
+
};
|
|
13864
|
+
}
|
|
13865
|
+
},
|
|
13866
|
+
{
|
|
13867
|
+
name: "project",
|
|
13868
|
+
capability: "projects",
|
|
13869
|
+
command: doctorProjectCommand,
|
|
13870
|
+
async run(input) {
|
|
13871
|
+
const report = await runDoctorProject(input);
|
|
13872
|
+
return {
|
|
13873
|
+
status: report.status,
|
|
13874
|
+
summary: report.summary,
|
|
13875
|
+
...report.reason ? { reason: report.reason } : {}
|
|
13876
|
+
};
|
|
13877
|
+
}
|
|
13878
|
+
}
|
|
13879
|
+
];
|
|
13880
|
+
// src/commands/doctor-all/doctor-all.ts
|
|
13881
|
+
/**
|
|
13882
|
+
* `holocron doctor --all` — run every deep check and print one row for each.
|
|
13883
|
+
*
|
|
13884
|
+
* A check's own steps are not printed (they are what `holocron doctor <name>` is for); a failing row says so.
|
|
13885
|
+
* A check that cannot run because a provider or token is missing is a skip with the reason. Any other error
|
|
13886
|
+
* fails that check alone, and the rest still run. The run fails when any check failed.
|
|
13887
|
+
*/
|
|
13888
|
+
async function runDoctorAll(input) {
|
|
13889
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
13890
|
+
const logger = input.logger ?? getLogger();
|
|
13891
|
+
const checks = input.checks ?? DEEP_CHECKS;
|
|
13892
|
+
const rows = [];
|
|
13893
|
+
for (const check of checks) rows.push(toRow(check, await outcomeOf(check, input)));
|
|
13894
|
+
printCheckRows(rows, print);
|
|
13895
|
+
const summary = summariseChecks(rows);
|
|
13896
|
+
printCheckSummary(summary, print);
|
|
13897
|
+
const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
|
|
13898
|
+
logger.info({
|
|
13899
|
+
...summary,
|
|
13900
|
+
status,
|
|
13901
|
+
checks: rows.map((r) => `${r.id}:${r.status}`)
|
|
13902
|
+
}, "doctor --all");
|
|
13903
|
+
return {
|
|
13904
|
+
status,
|
|
13905
|
+
rows,
|
|
13906
|
+
summary
|
|
13907
|
+
};
|
|
13908
|
+
}
|
|
13909
|
+
/** Runs one check silently. A missing token is a skip; any other error is that check's failure. */
|
|
13910
|
+
async function outcomeOf(check, input) {
|
|
13911
|
+
try {
|
|
13912
|
+
return await check.run({
|
|
13913
|
+
loaded: input.loaded,
|
|
13914
|
+
context: input.context,
|
|
13915
|
+
print: () => {},
|
|
13916
|
+
...input.logger ? { logger: input.logger } : {}
|
|
13917
|
+
});
|
|
13918
|
+
} catch (err) {
|
|
13919
|
+
if (err instanceof WorkspaceContextError) throw err;
|
|
13920
|
+
const noToken = missingTokenReason(err);
|
|
13921
|
+
if (noToken !== void 0) return {
|
|
13922
|
+
status: "skip",
|
|
13923
|
+
summary: {
|
|
13373
13924
|
ok: 0,
|
|
13374
13925
|
fail: 0,
|
|
13375
13926
|
skip: 1
|
|
@@ -20254,72 +20805,14 @@ const probeArgs = (y) => y.positional("provider", {
|
|
|
20254
20805
|
}).option("copy", {
|
|
20255
20806
|
type: "boolean",
|
|
20256
20807
|
describe: "`1password export-environment`: put the variables on the clipboard instead of a file"
|
|
20257
|
-
}).option("environment", {
|
|
20258
|
-
type: "string",
|
|
20259
|
-
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)"
|
|
20260
|
-
}).option("yes", {
|
|
20261
|
-
type: "boolean",
|
|
20262
|
-
default: false,
|
|
20263
|
-
describe: "Run a probe that changes things without asking first (required without a terminal)"
|
|
20264
|
-
}).epilogue(TOKEN_PROBE_HELP);
|
|
20265
|
-
// src/commands/owner-environments/owner-environments.ts
|
|
20266
|
-
/**
|
|
20267
|
-
* The Environments the config names: each `credentials` provider's, `githubApps[].environment`, `dev.environment`
|
|
20268
|
-
* and the one of every `repo.secrets.sync` and `repo.variables.sync` entry.
|
|
20269
|
-
*/
|
|
20270
|
-
function ownerEnvironments(config) {
|
|
20271
|
-
const names = /* @__PURE__ */ new Set();
|
|
20272
|
-
const entry = config.providers.credentials;
|
|
20273
|
-
for (const tuple of entry?.tuples ?? []) {
|
|
20274
|
-
const named = credentialsEnvironment(tuple, config);
|
|
20275
|
-
if (named !== void 0) names.add(named);
|
|
20276
|
-
}
|
|
20277
|
-
const instances = new Set((config.githubApps ?? []).map(resolvedEnvironment));
|
|
20278
|
-
for (const environment of instances) names.add(environment);
|
|
20279
|
-
if (config.dev?.environment) names.add(config.dev.environment);
|
|
20280
|
-
for (const sync of [...config.repo?.secrets?.sync ?? [], ...config.repo?.variables?.sync ?? []]) names.add(resolvedEnvironment(sync));
|
|
20281
|
-
return {
|
|
20282
|
-
names: [...names],
|
|
20283
|
-
instances
|
|
20284
|
-
};
|
|
20285
|
-
}
|
|
20286
|
-
// src/commands/token-rotation/token-rotation.ts
|
|
20287
|
-
/** The rotation policy of a token that declares none: a token is due after 90 days, and an expiry is flagged 14 days ahead. */
|
|
20288
|
-
const DEFAULT_TOKEN_ROTATION = {
|
|
20289
|
-
maxAgeDays: 90,
|
|
20290
|
-
warnDays: 14
|
|
20291
|
-
};
|
|
20292
|
-
// src/commands/token-expectations/token-expectations.ts
|
|
20293
|
-
/**
|
|
20294
|
-
* Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
|
|
20295
|
-
* order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
|
|
20296
|
-
* walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
|
|
20297
|
-
*/
|
|
20298
|
-
function tokenExpectations(tokens, filter = {}) {
|
|
20299
|
-
const found = [];
|
|
20300
|
-
for (const token of tokens) {
|
|
20301
|
-
if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
|
|
20302
|
-
const { layers = [], permissions = {} } = token.expect;
|
|
20303
|
-
for (const layer of ENVIRONMENT_LAYERS) {
|
|
20304
|
-
if (filter.layer !== void 0 && filter.layer !== layer) continue;
|
|
20305
|
-
const rules = permissions[layer];
|
|
20306
|
-
if (!rules && !layers.includes(layer)) continue;
|
|
20307
|
-
const entries = Object.entries(rules ?? {});
|
|
20308
|
-
found.push({
|
|
20309
|
-
envName: token.envName,
|
|
20310
|
-
layer,
|
|
20311
|
-
rules: rules ?? {},
|
|
20312
|
-
required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
|
|
20313
|
-
absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name),
|
|
20314
|
-
rotation: {
|
|
20315
|
-
...DEFAULT_TOKEN_ROTATION,
|
|
20316
|
-
...token.expect.rotation
|
|
20317
|
-
}
|
|
20318
|
-
});
|
|
20319
|
-
}
|
|
20320
|
-
}
|
|
20321
|
-
return found;
|
|
20322
|
-
}
|
|
20808
|
+
}).option("environment", {
|
|
20809
|
+
type: "string",
|
|
20810
|
+
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)"
|
|
20811
|
+
}).option("yes", {
|
|
20812
|
+
type: "boolean",
|
|
20813
|
+
default: false,
|
|
20814
|
+
describe: "Run a probe that changes things without asking first (required without a terminal)"
|
|
20815
|
+
}).epilogue(TOKEN_PROBE_HELP);
|
|
20323
20816
|
// src/commands/probe/app-vault.ts
|
|
20324
20817
|
/**
|
|
20325
20818
|
* The vault of an app that carries its own `holocron.config` (`apps/comlink`, `apps/sentinel`): those configs govern where
|
|
@@ -21961,118 +22454,6 @@ function listProbes(groups) {
|
|
|
21961
22454
|
}
|
|
21962
22455
|
return lines;
|
|
21963
22456
|
}
|
|
21964
|
-
// src/commands/probe/probe-token/choose-token.ts
|
|
21965
|
-
/**
|
|
21966
|
-
* Asks which token a probe that accepts one should check: the configured one, one from an Environment, or one typed in
|
|
21967
|
-
* (hidden as it is typed). Only called on a terminal when neither `--token` nor `--environment` was given.
|
|
21968
|
-
*/
|
|
21969
|
-
async function chooseToken(provider) {
|
|
21970
|
-
const how = await select({
|
|
21971
|
-
message: `Which ${provider} token should it check?`,
|
|
21972
|
-
choices: [
|
|
21973
|
-
{
|
|
21974
|
-
name: "The one this repo is configured to use",
|
|
21975
|
-
value: "configured"
|
|
21976
|
-
},
|
|
21977
|
-
{
|
|
21978
|
-
name: "One from a vault Environment (a layer such as ci or dev, or a name)",
|
|
21979
|
-
value: "environment"
|
|
21980
|
-
},
|
|
21981
|
-
{
|
|
21982
|
-
name: "Type or paste a token",
|
|
21983
|
-
value: "paste"
|
|
21984
|
-
}
|
|
21985
|
-
]
|
|
21986
|
-
});
|
|
21987
|
-
if (how === "environment") return { environment: (await input({
|
|
21988
|
-
message: "Environment (layer or name):",
|
|
21989
|
-
default: "ci"
|
|
21990
|
-
})).trim() };
|
|
21991
|
-
if (how === "paste") return { token: (await password({
|
|
21992
|
-
message: `${provider} token:`,
|
|
21993
|
-
mask: "*"
|
|
21994
|
-
})).trim() };
|
|
21995
|
-
}
|
|
21996
|
-
// src/commands/probe/probe-token/default-provider-tokens.ts
|
|
21997
|
-
/**
|
|
21998
|
-
* Reads the tokens a provider's plugin lists (its module-level `tokens`), resolving the plugin package from the
|
|
21999
|
-
* directory of the config that was loaded so a `--cwd` run finds the plugins installed there.
|
|
22000
|
-
*/
|
|
22001
|
-
function defaultProviderTokens(loaded, importer = createDefaultImporter(dirname(loaded.filepath))) {
|
|
22002
|
-
return async (provider) => (await importer(resolvePluginPackage$1(provider))).tokens ?? [];
|
|
22003
|
-
}
|
|
22004
|
-
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
22005
|
-
/**
|
|
22006
|
-
* The vault Environment `holocron sync secrets --env <environment>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
22007
|
-
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
22008
|
-
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
22009
|
-
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
22010
|
-
*
|
|
22011
|
-
* @param id - The `--env` value the user gave.
|
|
22012
|
-
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
22013
|
-
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
22014
|
-
*/
|
|
22015
|
-
async function resolveEnvironmentId(id, input) {
|
|
22016
|
-
if (!isEnvironmentLayer(id)) return id;
|
|
22017
|
-
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
22018
|
-
}
|
|
22019
|
-
// src/commands/probe/probe-token/environment-tokens.ts
|
|
22020
|
-
/**
|
|
22021
|
-
* Every token the provider declares that one vault Environment holds, read in memory. Only an Environment this repo uses is
|
|
22022
|
-
* read: a layer word (`local`, `dev`, `ci`, `prod`) is this repo's `<org/repo> - <layer>`, and any other text must be a
|
|
22023
|
-
* name the config already names (`configured`), so a probe cannot be pointed at an Environment the repo has nothing to
|
|
22024
|
-
* do with. `local` reads the way the CLI does, `- local` over `- dev`, and `- local` may be absent.
|
|
22025
|
-
*
|
|
22026
|
-
* Each token the provider's plugin lists is looked for under its own variable (`HOLOCRON_SENTRY_TOKEN`), then the
|
|
22027
|
-
* vendor's (`vendorEnvName`); the first that holds a value is that token's. A token the Environment does not hold is in
|
|
22028
|
-
* `missing`, so the caller can report it by name.
|
|
22029
|
-
*
|
|
22030
|
-
* @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured, the plugin
|
|
22031
|
-
* lists no token, or the Environment holds none of them.
|
|
22032
|
-
*/
|
|
22033
|
-
async function environmentTokens(input) {
|
|
22034
|
-
if (!isEnvironmentLayer(input.environment) && !input.configured.includes(input.environment)) {
|
|
22035
|
-
const known = [...ENVIRONMENT_LAYERS, ...input.configured];
|
|
22036
|
-
throw new Error(`${input.environment} is not an Environment this repo's config names; use one of: ${known.join(", ")}`);
|
|
22037
|
-
}
|
|
22038
|
-
const read = input.vault?.readEnvironment?.bind(input.vault);
|
|
22039
|
-
if (!read) throw new Error("--environment needs a vault provider that can read an Environment (1Password); none is configured");
|
|
22040
|
-
const at = {
|
|
22041
|
-
repoRoot: input.repoRoot,
|
|
22042
|
-
gitExec: input.gitExec
|
|
22043
|
-
};
|
|
22044
|
-
const environment = await resolveEnvironmentId(input.environment, at);
|
|
22045
|
-
let values;
|
|
22046
|
-
if (input.environment === "local") {
|
|
22047
|
-
const dev = await read(await resolveEnvironmentId("dev", at));
|
|
22048
|
-
const local = await read(environment).catch(() => ({}));
|
|
22049
|
-
values = {
|
|
22050
|
-
...dev,
|
|
22051
|
-
...local
|
|
22052
|
-
};
|
|
22053
|
-
} else values = await read(environment);
|
|
22054
|
-
if (input.tokens.length === 0) throw new Error(`the ${input.provider} plugin lists no token to look for`);
|
|
22055
|
-
const held = [];
|
|
22056
|
-
const missing = [];
|
|
22057
|
-
for (const declared of input.tokens) {
|
|
22058
|
-
const variable = [declared.envName, ...declared.vendorEnvName ? [declared.vendorEnvName] : []].find((v) => values[v]);
|
|
22059
|
-
if (variable) held.push({
|
|
22060
|
-
token: values[variable],
|
|
22061
|
-
variable,
|
|
22062
|
-
envName: declared.envName
|
|
22063
|
-
});
|
|
22064
|
-
else missing.push(declared.envName);
|
|
22065
|
-
}
|
|
22066
|
-
if (held.length === 0) {
|
|
22067
|
-
const names = input.tokens.flatMap((t) => [t.envName, ...t.vendorEnvName ? [t.vendorEnvName] : []]);
|
|
22068
|
-
throw new Error(`${environment} holds none of ${names.join(", ")}`);
|
|
22069
|
-
}
|
|
22070
|
-
return {
|
|
22071
|
-
environment,
|
|
22072
|
-
held,
|
|
22073
|
-
missing
|
|
22074
|
-
};
|
|
22075
|
-
}
|
|
22076
22457
|
// src/commands/probe/references/clone-org.ts
|
|
22077
22458
|
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
22078
22459
|
const MAX_FILE_BYTES = 5242880;
|
|
@@ -22253,145 +22634,6 @@ function ciProbes(org, clone = cloneOrg) {
|
|
|
22253
22634
|
}
|
|
22254
22635
|
};
|
|
22255
22636
|
}
|
|
22256
|
-
// src/commands/probe/scrub.ts
|
|
22257
|
-
const HIDDEN = "«hidden»";
|
|
22258
|
-
/** Shapes that are credentials wherever they appear: a Discord webhook URL, a bearer header, a Sentry token. */
|
|
22259
|
-
const SHAPES = [
|
|
22260
|
-
/https:\/\/(?:[\w-]+\.)?discord(?:app)?\.com\/api\/webhooks\/\d+\/[\w-]+/g,
|
|
22261
|
-
/\bBearer\s+[\w.~+/=-]+/gi,
|
|
22262
|
-
/\bsntry[a-z]_[\w+/=-]+/g
|
|
22263
|
-
];
|
|
22264
|
-
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22265
|
-
/**
|
|
22266
|
-
* Returns a function that replaces secrets in a line of output: every value the caller gave (a token, a signing secret)
|
|
22267
|
-
* and every string shaped like a credential. Values shorter than 6 characters are left, since replacing `ab` would
|
|
22268
|
-
* mangle ordinary words. `secrets` may grow after this is called; it is read on each use.
|
|
22269
|
-
*/
|
|
22270
|
-
function createScrubber(secrets) {
|
|
22271
|
-
return (text) => {
|
|
22272
|
-
let out = text;
|
|
22273
|
-
const known = [...secrets].filter((s) => s.length >= 6).sort((a, b) => b.length - a.length);
|
|
22274
|
-
for (const secret of known) out = out.replace(new RegExp(escape(secret), "g"), HIDDEN);
|
|
22275
|
-
for (const shape of SHAPES) out = out.replace(shape, HIDDEN);
|
|
22276
|
-
return out;
|
|
22277
|
-
};
|
|
22278
|
-
}
|
|
22279
|
-
// src/commands/probe/run-probe.ts
|
|
22280
|
-
const defaultInterrupt = (handler) => {
|
|
22281
|
-
const listener = () => void handler().finally(() => process.exit(130));
|
|
22282
|
-
process.once("SIGINT", listener);
|
|
22283
|
-
return () => void process.off("SIGINT", listener);
|
|
22284
|
-
};
|
|
22285
|
-
/**
|
|
22286
|
-
* Runs one probe under the rules every probe shares: what it prints is scrubbed, a change goes through `write` (skipped
|
|
22287
|
-
* on `--dry-run`), a probe that writes is asked about first, and what it registered to undo runs whether it succeeded,
|
|
22288
|
-
* failed or was interrupted.
|
|
22289
|
-
*/
|
|
22290
|
-
async function runProbe(input) {
|
|
22291
|
-
const progress = createProgress(input.print ?? ((line) => console.log(line)));
|
|
22292
|
-
const print = progress.print;
|
|
22293
|
-
const secrets = new Set(input.secrets ?? []);
|
|
22294
|
-
const scrub = createScrubber(secrets);
|
|
22295
|
-
const rows = [];
|
|
22296
|
-
const emit = (row) => {
|
|
22297
|
-
const clean = {
|
|
22298
|
-
status: row.status,
|
|
22299
|
-
label: scrub(stripControl(row.label)),
|
|
22300
|
-
...row.detail ? { detail: scrub(sanitizeDetail(row.detail)) } : {}
|
|
22301
|
-
};
|
|
22302
|
-
rows.push(clean);
|
|
22303
|
-
if (clean.status === "heading") print(`\n ${style.header(clean.label)}`);
|
|
22304
|
-
else print(statusRow(clean.status === "info" ? "skip" : clean.status, [clean.label, clean.detail ?? ""]));
|
|
22305
|
-
};
|
|
22306
|
-
if (input.heading) emit({
|
|
22307
|
-
status: "heading",
|
|
22308
|
-
label: input.heading
|
|
22309
|
-
});
|
|
22310
|
-
if (input.probe.writes && !input.dryRun && !input.yes) {
|
|
22311
|
-
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`);
|
|
22312
|
-
if (!await (input.confirm ?? ((message) => confirm({
|
|
22313
|
-
message,
|
|
22314
|
-
default: false
|
|
22315
|
-
})))(`${input.name} changes things on ${input.provider}: ${input.probe.summary}. Continue?`)) {
|
|
22316
|
-
emit({
|
|
22317
|
-
status: "info",
|
|
22318
|
-
label: input.name,
|
|
22319
|
-
detail: "cancelled; nothing was changed"
|
|
22320
|
-
});
|
|
22321
|
-
return {
|
|
22322
|
-
status: "cancelled",
|
|
22323
|
-
rows
|
|
22324
|
-
};
|
|
22325
|
-
}
|
|
22326
|
-
}
|
|
22327
|
-
const undo = [];
|
|
22328
|
-
const runCleanups = async () => {
|
|
22329
|
-
while (undo.length > 0) {
|
|
22330
|
-
const { label, fn } = undo.pop();
|
|
22331
|
-
try {
|
|
22332
|
-
await fn();
|
|
22333
|
-
emit({
|
|
22334
|
-
status: "info",
|
|
22335
|
-
label: `cleaned up ${label}`
|
|
22336
|
-
});
|
|
22337
|
-
} catch (err) {
|
|
22338
|
-
emit({
|
|
22339
|
-
status: "fail",
|
|
22340
|
-
label: `could not clean up ${label}`,
|
|
22341
|
-
detail: commandFailureMessage(err)
|
|
22342
|
-
});
|
|
22343
|
-
}
|
|
22344
|
-
}
|
|
22345
|
-
};
|
|
22346
|
-
const ctx = {
|
|
22347
|
-
dryRun: input.dryRun,
|
|
22348
|
-
args: input.args ?? [],
|
|
22349
|
-
...input.lcov ? { lcov: input.lcov } : {},
|
|
22350
|
-
say: emit,
|
|
22351
|
-
secret: (value) => {
|
|
22352
|
-
if (value) secrets.add(value);
|
|
22353
|
-
},
|
|
22354
|
-
async write(label, fn) {
|
|
22355
|
-
if (!input.probe.writes) throw new Error(`${input.name} is read-only and cannot ${label}`);
|
|
22356
|
-
if (input.dryRun) {
|
|
22357
|
-
emit({
|
|
22358
|
-
status: "info",
|
|
22359
|
-
label: `would ${label}`
|
|
22360
|
-
});
|
|
22361
|
-
return;
|
|
22362
|
-
}
|
|
22363
|
-
return fn();
|
|
22364
|
-
},
|
|
22365
|
-
cleanup(label, fn) {
|
|
22366
|
-
if (!input.dryRun) undo.push({
|
|
22367
|
-
label,
|
|
22368
|
-
fn
|
|
22369
|
-
});
|
|
22370
|
-
}
|
|
22371
|
-
};
|
|
22372
|
-
const stopListening = (input.onInterrupt ?? defaultInterrupt)(runCleanups);
|
|
22373
|
-
try {
|
|
22374
|
-
await progress.run(`${input.name}…`, () => input.probe.run(ctx));
|
|
22375
|
-
} catch (err) {
|
|
22376
|
-
emit({
|
|
22377
|
-
status: "fail",
|
|
22378
|
-
label: input.name,
|
|
22379
|
-
detail: commandFailureMessage(err)
|
|
22380
|
-
});
|
|
22381
|
-
} finally {
|
|
22382
|
-
stopListening();
|
|
22383
|
-
await runCleanups();
|
|
22384
|
-
}
|
|
22385
|
-
const counts = {
|
|
22386
|
-
ok: rows.filter((r) => r.status === "ok").length,
|
|
22387
|
-
fail: rows.filter((r) => r.status === "fail").length
|
|
22388
|
-
};
|
|
22389
|
-
if (counts.ok + counts.fail > 0) print(`\n${counts.ok} ok, ${counts.fail} fail`);
|
|
22390
|
-
return {
|
|
22391
|
-
status: counts.fail > 0 ? "fail" : "ok",
|
|
22392
|
-
rows
|
|
22393
|
-
};
|
|
22394
|
-
}
|
|
22395
22637
|
// src/commands/probe/specs/real-specs-io.ts
|
|
22396
22638
|
/** The `specs check` probe's inputs from the real filesystem under `repoRoot`. */
|
|
22397
22639
|
function realSpecsIo(repoRoot) {
|