@theholocron/cli 5.0.0-alpha.410 → 5.0.0-alpha.411
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 +138 -13
- package/dist/cli.mjs.map +1 -1
- package/dist/{config-system-CeVFoOau.mjs → config-system-DdlsU8TW.mjs} +22 -1
- package/dist/{index-BqUevSW_.d.mts → index-D39ic8yM.d.mts} +20 -1
- package/dist/index.d.mts +2 -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 +7 -7
package/dist/cli.mjs
CHANGED
|
@@ -115,6 +115,25 @@ var MissingTokenError = class extends Error {
|
|
|
115
115
|
/** Lets a caller tell this error from any other by name, across package copies. */
|
|
116
116
|
name = "MissingTokenError";
|
|
117
117
|
};
|
|
118
|
+
// src/config/validate-secrets-deploy/validate-secrets-deploy.ts
|
|
119
|
+
/**
|
|
120
|
+
* Check `repo.secrets.deploy`: each entry names a vault environment and at least one of a non-empty `keys` list and a
|
|
121
|
+
* non-empty `prefix`. An entry with neither would mean "all keys", which a deployment never gets (spec
|
|
122
|
+
* `tech-deployment-key-allowlist`, #2061), so it is an error here and not a silent skip.
|
|
123
|
+
*
|
|
124
|
+
* @param secrets - `repo.secrets`, if the config has it.
|
|
125
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
126
|
+
*/
|
|
127
|
+
function validateSecretsDeploy(secrets) {
|
|
128
|
+
for (const entry of secrets?.deploy ?? []) {
|
|
129
|
+
if (typeof entry.environment !== "string" || entry.environment.trim() === "") throw new ConfigError("a `repo.secrets.deploy` entry needs the name of a vault environment");
|
|
130
|
+
const label = `\`repo.secrets.deploy\` entry for ${JSON.stringify(entry.environment)}`;
|
|
131
|
+
const { keys, prefix } = entry;
|
|
132
|
+
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`);
|
|
133
|
+
if (prefix !== void 0 && (typeof prefix !== "string" || prefix === "")) throw new ConfigError(`${label} has an empty \`prefix\``);
|
|
134
|
+
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`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
118
137
|
// src/config/validate-variables-sync/validate-variables-sync.ts
|
|
119
138
|
/** GitHub treats variable names as case-insensitive, so every comparison goes through this. */
|
|
120
139
|
const key = (name) => name.toUpperCase();
|
|
@@ -292,6 +311,7 @@ function resolveConfig(raw) {
|
|
|
292
311
|
if (raw.githubApps !== void 0) validateGitHubApps(raw.githubApps);
|
|
293
312
|
if (raw.ideas !== void 0) validateIdeas(raw.ideas);
|
|
294
313
|
validateVariablesSync(raw.repo?.variables);
|
|
314
|
+
validateSecretsDeploy(raw.repo?.secrets);
|
|
295
315
|
const credentialsEntry = providers.credentials;
|
|
296
316
|
if (credentialsEntry?.cardinality === "many") for (const tuple of credentialsEntry.tuples) {
|
|
297
317
|
const own = tuple.options.environment;
|
|
@@ -385,7 +405,8 @@ function mergeRepo(prev, next) {
|
|
|
385
405
|
...repo.secrets?.repo || secrets.repo ? { repo: names$1.merge(repo.secrets?.repo ?? [], secrets.repo ?? []) } : {},
|
|
386
406
|
...repo.secrets?.org || secrets.org ? { org: names$1.merge(repo.secrets?.org ?? [], secrets.org ?? []) } : {},
|
|
387
407
|
...Object.keys(environments).length > 0 ? { environments } : {},
|
|
388
|
-
...repo.secrets?.sync || secrets.sync ? { sync: mergeSync(repo.secrets?.sync, secrets.sync) } : {}
|
|
408
|
+
...repo.secrets?.sync || secrets.sync ? { sync: mergeSync(repo.secrets?.sync, secrets.sync) } : {},
|
|
409
|
+
...repo.secrets?.deploy || secrets.deploy ? { deploy: [...repo.secrets?.deploy ?? [], ...secrets.deploy ?? []] } : {}
|
|
389
410
|
};
|
|
390
411
|
}
|
|
391
412
|
if (topics) repo.topics = names$1.merge(repo.topics ?? [], topics);
|
|
@@ -10348,6 +10369,83 @@ const doctorRepoCommand = {
|
|
|
10348
10369
|
})).status === "fail") process.exitCode = 1;
|
|
10349
10370
|
}
|
|
10350
10371
|
};
|
|
10372
|
+
// src/commands/secrets-sync/deploy-filter/deploy-filter.ts
|
|
10373
|
+
/**
|
|
10374
|
+
* What `repo.secrets.deploy` lets one vault environment send to a deployment or a Worker: every entry naming it adds
|
|
10375
|
+
* its `keys` and `prefix`. `undefined` when no entry names it, which the caller turns into a `ConfigError`; there is
|
|
10376
|
+
* no default that sends everything.
|
|
10377
|
+
*
|
|
10378
|
+
* @param entries - `repo.secrets.deploy`, if the config has it.
|
|
10379
|
+
* @param environmentId - The vault environment being synced.
|
|
10380
|
+
*/
|
|
10381
|
+
function deployFilter(entries, environmentId) {
|
|
10382
|
+
const matching = (entries ?? []).filter((entry) => entry.environment === environmentId);
|
|
10383
|
+
if (matching.length === 0) return void 0;
|
|
10384
|
+
return {
|
|
10385
|
+
keys: [...new Set(matching.flatMap((entry) => entry.keys ?? []))],
|
|
10386
|
+
prefixes: [...new Set(matching.flatMap((entry) => entry.prefix ? [entry.prefix] : []))]
|
|
10387
|
+
};
|
|
10388
|
+
}
|
|
10389
|
+
// src/commands/secrets-sync/split-deploy-keys/split-deploy-keys.ts
|
|
10390
|
+
/**
|
|
10391
|
+
* Split a vault environment's key names by what a deployment may receive. A key passes when it is listed or starts
|
|
10392
|
+
* with a prefix (case-sensitive). A listed key the vault does not hold stays in `send`, so the sync reports it as
|
|
10393
|
+
* missing rather than dropping it. Only names go in and out.
|
|
10394
|
+
*
|
|
10395
|
+
* @param vaultKeys - The names the vault environment holds.
|
|
10396
|
+
* @param filter - From `deployFilter()`.
|
|
10397
|
+
*/
|
|
10398
|
+
function splitDeployKeys(vaultKeys, filter) {
|
|
10399
|
+
const passes = (key) => filter.keys.includes(key) || filter.prefixes.some((p) => key.startsWith(p));
|
|
10400
|
+
const send = vaultKeys.filter(passes);
|
|
10401
|
+
const filtered = vaultKeys.filter((key) => !passes(key));
|
|
10402
|
+
return {
|
|
10403
|
+
send: [...send, ...filter.keys.filter((key) => !vaultKeys.includes(key))],
|
|
10404
|
+
filtered
|
|
10405
|
+
};
|
|
10406
|
+
}
|
|
10407
|
+
// src/commands/doctor-secrets/deploy-key-rows.ts
|
|
10408
|
+
/**
|
|
10409
|
+
* One row per vault environment `repo.secrets.deploy` names: the key names a deployment or Worker would receive from
|
|
10410
|
+
* a `secrets sync`, and how many the filter keeps back, so a token that should not go out is visible before the
|
|
10411
|
+
* sync. Names only: the values the vault returns are dropped at once. An environment that cannot be listed (no vault,
|
|
10412
|
+
* no token, an error) is a skipped row with the reason, never a failure.
|
|
10413
|
+
*
|
|
10414
|
+
* @param entries - `repo.secrets.deploy`.
|
|
10415
|
+
* @param vault - The `vault` provider, or why there is none.
|
|
10416
|
+
*/
|
|
10417
|
+
async function deployKeyRows(entries, vault) {
|
|
10418
|
+
const rows = [];
|
|
10419
|
+
for (const environment of [...new Set(entries.map((entry) => entry.environment))]) {
|
|
10420
|
+
const id = `deploy-${environment}`;
|
|
10421
|
+
const title = `${environment} deployment receives only its keys`;
|
|
10422
|
+
const skip = (detail) => rows.push({
|
|
10423
|
+
id,
|
|
10424
|
+
title,
|
|
10425
|
+
status: "skip",
|
|
10426
|
+
detail,
|
|
10427
|
+
problems: []
|
|
10428
|
+
});
|
|
10429
|
+
const filter = deployFilter(entries, environment);
|
|
10430
|
+
if ("why" in vault) skip(vault.why);
|
|
10431
|
+
else if (!vault.readEnvironment) skip(`vault provider (${vault.providerName}) cannot list an environment's keys`);
|
|
10432
|
+
else try {
|
|
10433
|
+
const names = Object.keys(await vault.readEnvironment(environment)).sort();
|
|
10434
|
+
const { send, filtered } = splitDeployKeys(names, filter);
|
|
10435
|
+
const sends = send.filter((name) => names.includes(name));
|
|
10436
|
+
rows.push({
|
|
10437
|
+
id,
|
|
10438
|
+
title,
|
|
10439
|
+
status: "ok",
|
|
10440
|
+
detail: `sends ${sends.length} of ${names.length}: ${sends.join(", ") || "(none)"}${filtered.length > 0 ? `; keeps back ${filtered.length}: ${filtered.join(", ")}` : ""}`,
|
|
10441
|
+
problems: []
|
|
10442
|
+
});
|
|
10443
|
+
} catch (err) {
|
|
10444
|
+
skip(missingTokenReason(err) ?? `could not read vault environment ${environment}: ${describeError(err)}`);
|
|
10445
|
+
}
|
|
10446
|
+
}
|
|
10447
|
+
return rows;
|
|
10448
|
+
}
|
|
10351
10449
|
// src/commands/doctor-secrets/unique-names.ts
|
|
10352
10450
|
/** Names that differ only in case are one secret to GitHub, so the first spelling wins. */
|
|
10353
10451
|
const uniqueNames = (names) => {
|
|
@@ -10500,7 +10598,8 @@ async function runDoctorSecrets(input) {
|
|
|
10500
10598
|
});
|
|
10501
10599
|
}
|
|
10502
10600
|
const rows = [];
|
|
10503
|
-
|
|
10601
|
+
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") });
|
|
10602
|
+
if (checks.length === 0 && synced.rows.length === 0 && deployRows.length === 0) rows.push({
|
|
10504
10603
|
id: "secrets",
|
|
10505
10604
|
title: "secrets",
|
|
10506
10605
|
status: "ok",
|
|
@@ -10520,7 +10619,7 @@ async function runDoctorSecrets(input) {
|
|
|
10520
10619
|
const secrets = loader.get("secrets");
|
|
10521
10620
|
for (const check of checks) rows.push(await checkScope(secrets, check));
|
|
10522
10621
|
}
|
|
10523
|
-
rows.push(...synced.rows);
|
|
10622
|
+
rows.push(...synced.rows, ...deployRows);
|
|
10524
10623
|
printCheckRows(rows, print);
|
|
10525
10624
|
const summary = summariseChecks(rows);
|
|
10526
10625
|
printCheckSummary(summary, print);
|
|
@@ -24097,8 +24196,10 @@ function restorePem(value) {
|
|
|
24097
24196
|
*
|
|
24098
24197
|
* Per-secret routing rules:
|
|
24099
24198
|
*
|
|
24100
|
-
* -
|
|
24101
|
-
* (
|
|
24199
|
+
* - `deployment` (for each target the caller asks for, defaults: production + preview) and a Worker's secrets fail
|
|
24200
|
+
* closed (#2061): they receive only the keys `repo.secrets.deploy` names for this environment (an exact `keys`
|
|
24201
|
+
* list and/or a `prefix`), passed in as `deployFilter`. With none, the run throws a `ConfigError` before it reads
|
|
24202
|
+
* the vault. A name outside the filter is reported by name only and never reaches the provider.
|
|
24102
24203
|
* - `secrets` (GH Actions) defaults to every key, repo-scoped — but a
|
|
24103
24204
|
* caller can pass `githubSecretKeys` (an allowlist, from repeatable
|
|
24104
24205
|
* `--github-secret KEY` CLI values) to restrict `secrets` to only
|
|
@@ -24141,6 +24242,8 @@ async function runSecretsSync(input) {
|
|
|
24141
24242
|
dryRun: (input.context.dryRun ?? false) || void 0
|
|
24142
24243
|
}, "secrets sync: start");
|
|
24143
24244
|
const dryRun = input.context.dryRun ?? false;
|
|
24245
|
+
const variablesOnly = (input.variableRoutes?.length ?? 0) > 0 && input.secretRoutes?.length === 0 && !input.projectId;
|
|
24246
|
+
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
24247
|
const targets = input.targets ?? ["production", "preview"];
|
|
24145
24248
|
print(style.header(`Holocron secrets sync — environment ${input.environmentId}${dryRun ? " (dry-run)" : ""}`));
|
|
24146
24249
|
print(style.dim(` vault: ${vaultProviderName(loader)}`));
|
|
@@ -24168,6 +24271,7 @@ async function runSecretsSync(input) {
|
|
|
24168
24271
|
const keys = Object.keys(envVars).sort();
|
|
24169
24272
|
print(style.step(`read ${keys.length} keys from vault`));
|
|
24170
24273
|
print("");
|
|
24274
|
+
const deploySplit = input.deployFilter ? splitDeployKeys(keys, input.deployFilter) : void 0;
|
|
24171
24275
|
const rows = [];
|
|
24172
24276
|
if (loader.has("secrets")) {
|
|
24173
24277
|
const secrets = loader.get("secrets");
|
|
@@ -24218,7 +24322,6 @@ async function runSecretsSync(input) {
|
|
|
24218
24322
|
}
|
|
24219
24323
|
}
|
|
24220
24324
|
}
|
|
24221
|
-
const variablesOnly = variableRoutes.length > 0 && input.secretRoutes?.length === 0 && !input.projectId;
|
|
24222
24325
|
if (loader.has("deployment") && !variablesOnly) {
|
|
24223
24326
|
const deploy = loader.get("deployment");
|
|
24224
24327
|
if (!input.projectId) {
|
|
@@ -24234,8 +24337,10 @@ async function runSecretsSync(input) {
|
|
|
24234
24337
|
print(formatRow(row));
|
|
24235
24338
|
} else for (const target of targets) {
|
|
24236
24339
|
print(style.step(`deployment (target=${target})`));
|
|
24237
|
-
|
|
24238
|
-
|
|
24340
|
+
const destination = `deployment:${deploy.providerName}`;
|
|
24341
|
+
reportFiltered(destination, `target=${target}`, deploySplit.filtered, input.deployFilter, rows, print);
|
|
24342
|
+
for (const key of deploySplit.send) {
|
|
24343
|
+
rows.push(await pushRow(destination, `target=${target}`, key, envVars, dryRun, async (value) => {
|
|
24239
24344
|
await deploy.setEnvVar(input.projectId, target, key, value);
|
|
24240
24345
|
}));
|
|
24241
24346
|
print(formatRow(rows[rows.length - 1]));
|
|
@@ -24256,15 +24361,33 @@ async function runSecretsSync(input) {
|
|
|
24256
24361
|
};
|
|
24257
24362
|
rows.push(row);
|
|
24258
24363
|
print(formatRow(row));
|
|
24259
|
-
} else
|
|
24260
|
-
|
|
24261
|
-
|
|
24262
|
-
|
|
24263
|
-
|
|
24364
|
+
} else {
|
|
24365
|
+
reportFiltered(`workers:${workers.providerName}`, `script=${script}`, deploySplit.filtered, input.deployFilter, rows, print);
|
|
24366
|
+
for (const key of deploySplit.send) {
|
|
24367
|
+
rows.push(await pushRow(`workers:${workers.providerName}`, `script=${script}`, key, envVars, dryRun, async (value) => {
|
|
24368
|
+
await workers.setSecret(script, key, value);
|
|
24369
|
+
}));
|
|
24370
|
+
print(formatRow(rows[rows.length - 1]));
|
|
24371
|
+
}
|
|
24264
24372
|
}
|
|
24265
24373
|
}
|
|
24266
24374
|
return summarise(rows, logger, print, dryRun);
|
|
24267
24375
|
}
|
|
24376
|
+
/**
|
|
24377
|
+
* Record the vault keys a deployment or Worker filter left out: one skipped row each (names only; the value is never
|
|
24378
|
+
* read for them) and one line naming them all, so the dry run and the real run show what stayed behind.
|
|
24379
|
+
*/
|
|
24380
|
+
function reportFiltered(destination, scope, filtered, filter, rows, print) {
|
|
24381
|
+
const allowed = [...filter.prefixes.map((p) => `${p}*`), ...filter.keys].join(", ");
|
|
24382
|
+
for (const key of filtered) rows.push({
|
|
24383
|
+
destination,
|
|
24384
|
+
scope,
|
|
24385
|
+
key,
|
|
24386
|
+
status: "skip",
|
|
24387
|
+
message: `filtered: not in repo.secrets.deploy (${allowed})`
|
|
24388
|
+
});
|
|
24389
|
+
if (filtered.length > 0) print(style.dim(` · not sent (${filtered.length}, outside ${allowed}): ${filtered.join(", ")}`));
|
|
24390
|
+
}
|
|
24268
24391
|
/** Log every row, then print and log the summary. Shared by a finished run and one that stopped at the vault. */
|
|
24269
24392
|
function summarise(rows, logger, print, dryRun) {
|
|
24270
24393
|
for (const r of rows) logger[r.status === "fail" ? "warn" : "info"]({
|
|
@@ -24432,6 +24555,7 @@ const secretsSyncCommand = {
|
|
|
24432
24555
|
const routes = argv.githubSecret?.length ? [] : secretRoutes(loaded.resolved.repo?.secrets?.sync, environmentId);
|
|
24433
24556
|
const variables = variableRoutes(loaded.resolved.repo?.variables?.sync, environmentId);
|
|
24434
24557
|
const variablesOnly = variables.length > 0 && routes.length === 0 && !argv.githubSecret?.length;
|
|
24558
|
+
const deploy = deployFilter(loaded.resolved.repo?.secrets?.deploy, environmentId);
|
|
24435
24559
|
if ((await runSecretsSync({
|
|
24436
24560
|
loaded,
|
|
24437
24561
|
context: {
|
|
@@ -24443,6 +24567,7 @@ const secretsSyncCommand = {
|
|
|
24443
24567
|
environmentId,
|
|
24444
24568
|
...argv.projectId ? { projectId: argv.projectId } : {},
|
|
24445
24569
|
...argv.worker ? { workerScript: argv.worker } : {},
|
|
24570
|
+
...deploy ? { deployFilter: deploy } : {},
|
|
24446
24571
|
...argv.githubSecret?.length ? { githubSecretKeys: argv.githubSecret } : {},
|
|
24447
24572
|
githubSecretScope,
|
|
24448
24573
|
...routes.length ? { secretRoutes: routes } : variablesOnly ? { secretRoutes: [] } : {},
|