@theholocron/cli 5.0.0-alpha.410 → 5.0.0-alpha.412
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +296 -30
- package/dist/cli.mjs.map +1 -1
- package/dist/{config-system-CeVFoOau.mjs → config-system-DYqb53Rd.mjs} +31 -3
- package/dist/{index-BqUevSW_.d.mts → index-D39ic8yM.d.mts} +20 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +1 -1
- package/dist/plugin/capabilities.d.mts +1 -1
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/package.json +10 -10
package/dist/cli.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { homedir, tmpdir } from "node:os";
|
|
4
4
|
import path, { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
-
import { PREFIX, createEnvLookup, firstEnv, holocronEnv } from "@theholocron/env-utils/lookup";
|
|
5
|
+
import { PREFIX, createEnvLookup, detectEnvironment, firstEnv, holocronEnv } from "@theholocron/env-utils/lookup";
|
|
6
6
|
import { ProviderApiError, ProviderApiError as ProviderApiError$1, createRestClient, onRetry } from "@theholocron/http-client";
|
|
7
7
|
import { addGlobalOptions, groupMenu, tokenContext } from "@theholocron/kyber/flags";
|
|
8
8
|
import { checkForUpdates } from "@theholocron/kyber/notifier";
|
|
@@ -40,6 +40,13 @@ import { ADR_DIR, ADR_STATUSES, CLOSED_STATUSES, SPEC_DIRS, SPEC_STATUSES, WITHD
|
|
|
40
40
|
import { loadConfigPath } from "@theholocron/datapad";
|
|
41
41
|
import { fetchLatestFromNpm, runUpgradeNode } from "@theholocron/astromech/upgrade";
|
|
42
42
|
import { lintCommitMsgFile } from "@theholocron/astromech/lint";
|
|
43
|
+
// src/credentials-environments/derives-environment/derives-environment.ts
|
|
44
|
+
/** The providers whose `credentials` entry may leave `environment` out and have it derived (#2063). */
|
|
45
|
+
const DERIVING = /* @__PURE__ */ new Set(["1password"]);
|
|
46
|
+
/** Whether a `credentials` provider with no `environment` option derives its Environment names. */
|
|
47
|
+
function derivesEnvironment(provider) {
|
|
48
|
+
return DERIVING.has(provider);
|
|
49
|
+
}
|
|
43
50
|
// src/plugin/capabilities/capabilities.ts
|
|
44
51
|
/** How many providers each capability resolves to: one (`"single"`) or several active at once (`"many"`). */
|
|
45
52
|
const CARDINALITY = {
|
|
@@ -115,6 +122,25 @@ var MissingTokenError = class extends Error {
|
|
|
115
122
|
/** Lets a caller tell this error from any other by name, across package copies. */
|
|
116
123
|
name = "MissingTokenError";
|
|
117
124
|
};
|
|
125
|
+
// src/config/validate-secrets-deploy/validate-secrets-deploy.ts
|
|
126
|
+
/**
|
|
127
|
+
* Check `repo.secrets.deploy`: each entry names a vault environment and at least one of a non-empty `keys` list and a
|
|
128
|
+
* non-empty `prefix`. An entry with neither would mean "all keys", which a deployment never gets (spec
|
|
129
|
+
* `tech-deployment-key-allowlist`, #2061), so it is an error here and not a silent skip.
|
|
130
|
+
*
|
|
131
|
+
* @param secrets - `repo.secrets`, if the config has it.
|
|
132
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
133
|
+
*/
|
|
134
|
+
function validateSecretsDeploy(secrets) {
|
|
135
|
+
for (const entry of secrets?.deploy ?? []) {
|
|
136
|
+
if (typeof entry.environment !== "string" || entry.environment.trim() === "") throw new ConfigError("a `repo.secrets.deploy` entry needs the name of a vault environment");
|
|
137
|
+
const label = `\`repo.secrets.deploy\` entry for ${JSON.stringify(entry.environment)}`;
|
|
138
|
+
const { keys, prefix } = entry;
|
|
139
|
+
if (keys !== void 0 && (!Array.isArray(keys) || keys.some((k) => typeof k !== "string" || k === ""))) throw new ConfigError(`${label} has \`keys\` that is not a list of key names`);
|
|
140
|
+
if (prefix !== void 0 && (typeof prefix !== "string" || prefix === "")) throw new ConfigError(`${label} has an empty \`prefix\``);
|
|
141
|
+
if ((keys === void 0 || keys.length === 0) && prefix === void 0) throw new ConfigError(`${label} needs \`keys\` (a list of names) or \`prefix\` (such as "SENTINEL_"): a deployment never receives every key`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
118
144
|
// src/config/validate-variables-sync/validate-variables-sync.ts
|
|
119
145
|
/** GitHub treats variable names as case-insensitive, so every comparison goes through this. */
|
|
120
146
|
const key = (name) => name.toUpperCase();
|
|
@@ -292,11 +318,12 @@ function resolveConfig(raw) {
|
|
|
292
318
|
if (raw.githubApps !== void 0) validateGitHubApps(raw.githubApps);
|
|
293
319
|
if (raw.ideas !== void 0) validateIdeas(raw.ideas);
|
|
294
320
|
validateVariablesSync(raw.repo?.variables);
|
|
321
|
+
validateSecretsDeploy(raw.repo?.secrets);
|
|
295
322
|
const credentialsEntry = providers.credentials;
|
|
296
323
|
if (credentialsEntry?.cardinality === "many") for (const tuple of credentialsEntry.tuples) {
|
|
297
324
|
const own = tuple.options.environment;
|
|
298
325
|
if (own !== void 0 && (typeof own !== "string" || own.trim() === "")) throw new ConfigError$1(`the \`environment\` option of the \`${tuple.provider}\` credentials provider must be the name of an environment, got an empty value`);
|
|
299
|
-
if (credentialsEnvironment(tuple, raw) === void 0) throw new ConfigError$1(`the \`${tuple.provider}\` credentials provider has no environment to read: give it an \`environment\` option or set \`credentials.environment\``);
|
|
326
|
+
if (credentialsEnvironment(tuple, raw) === void 0 && !derivesEnvironment(tuple.provider)) throw new ConfigError$1(`the \`${tuple.provider}\` credentials provider has no environment to read: give it an \`environment\` option or set \`credentials.environment\``);
|
|
300
327
|
}
|
|
301
328
|
const homepage = raw.homepage ?? (docs?.domain ? `https://${docs.domain}/` : void 0);
|
|
302
329
|
return {
|
|
@@ -385,7 +412,8 @@ function mergeRepo(prev, next) {
|
|
|
385
412
|
...repo.secrets?.repo || secrets.repo ? { repo: names$1.merge(repo.secrets?.repo ?? [], secrets.repo ?? []) } : {},
|
|
386
413
|
...repo.secrets?.org || secrets.org ? { org: names$1.merge(repo.secrets?.org ?? [], secrets.org ?? []) } : {},
|
|
387
414
|
...Object.keys(environments).length > 0 ? { environments } : {},
|
|
388
|
-
...repo.secrets?.sync || secrets.sync ? { sync: mergeSync(repo.secrets?.sync, secrets.sync) } : {}
|
|
415
|
+
...repo.secrets?.sync || secrets.sync ? { sync: mergeSync(repo.secrets?.sync, secrets.sync) } : {},
|
|
416
|
+
...repo.secrets?.deploy || secrets.deploy ? { deploy: [...repo.secrets?.deploy ?? [], ...secrets.deploy ?? []] } : {}
|
|
389
417
|
};
|
|
390
418
|
}
|
|
391
419
|
if (topics) repo.topics = names$1.merge(repo.topics ?? [], topics);
|
|
@@ -985,6 +1013,103 @@ function applyResolvedConfig(argv, resolved) {
|
|
|
985
1013
|
buildCliLogger(argv, cliLoggerOpts(argv, resolved));
|
|
986
1014
|
applyConfig(resolved.telemetry);
|
|
987
1015
|
}
|
|
1016
|
+
// src/credentials-environments/environment-layers/environment-layers.ts
|
|
1017
|
+
/** The suffix each layer's Environment carries: `<org/repo> - <suffix>`. `test` has none. */
|
|
1018
|
+
const SUFFIX = {
|
|
1019
|
+
local: "local",
|
|
1020
|
+
development: "dev",
|
|
1021
|
+
ci: "ci",
|
|
1022
|
+
production: "prod"
|
|
1023
|
+
};
|
|
1024
|
+
/**
|
|
1025
|
+
* The Environments a layer reads, in the order they are tried (#2063, #2058). A machine (`local`) reads
|
|
1026
|
+
* `<slug> - local` and then `<slug> - dev`: that is the only fallback there is. `development` reads `- dev`, `ci`
|
|
1027
|
+
* reads `- ci` and `production` reads `- prod`; a missing name is a missing name. `test` reads none. Only `- local`
|
|
1028
|
+
* is optional.
|
|
1029
|
+
*/
|
|
1030
|
+
function environmentLayers(slug, layer) {
|
|
1031
|
+
if (layer === "test") return [];
|
|
1032
|
+
const candidate = (suffix, optional) => ({
|
|
1033
|
+
name: `${slug} - ${suffix}`,
|
|
1034
|
+
optional,
|
|
1035
|
+
legacy: false
|
|
1036
|
+
});
|
|
1037
|
+
return layer === "local" ? [candidate(SUFFIX.local, true), candidate(SUFFIX.development, false)] : [candidate(SUFFIX[layer], false)];
|
|
1038
|
+
}
|
|
1039
|
+
// src/credentials-environments/repo-slug/repo-slug.ts
|
|
1040
|
+
/**
|
|
1041
|
+
* The `<org>/<repo>` of the repository at `cwd`, from its `origin` remote. A remote that is missing or cannot be
|
|
1042
|
+
* parsed is a `ConfigError` that names the `environment` option as the fix.
|
|
1043
|
+
*/
|
|
1044
|
+
async function repoSlug(cwd, exec) {
|
|
1045
|
+
const remote = await readGitRemote(cwd, exec ? { exec } : {});
|
|
1046
|
+
if (!remote) throw new ConfigError(`cannot derive the 1Password Environment name: the \`origin\` remote of ${cwd} is missing or not an owner/repo URL. Give the \`credentials\` provider an \`environment\` option to name it.`);
|
|
1047
|
+
return remote.slug;
|
|
1048
|
+
}
|
|
1049
|
+
// src/credentials-environments/legacy-environments/legacy-environments.ts
|
|
1050
|
+
const OLD_NAMES = ["Holocron", "Holocron - GitHub Actions variables"];
|
|
1051
|
+
/** The old Environment names, as candidates that are never reported when absent. */
|
|
1052
|
+
function legacyEnvironments() {
|
|
1053
|
+
return OLD_NAMES.map((name) => ({
|
|
1054
|
+
name,
|
|
1055
|
+
optional: true,
|
|
1056
|
+
legacy: true
|
|
1057
|
+
}));
|
|
1058
|
+
}
|
|
1059
|
+
// src/credentials-environments/resolve-environments/resolve-environments.ts
|
|
1060
|
+
/**
|
|
1061
|
+
* The Environments one `credentials` entry reads. An explicit name (the entry's `environment` option, else the shared
|
|
1062
|
+
* `credentials.environment`) is the only candidate and wins. Otherwise a deriving provider gets the names of its layer
|
|
1063
|
+
* (`environmentLayers()`) from the repo's `origin` and `detectEnvironment()`, followed by the migration fallback.
|
|
1064
|
+
* Nothing is read from a provider here. An empty list means there is nothing to read (the `test` layer).
|
|
1065
|
+
*/
|
|
1066
|
+
async function resolveEnvironments(provider, explicit, input) {
|
|
1067
|
+
if (explicit !== void 0) return [{
|
|
1068
|
+
name: explicit,
|
|
1069
|
+
optional: false,
|
|
1070
|
+
legacy: false
|
|
1071
|
+
}];
|
|
1072
|
+
if (!derivesEnvironment(provider)) return [];
|
|
1073
|
+
const layer = detectEnvironment(input.env);
|
|
1074
|
+
if (layer === "test") return [];
|
|
1075
|
+
return [...environmentLayers(await repoSlug(input.repoRoot, input.gitExec), layer), ...legacyEnvironments()];
|
|
1076
|
+
}
|
|
1077
|
+
// src/credentials-environments/try-environments/try-environments.ts
|
|
1078
|
+
/** A provider's "no such Environment": its API error with status 404 (`ProviderApiError`, matched by shape). */
|
|
1079
|
+
function isNotFound(err) {
|
|
1080
|
+
return typeof err === "object" && err !== null && err.status === 404;
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Calls `attempt` for each candidate and sorts the answers into found and missing. A 404 is a miss; any other error
|
|
1084
|
+
* is thrown. A missing optional Environment is silent. When a required one is missing, the legacy candidates
|
|
1085
|
+
* (migration only, #2063) are tried too, and if one exists the miss is forgiven.
|
|
1086
|
+
*/
|
|
1087
|
+
async function tryEnvironments(candidates, attempt) {
|
|
1088
|
+
const found = [];
|
|
1089
|
+
const missing = [];
|
|
1090
|
+
const ask = async (candidate) => {
|
|
1091
|
+
try {
|
|
1092
|
+
found.push({
|
|
1093
|
+
name: candidate.name,
|
|
1094
|
+
legacy: candidate.legacy,
|
|
1095
|
+
result: await attempt(candidate.name)
|
|
1096
|
+
});
|
|
1097
|
+
} catch (err) {
|
|
1098
|
+
if (!isNotFound(err)) throw err;
|
|
1099
|
+
if (!candidate.optional) missing.push(candidate.name);
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
for (const candidate of candidates.filter((c) => !c.legacy)) await ask(candidate);
|
|
1103
|
+
if (missing.length > 0) {
|
|
1104
|
+
const before = found.length;
|
|
1105
|
+
for (const candidate of candidates.filter((c) => c.legacy)) await ask(candidate);
|
|
1106
|
+
if (found.length > before) missing.length = 0;
|
|
1107
|
+
}
|
|
1108
|
+
return {
|
|
1109
|
+
found,
|
|
1110
|
+
missing
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
988
1113
|
// src/plugin/workspace/workspace.ts
|
|
989
1114
|
/**
|
|
990
1115
|
* The `workspace`-context guard.
|
|
@@ -1082,12 +1207,20 @@ const system = createPluginSystem({
|
|
|
1082
1207
|
if (!entry || entry.cardinality !== "many") return;
|
|
1083
1208
|
const impls = [];
|
|
1084
1209
|
for (const tuple of entry.tuples) try {
|
|
1085
|
-
const
|
|
1086
|
-
if (!
|
|
1210
|
+
const explicit = credentialsEnvironment(tuple, config);
|
|
1211
|
+
if (explicit === void 0 && !derivesEnvironment(tuple.provider)) throw new LoaderError(`the ${tuple.provider} credentials provider has no \`environment\` option and \`credentials.environment\` is not set`);
|
|
1087
1212
|
const impl = await api.loadOne("credentials", tuple);
|
|
1088
1213
|
impls.push(impl);
|
|
1089
|
-
|
|
1090
|
-
|
|
1214
|
+
if (options?.readCredentials === false) continue;
|
|
1215
|
+
const { missing } = await tryEnvironments(await resolveEnvironments(tuple.provider, explicit, {
|
|
1216
|
+
repoRoot: context.repoRoot,
|
|
1217
|
+
...options?.env ? { env: options.env } : {},
|
|
1218
|
+
...options?.gitExec ? { gitExec: options.gitExec } : {}
|
|
1219
|
+
}), async (name) => {
|
|
1220
|
+
const sourceName = `${tuple.provider}:${name}`;
|
|
1221
|
+
if (!hasCredentials(sourceName)) setCredentials(sourceName, await impl.read(name));
|
|
1222
|
+
});
|
|
1223
|
+
if (missing.length > 0) throw new LoaderError(`${tuple.provider} has no Environment named ${missing.map((n) => `"${n}"`).join(", ")}`);
|
|
1091
1224
|
} catch (err) {
|
|
1092
1225
|
api.fail("credentials", tuple, err);
|
|
1093
1226
|
}
|
|
@@ -5065,23 +5198,49 @@ async function checkCredentials(input, loader) {
|
|
|
5065
5198
|
const { tuples } = resolved.providers.credentials;
|
|
5066
5199
|
for (const impl of loader.get("credentials")) {
|
|
5067
5200
|
const tuple = tuples.find((t) => t.provider === impl.providerName);
|
|
5068
|
-
const
|
|
5069
|
-
|
|
5201
|
+
const explicit = tuple && credentialsEnvironment(tuple, resolved);
|
|
5202
|
+
if (!explicit && !derivesEnvironment(impl.providerName)) {
|
|
5203
|
+
rows.push(row$10(impl.providerName, "skip", "no `environment` option and `credentials.environment` is not set"));
|
|
5204
|
+
continue;
|
|
5205
|
+
}
|
|
5206
|
+
try {
|
|
5207
|
+
const candidates = await resolveEnvironments(impl.providerName, explicit, {
|
|
5208
|
+
repoRoot: input.context.repoRoot,
|
|
5209
|
+
...input.env ? { env: input.env } : {},
|
|
5210
|
+
...input.gitExec ? { gitExec: input.gitExec } : {}
|
|
5211
|
+
});
|
|
5212
|
+
rows.push(...await checkProvider(impl, candidates, expected));
|
|
5213
|
+
} catch (err) {
|
|
5214
|
+
rows.push(row$10(impl.providerName, "fail", errorMessage(err)));
|
|
5215
|
+
}
|
|
5070
5216
|
}
|
|
5071
5217
|
return rows;
|
|
5072
5218
|
}
|
|
5073
|
-
|
|
5219
|
+
/**
|
|
5220
|
+
* One row per expected variable, against the Environments the layer reads. A variable counts as present when any
|
|
5221
|
+
* Environment found holds it (the first found wins, as in the credential store). A required Environment that does not
|
|
5222
|
+
* exist is a failing row of its own, by name; a missing `- local` is not mentioned; an old name in use is a skipped row.
|
|
5223
|
+
*/
|
|
5224
|
+
async function checkProvider(impl, candidates, expected) {
|
|
5074
5225
|
const provider = impl.providerName;
|
|
5075
5226
|
if (!impl.inspect) return [row$10(provider, "skip", "cannot list the variables without reading their values")];
|
|
5076
5227
|
if (expected.length === 0) return [row$10(provider, "skip", "no configured plugin lists the tokens it takes")];
|
|
5228
|
+
if (candidates.length === 0) return [row$10(provider, "skip", "the `test` layer reads no Environment")];
|
|
5229
|
+
const inspect = impl.inspect.bind(impl);
|
|
5077
5230
|
try {
|
|
5078
|
-
const found = await
|
|
5079
|
-
const
|
|
5080
|
-
const
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
})
|
|
5231
|
+
const { found, missing } = await tryEnvironments(candidates, inspect);
|
|
5232
|
+
const rows = missing.map((name) => row$10(provider, "fail", `${provider} has no Environment named "${name}"`));
|
|
5233
|
+
const labels = found.map(({ name, result }) => result.environment === name ? `"${name}"` : `"${result.environment}" (the config writes "${name}")`);
|
|
5234
|
+
const where = labels.join(", ");
|
|
5235
|
+
for (const { name, legacy } of found) if (legacy) rows.push(row$10(provider, "skip", `read from the old Environment name "${name}"; rename it`));
|
|
5236
|
+
if (found.length === 0) return rows;
|
|
5237
|
+
for (const { name, optional } of expected) {
|
|
5238
|
+
const at = found.findIndex((f) => f.result.names.includes(name));
|
|
5239
|
+
if (at >= 0) rows.push(row$10(provider, "ok", `present in ${labels[at]}`, name));
|
|
5240
|
+
else if (optional) rows.push(row$10(provider, "skip", `optional, not set in ${where}`, name));
|
|
5241
|
+
else rows.push(row$10(provider, "fail", `missing from ${where}`, name));
|
|
5242
|
+
}
|
|
5243
|
+
return rows;
|
|
5085
5244
|
} catch (err) {
|
|
5086
5245
|
return [row$10(provider, "fail", errorMessage(err))];
|
|
5087
5246
|
}
|
|
@@ -10348,6 +10507,83 @@ const doctorRepoCommand = {
|
|
|
10348
10507
|
})).status === "fail") process.exitCode = 1;
|
|
10349
10508
|
}
|
|
10350
10509
|
};
|
|
10510
|
+
// src/commands/secrets-sync/deploy-filter/deploy-filter.ts
|
|
10511
|
+
/**
|
|
10512
|
+
* What `repo.secrets.deploy` lets one vault environment send to a deployment or a Worker: every entry naming it adds
|
|
10513
|
+
* its `keys` and `prefix`. `undefined` when no entry names it, which the caller turns into a `ConfigError`; there is
|
|
10514
|
+
* no default that sends everything.
|
|
10515
|
+
*
|
|
10516
|
+
* @param entries - `repo.secrets.deploy`, if the config has it.
|
|
10517
|
+
* @param environmentId - The vault environment being synced.
|
|
10518
|
+
*/
|
|
10519
|
+
function deployFilter(entries, environmentId) {
|
|
10520
|
+
const matching = (entries ?? []).filter((entry) => entry.environment === environmentId);
|
|
10521
|
+
if (matching.length === 0) return void 0;
|
|
10522
|
+
return {
|
|
10523
|
+
keys: [...new Set(matching.flatMap((entry) => entry.keys ?? []))],
|
|
10524
|
+
prefixes: [...new Set(matching.flatMap((entry) => entry.prefix ? [entry.prefix] : []))]
|
|
10525
|
+
};
|
|
10526
|
+
}
|
|
10527
|
+
// src/commands/secrets-sync/split-deploy-keys/split-deploy-keys.ts
|
|
10528
|
+
/**
|
|
10529
|
+
* Split a vault environment's key names by what a deployment may receive. A key passes when it is listed or starts
|
|
10530
|
+
* with a prefix (case-sensitive). A listed key the vault does not hold stays in `send`, so the sync reports it as
|
|
10531
|
+
* missing rather than dropping it. Only names go in and out.
|
|
10532
|
+
*
|
|
10533
|
+
* @param vaultKeys - The names the vault environment holds.
|
|
10534
|
+
* @param filter - From `deployFilter()`.
|
|
10535
|
+
*/
|
|
10536
|
+
function splitDeployKeys(vaultKeys, filter) {
|
|
10537
|
+
const passes = (key) => filter.keys.includes(key) || filter.prefixes.some((p) => key.startsWith(p));
|
|
10538
|
+
const send = vaultKeys.filter(passes);
|
|
10539
|
+
const filtered = vaultKeys.filter((key) => !passes(key));
|
|
10540
|
+
return {
|
|
10541
|
+
send: [...send, ...filter.keys.filter((key) => !vaultKeys.includes(key))],
|
|
10542
|
+
filtered
|
|
10543
|
+
};
|
|
10544
|
+
}
|
|
10545
|
+
// src/commands/doctor-secrets/deploy-key-rows.ts
|
|
10546
|
+
/**
|
|
10547
|
+
* One row per vault environment `repo.secrets.deploy` names: the key names a deployment or Worker would receive from
|
|
10548
|
+
* a `secrets sync`, and how many the filter keeps back, so a token that should not go out is visible before the
|
|
10549
|
+
* sync. Names only: the values the vault returns are dropped at once. An environment that cannot be listed (no vault,
|
|
10550
|
+
* no token, an error) is a skipped row with the reason, never a failure.
|
|
10551
|
+
*
|
|
10552
|
+
* @param entries - `repo.secrets.deploy`.
|
|
10553
|
+
* @param vault - The `vault` provider, or why there is none.
|
|
10554
|
+
*/
|
|
10555
|
+
async function deployKeyRows(entries, vault) {
|
|
10556
|
+
const rows = [];
|
|
10557
|
+
for (const environment of [...new Set(entries.map((entry) => entry.environment))]) {
|
|
10558
|
+
const id = `deploy-${environment}`;
|
|
10559
|
+
const title = `${environment} deployment receives only its keys`;
|
|
10560
|
+
const skip = (detail) => rows.push({
|
|
10561
|
+
id,
|
|
10562
|
+
title,
|
|
10563
|
+
status: "skip",
|
|
10564
|
+
detail,
|
|
10565
|
+
problems: []
|
|
10566
|
+
});
|
|
10567
|
+
const filter = deployFilter(entries, environment);
|
|
10568
|
+
if ("why" in vault) skip(vault.why);
|
|
10569
|
+
else if (!vault.readEnvironment) skip(`vault provider (${vault.providerName}) cannot list an environment's keys`);
|
|
10570
|
+
else try {
|
|
10571
|
+
const names = Object.keys(await vault.readEnvironment(environment)).sort();
|
|
10572
|
+
const { send, filtered } = splitDeployKeys(names, filter);
|
|
10573
|
+
const sends = send.filter((name) => names.includes(name));
|
|
10574
|
+
rows.push({
|
|
10575
|
+
id,
|
|
10576
|
+
title,
|
|
10577
|
+
status: "ok",
|
|
10578
|
+
detail: `sends ${sends.length} of ${names.length}: ${sends.join(", ") || "(none)"}${filtered.length > 0 ? `; keeps back ${filtered.length}: ${filtered.join(", ")}` : ""}`,
|
|
10579
|
+
problems: []
|
|
10580
|
+
});
|
|
10581
|
+
} catch (err) {
|
|
10582
|
+
skip(missingTokenReason(err) ?? `could not read vault environment ${environment}: ${describeError(err)}`);
|
|
10583
|
+
}
|
|
10584
|
+
}
|
|
10585
|
+
return rows;
|
|
10586
|
+
}
|
|
10351
10587
|
// src/commands/doctor-secrets/unique-names.ts
|
|
10352
10588
|
/** Names that differ only in case are one secret to GitHub, so the first spelling wins. */
|
|
10353
10589
|
const uniqueNames = (names) => {
|
|
@@ -10500,7 +10736,8 @@ async function runDoctorSecrets(input) {
|
|
|
10500
10736
|
});
|
|
10501
10737
|
}
|
|
10502
10738
|
const rows = [];
|
|
10503
|
-
|
|
10739
|
+
const deployRows = await deployKeyRows(config.repo?.secrets?.deploy ?? [], loader.has("vault") ? loader.get("vault") : { why: whyMissing(loader, "vault", "no `vault` provider to list the environment's keys with") });
|
|
10740
|
+
if (checks.length === 0 && synced.rows.length === 0 && deployRows.length === 0) rows.push({
|
|
10504
10741
|
id: "secrets",
|
|
10505
10742
|
title: "secrets",
|
|
10506
10743
|
status: "ok",
|
|
@@ -10520,7 +10757,7 @@ async function runDoctorSecrets(input) {
|
|
|
10520
10757
|
const secrets = loader.get("secrets");
|
|
10521
10758
|
for (const check of checks) rows.push(await checkScope(secrets, check));
|
|
10522
10759
|
}
|
|
10523
|
-
rows.push(...synced.rows);
|
|
10760
|
+
rows.push(...synced.rows, ...deployRows);
|
|
10524
10761
|
printCheckRows(rows, print);
|
|
10525
10762
|
const summary = summariseChecks(rows);
|
|
10526
10763
|
printCheckSummary(summary, print);
|
|
@@ -10703,7 +10940,10 @@ function githubEnvironments(config, feeds) {
|
|
|
10703
10940
|
function ownerEnvironments(config) {
|
|
10704
10941
|
const names = /* @__PURE__ */ new Set();
|
|
10705
10942
|
const entry = config.providers.credentials;
|
|
10706
|
-
for (const tuple of entry?.tuples ?? [])
|
|
10943
|
+
for (const tuple of entry?.tuples ?? []) {
|
|
10944
|
+
const named = credentialsEnvironment(tuple, config);
|
|
10945
|
+
if (named !== void 0) names.add(named);
|
|
10946
|
+
}
|
|
10707
10947
|
const instances = new Set((config.githubApps ?? []).map((app) => app.environment));
|
|
10708
10948
|
for (const environment of instances) names.add(environment);
|
|
10709
10949
|
if (config.dev?.environment) names.add(config.dev.environment);
|
|
@@ -24097,8 +24337,10 @@ function restorePem(value) {
|
|
|
24097
24337
|
*
|
|
24098
24338
|
* Per-secret routing rules:
|
|
24099
24339
|
*
|
|
24100
|
-
* -
|
|
24101
|
-
* (
|
|
24340
|
+
* - `deployment` (for each target the caller asks for, defaults: production + preview) and a Worker's secrets fail
|
|
24341
|
+
* closed (#2061): they receive only the keys `repo.secrets.deploy` names for this environment (an exact `keys`
|
|
24342
|
+
* list and/or a `prefix`), passed in as `deployFilter`. With none, the run throws a `ConfigError` before it reads
|
|
24343
|
+
* the vault. A name outside the filter is reported by name only and never reaches the provider.
|
|
24102
24344
|
* - `secrets` (GH Actions) defaults to every key, repo-scoped — but a
|
|
24103
24345
|
* caller can pass `githubSecretKeys` (an allowlist, from repeatable
|
|
24104
24346
|
* `--github-secret KEY` CLI values) to restrict `secrets` to only
|
|
@@ -24141,6 +24383,8 @@ async function runSecretsSync(input) {
|
|
|
24141
24383
|
dryRun: (input.context.dryRun ?? false) || void 0
|
|
24142
24384
|
}, "secrets sync: start");
|
|
24143
24385
|
const dryRun = input.context.dryRun ?? false;
|
|
24386
|
+
const variablesOnly = (input.variableRoutes?.length ?? 0) > 0 && input.secretRoutes?.length === 0 && !input.projectId;
|
|
24387
|
+
if ((loader.has("deployment") && !variablesOnly && Boolean(input.projectId) || input.workerScript) && !input.deployFilter) throw new ConfigError(`no \`repo.secrets.deploy\` entry for environment ${JSON.stringify(input.environmentId)}: a deployment or a Worker receives only the keys named by \`keys\` or \`prefix\`, never every key. Add { environment: ${JSON.stringify(input.environmentId)}, prefix: "<PREFIX>_" } (or keys: [...]) to repo.secrets.deploy`);
|
|
24144
24388
|
const targets = input.targets ?? ["production", "preview"];
|
|
24145
24389
|
print(style.header(`Holocron secrets sync — environment ${input.environmentId}${dryRun ? " (dry-run)" : ""}`));
|
|
24146
24390
|
print(style.dim(` vault: ${vaultProviderName(loader)}`));
|
|
@@ -24168,6 +24412,7 @@ async function runSecretsSync(input) {
|
|
|
24168
24412
|
const keys = Object.keys(envVars).sort();
|
|
24169
24413
|
print(style.step(`read ${keys.length} keys from vault`));
|
|
24170
24414
|
print("");
|
|
24415
|
+
const deploySplit = input.deployFilter ? splitDeployKeys(keys, input.deployFilter) : void 0;
|
|
24171
24416
|
const rows = [];
|
|
24172
24417
|
if (loader.has("secrets")) {
|
|
24173
24418
|
const secrets = loader.get("secrets");
|
|
@@ -24218,7 +24463,6 @@ async function runSecretsSync(input) {
|
|
|
24218
24463
|
}
|
|
24219
24464
|
}
|
|
24220
24465
|
}
|
|
24221
|
-
const variablesOnly = variableRoutes.length > 0 && input.secretRoutes?.length === 0 && !input.projectId;
|
|
24222
24466
|
if (loader.has("deployment") && !variablesOnly) {
|
|
24223
24467
|
const deploy = loader.get("deployment");
|
|
24224
24468
|
if (!input.projectId) {
|
|
@@ -24234,8 +24478,10 @@ async function runSecretsSync(input) {
|
|
|
24234
24478
|
print(formatRow(row));
|
|
24235
24479
|
} else for (const target of targets) {
|
|
24236
24480
|
print(style.step(`deployment (target=${target})`));
|
|
24237
|
-
|
|
24238
|
-
|
|
24481
|
+
const destination = `deployment:${deploy.providerName}`;
|
|
24482
|
+
reportFiltered(destination, `target=${target}`, deploySplit.filtered, input.deployFilter, rows, print);
|
|
24483
|
+
for (const key of deploySplit.send) {
|
|
24484
|
+
rows.push(await pushRow(destination, `target=${target}`, key, envVars, dryRun, async (value) => {
|
|
24239
24485
|
await deploy.setEnvVar(input.projectId, target, key, value);
|
|
24240
24486
|
}));
|
|
24241
24487
|
print(formatRow(rows[rows.length - 1]));
|
|
@@ -24256,15 +24502,33 @@ async function runSecretsSync(input) {
|
|
|
24256
24502
|
};
|
|
24257
24503
|
rows.push(row);
|
|
24258
24504
|
print(formatRow(row));
|
|
24259
|
-
} else
|
|
24260
|
-
|
|
24261
|
-
|
|
24262
|
-
|
|
24263
|
-
|
|
24505
|
+
} else {
|
|
24506
|
+
reportFiltered(`workers:${workers.providerName}`, `script=${script}`, deploySplit.filtered, input.deployFilter, rows, print);
|
|
24507
|
+
for (const key of deploySplit.send) {
|
|
24508
|
+
rows.push(await pushRow(`workers:${workers.providerName}`, `script=${script}`, key, envVars, dryRun, async (value) => {
|
|
24509
|
+
await workers.setSecret(script, key, value);
|
|
24510
|
+
}));
|
|
24511
|
+
print(formatRow(rows[rows.length - 1]));
|
|
24512
|
+
}
|
|
24264
24513
|
}
|
|
24265
24514
|
}
|
|
24266
24515
|
return summarise(rows, logger, print, dryRun);
|
|
24267
24516
|
}
|
|
24517
|
+
/**
|
|
24518
|
+
* Record the vault keys a deployment or Worker filter left out: one skipped row each (names only; the value is never
|
|
24519
|
+
* read for them) and one line naming them all, so the dry run and the real run show what stayed behind.
|
|
24520
|
+
*/
|
|
24521
|
+
function reportFiltered(destination, scope, filtered, filter, rows, print) {
|
|
24522
|
+
const allowed = [...filter.prefixes.map((p) => `${p}*`), ...filter.keys].join(", ");
|
|
24523
|
+
for (const key of filtered) rows.push({
|
|
24524
|
+
destination,
|
|
24525
|
+
scope,
|
|
24526
|
+
key,
|
|
24527
|
+
status: "skip",
|
|
24528
|
+
message: `filtered: not in repo.secrets.deploy (${allowed})`
|
|
24529
|
+
});
|
|
24530
|
+
if (filtered.length > 0) print(style.dim(` · not sent (${filtered.length}, outside ${allowed}): ${filtered.join(", ")}`));
|
|
24531
|
+
}
|
|
24268
24532
|
/** Log every row, then print and log the summary. Shared by a finished run and one that stopped at the vault. */
|
|
24269
24533
|
function summarise(rows, logger, print, dryRun) {
|
|
24270
24534
|
for (const r of rows) logger[r.status === "fail" ? "warn" : "info"]({
|
|
@@ -24432,6 +24696,7 @@ const secretsSyncCommand = {
|
|
|
24432
24696
|
const routes = argv.githubSecret?.length ? [] : secretRoutes(loaded.resolved.repo?.secrets?.sync, environmentId);
|
|
24433
24697
|
const variables = variableRoutes(loaded.resolved.repo?.variables?.sync, environmentId);
|
|
24434
24698
|
const variablesOnly = variables.length > 0 && routes.length === 0 && !argv.githubSecret?.length;
|
|
24699
|
+
const deploy = deployFilter(loaded.resolved.repo?.secrets?.deploy, environmentId);
|
|
24435
24700
|
if ((await runSecretsSync({
|
|
24436
24701
|
loaded,
|
|
24437
24702
|
context: {
|
|
@@ -24443,6 +24708,7 @@ const secretsSyncCommand = {
|
|
|
24443
24708
|
environmentId,
|
|
24444
24709
|
...argv.projectId ? { projectId: argv.projectId } : {},
|
|
24445
24710
|
...argv.worker ? { workerScript: argv.worker } : {},
|
|
24711
|
+
...deploy ? { deployFilter: deploy } : {},
|
|
24446
24712
|
...argv.githubSecret?.length ? { githubSecretKeys: argv.githubSecret } : {},
|
|
24447
24713
|
githubSecretScope,
|
|
24448
24714
|
...routes.length ? { secretRoutes: routes } : variablesOnly ? { secretRoutes: [] } : {},
|