@theholocron/cli 5.0.0-alpha.413 → 5.0.0-alpha.415
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 -130
- package/dist/cli.mjs.map +1 -1
- package/dist/{config-system-DYqb53Rd.mjs → config-system-CZVj19gs.mjs} +160 -13
- package/dist/{index-D39ic8yM.d.mts → index-C4pFARzT.d.mts} +43 -5
- 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 +4 -4
- package/dist/presets.mjs +5 -5
- package/package.json +8 -8
package/dist/cli.mjs
CHANGED
|
@@ -122,9 +122,53 @@ var MissingTokenError = class extends Error {
|
|
|
122
122
|
/** Lets a caller tell this error from any other by name, across package copies. */
|
|
123
123
|
name = "MissingTokenError";
|
|
124
124
|
};
|
|
125
|
+
// src/credentials-environments/layer-environment/layer-environment.ts
|
|
126
|
+
/** The layer words, in the order the docs list them. */
|
|
127
|
+
const ENVIRONMENT_LAYERS = [
|
|
128
|
+
"local",
|
|
129
|
+
"dev",
|
|
130
|
+
"ci",
|
|
131
|
+
"prod"
|
|
132
|
+
];
|
|
133
|
+
/** Whether `value` is exactly one of the layer words (case-sensitive: `Prod` is a literal Environment name). */
|
|
134
|
+
function isEnvironmentLayer(value) {
|
|
135
|
+
return typeof value === "string" && ENVIRONMENT_LAYERS.includes(value);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The Environment a layer of a repository is kept in: `<org/repo> - <layer>`. The one place the name is built, for the
|
|
139
|
+
* `credentials` providers (`environmentLayers()`) and for the config entries that name a `layer`.
|
|
140
|
+
*/
|
|
141
|
+
function layerEnvironment(slug, layer) {
|
|
142
|
+
return `${slug} - ${layer}`;
|
|
143
|
+
}
|
|
144
|
+
// src/config/validate-environment-choice/validate-environment-choice.ts
|
|
145
|
+
/**
|
|
146
|
+
* Check that an entry names its vault Environment one way: a literal `environment`, or a `layer` the name is derived
|
|
147
|
+
* from (spec `tech-environment-layers`, #2069). Both together are an error, and so is a `layer` that is not a layer word
|
|
148
|
+
* or an `environment` that is blank. With neither, the entry is an error unless `required` is false.
|
|
149
|
+
*
|
|
150
|
+
* @param entry - The `environment` and `layer` the entry sets.
|
|
151
|
+
* @param what - How a message names the entry, e.g. "a `repo.secrets.deploy` entry".
|
|
152
|
+
* @param required - Whether the entry must name one of the two. Default true.
|
|
153
|
+
* @returns What the entry names (the environment, else the layer), for the rest of its messages; `undefined` for neither.
|
|
154
|
+
* @throws {ConfigError} Naming the entry and the problem.
|
|
155
|
+
*/
|
|
156
|
+
function validateEnvironmentChoice(entry, what, required = true) {
|
|
157
|
+
const { environment, layer } = entry;
|
|
158
|
+
if (environment !== void 0 && layer !== void 0) throw new ConfigError(`${what} sets both \`layer\` and \`environment\`: name the Environment one way`);
|
|
159
|
+
if (layer !== void 0) {
|
|
160
|
+
if (!isEnvironmentLayer(layer)) throw new ConfigError(`${what} has \`layer\` ${JSON.stringify(layer)}: use ${ENVIRONMENT_LAYERS.map((l) => `"${l}"`).join(", ")}, or \`environment\` for a literal name`);
|
|
161
|
+
return layer;
|
|
162
|
+
}
|
|
163
|
+
if (environment !== void 0) {
|
|
164
|
+
if (typeof environment !== "string" || environment.trim() === "") throw new ConfigError(`${what} needs the name of a vault environment, got an empty \`environment\``);
|
|
165
|
+
return environment;
|
|
166
|
+
}
|
|
167
|
+
if (required) throw new ConfigError(`${what} needs the name of a vault environment (\`environment\`) or a \`layer\``);
|
|
168
|
+
}
|
|
125
169
|
// src/config/validate-secrets-deploy/validate-secrets-deploy.ts
|
|
126
170
|
/**
|
|
127
|
-
* Check `repo.secrets.deploy`: each entry names a vault environment and at least one of a non-empty `keys` list and a
|
|
171
|
+
* Check `repo.secrets.deploy`: each entry names a vault environment (or a `layer`) and at least one of a non-empty `keys` list and a
|
|
128
172
|
* non-empty `prefix`. An entry with neither would mean "all keys", which a deployment never gets (spec
|
|
129
173
|
* `tech-deployment-key-allowlist`, #2061), so it is an error here and not a silent skip.
|
|
130
174
|
*
|
|
@@ -133,14 +177,25 @@ var MissingTokenError = class extends Error {
|
|
|
133
177
|
*/
|
|
134
178
|
function validateSecretsDeploy(secrets) {
|
|
135
179
|
for (const entry of secrets?.deploy ?? []) {
|
|
136
|
-
|
|
137
|
-
const label = `\`repo.secrets.deploy\` entry for ${JSON.stringify(
|
|
180
|
+
const named = validateEnvironmentChoice(entry, "a `repo.secrets.deploy` entry");
|
|
181
|
+
const label = `\`repo.secrets.deploy\` entry for ${JSON.stringify(named)}`;
|
|
138
182
|
const { keys, prefix } = entry;
|
|
139
183
|
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
184
|
if (prefix !== void 0 && (typeof prefix !== "string" || prefix === "")) throw new ConfigError(`${label} has an empty \`prefix\``);
|
|
141
185
|
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
186
|
}
|
|
143
187
|
}
|
|
188
|
+
// src/config/validate-secrets-sync/validate-secrets-sync.ts
|
|
189
|
+
/**
|
|
190
|
+
* Check `repo.secrets.sync`: each entry names its vault environment one way, a literal `environment` or a `layer`
|
|
191
|
+
* (spec `tech-environment-layers`, #2069).
|
|
192
|
+
*
|
|
193
|
+
* @param secrets - `repo.secrets`, if the config has it.
|
|
194
|
+
* @throws {ConfigError} Naming the first problem found.
|
|
195
|
+
*/
|
|
196
|
+
function validateSecretsSync(secrets) {
|
|
197
|
+
for (const entry of secrets?.sync ?? []) validateEnvironmentChoice(entry, "a `repo.secrets.sync` entry");
|
|
198
|
+
}
|
|
144
199
|
// src/config/validate-variables-sync/validate-variables-sync.ts
|
|
145
200
|
/** GitHub treats variable names as case-insensitive, so every comparison goes through this. */
|
|
146
201
|
const key = (name) => name.toUpperCase();
|
|
@@ -157,8 +212,8 @@ function validateVariablesSync(variables) {
|
|
|
157
212
|
if (!entries || entries.length === 0) return;
|
|
158
213
|
if (variables?.prune === true) throw new ConfigError("`repo.variables.prune` cannot be combined with `repo.variables.sync`: pruning would delete the variables the sync writes");
|
|
159
214
|
for (const entry of entries) {
|
|
160
|
-
|
|
161
|
-
const label = `\`repo.variables.sync\` entry for ${JSON.stringify(
|
|
215
|
+
const named = validateEnvironmentChoice(entry, "a `repo.variables.sync` entry");
|
|
216
|
+
const label = `\`repo.variables.sync\` entry for ${JSON.stringify(named)}`;
|
|
162
217
|
if (!Array.isArray(entry.keys) || entry.keys.length === 0 || entry.keys.some((k) => typeof k !== "string" || k === "")) throw new ConfigError(`${label} needs \`keys\`, a list of variable names`);
|
|
163
218
|
const scope = entry.scope ?? "repo";
|
|
164
219
|
const org = scope.startsWith("org=") ? scope.slice(4) : void 0;
|
|
@@ -239,14 +294,11 @@ const HOSTNAME = /^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0
|
|
|
239
294
|
function validateGitHubApps(apps) {
|
|
240
295
|
if (!Array.isArray(apps)) throw new ConfigError$1("`githubApps` must be a list of { name, manifest, environment }");
|
|
241
296
|
apps.forEach((app, idx) => {
|
|
242
|
-
for (const key of [
|
|
243
|
-
"name",
|
|
244
|
-
"manifest",
|
|
245
|
-
"environment"
|
|
246
|
-
]) {
|
|
297
|
+
for (const key of ["name", "manifest"]) {
|
|
247
298
|
const value = app?.[key];
|
|
248
299
|
if (typeof value !== "string" || value.trim() === "") throw new ConfigError$1(`\`githubApps[${idx}].${key}\` must be a non-empty string`);
|
|
249
300
|
}
|
|
301
|
+
validateEnvironmentChoice(app, `\`githubApps[${idx}]\``);
|
|
250
302
|
});
|
|
251
303
|
}
|
|
252
304
|
/** Throws a {@link ConfigError} naming the first thing wrong with the `ideas` block. */
|
|
@@ -263,7 +315,7 @@ function validateIdeas(ideas) {
|
|
|
263
315
|
/** Throws a {@link ConfigError} naming the first thing wrong with the `dev` block. */
|
|
264
316
|
function validateDev(dev) {
|
|
265
317
|
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
|
|
266
|
-
|
|
318
|
+
validateEnvironmentChoice(dev, "`dev`", false);
|
|
267
319
|
if (dev.tunnel !== void 0) {
|
|
268
320
|
if (!nonEmpty(dev.tunnel.name)) throw new ConfigError$1("`dev.tunnel.name` must be a name, got an empty value");
|
|
269
321
|
if (typeof dev.tunnel.hostname !== "string" || !HOSTNAME.test(dev.tunnel.hostname)) throw new ConfigError$1(`\`dev.tunnel.hostname\` must be a hostname such as sentinel-dev.example.dev (no scheme or path), got ${JSON.stringify(dev.tunnel.hostname)}`);
|
|
@@ -278,6 +330,11 @@ function validateDev(dev) {
|
|
|
278
330
|
if (serve.logging !== void 0 && !(nonEmpty(serve.logging.tokenVar) && nonEmpty(serve.logging.datasetVar))) throw new ConfigError$1("`dev.serve.logging` needs a `tokenVar` and a `datasetVar`, both variable names");
|
|
279
331
|
}
|
|
280
332
|
}
|
|
333
|
+
/** Throws a {@link ConfigError} when the `vault` entry's options name an Environment two ways, or a `layer` that is no layer word. */
|
|
334
|
+
function validateVaultLayer(entry) {
|
|
335
|
+
if (entry?.cardinality !== "single") return;
|
|
336
|
+
validateEnvironmentChoice(entry.tuple.options, "the `vault` provider's options", false);
|
|
337
|
+
}
|
|
281
338
|
/** The values `repoValidation.docsCoverage` accepts. */
|
|
282
339
|
const DOCS_COVERAGE_MODES = [
|
|
283
340
|
"off",
|
|
@@ -319,6 +376,8 @@ function resolveConfig(raw) {
|
|
|
319
376
|
if (raw.ideas !== void 0) validateIdeas(raw.ideas);
|
|
320
377
|
validateVariablesSync(raw.repo?.variables);
|
|
321
378
|
validateSecretsDeploy(raw.repo?.secrets);
|
|
379
|
+
validateSecretsSync(raw.repo?.secrets);
|
|
380
|
+
validateVaultLayer(providers.vault);
|
|
322
381
|
const credentialsEntry = providers.credentials;
|
|
323
382
|
if (credentialsEntry?.cardinality === "many") for (const tuple of credentialsEntry.tuples) {
|
|
324
383
|
const own = tuple.options.environment;
|
|
@@ -364,7 +423,11 @@ function resolveConfig(raw) {
|
|
|
364
423
|
function mergeSync(a, b) {
|
|
365
424
|
const merged = /* @__PURE__ */ new Map();
|
|
366
425
|
for (const entry of [...a ?? [], ...b ?? []]) {
|
|
367
|
-
const id =
|
|
426
|
+
const id = JSON.stringify([
|
|
427
|
+
entry.environment,
|
|
428
|
+
entry.layer,
|
|
429
|
+
entry.scope ?? "repo"
|
|
430
|
+
]);
|
|
368
431
|
const have = merged.get(id);
|
|
369
432
|
merged.set(id, have ? {
|
|
370
433
|
...have,
|
|
@@ -667,6 +730,165 @@ function placeAreas(areas, raw) {
|
|
|
667
730
|
else if (area.area === "org") result = placeOrg(result, area);
|
|
668
731
|
return result;
|
|
669
732
|
}
|
|
733
|
+
// src/credentials-environments/environment-layers/environment-layers.ts
|
|
734
|
+
/** The suffix each layer's Environment carries: `<org/repo> - <suffix>`. `test` has none. */
|
|
735
|
+
const SUFFIX = {
|
|
736
|
+
local: "local",
|
|
737
|
+
development: "dev",
|
|
738
|
+
ci: "ci",
|
|
739
|
+
production: "prod"
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* The Environments a layer reads, in the order they are tried (#2063, #2058). A machine (`local`) reads
|
|
743
|
+
* `<slug> - local` and then `<slug> - dev`: that is the only fallback there is. `development` reads `- dev`, `ci`
|
|
744
|
+
* reads `- ci` and `production` reads `- prod`; a missing name is a missing name. `test` reads none. Only `- local`
|
|
745
|
+
* is optional.
|
|
746
|
+
*/
|
|
747
|
+
function environmentLayers(slug, layer) {
|
|
748
|
+
if (layer === "test") return [];
|
|
749
|
+
const candidate = (suffix, optional) => ({
|
|
750
|
+
name: layerEnvironment(slug, suffix),
|
|
751
|
+
optional,
|
|
752
|
+
legacy: false
|
|
753
|
+
});
|
|
754
|
+
return layer === "local" ? [candidate(SUFFIX.local, true), candidate(SUFFIX.development, false)] : [candidate(SUFFIX[layer], false)];
|
|
755
|
+
}
|
|
756
|
+
// src/credentials-environments/repo-slug/repo-slug.ts
|
|
757
|
+
/**
|
|
758
|
+
* The `<org>/<repo>` of the repository at `cwd`, from its `origin` remote. A remote that is missing or cannot be
|
|
759
|
+
* parsed is a `ConfigError` that names the `environment` option as the fix.
|
|
760
|
+
*/
|
|
761
|
+
async function repoSlug(cwd, exec) {
|
|
762
|
+
const remote = await readGitRemote(cwd, exec ? { exec } : {});
|
|
763
|
+
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.`);
|
|
764
|
+
return remote.slug;
|
|
765
|
+
}
|
|
766
|
+
// src/credentials-environments/legacy-environments/legacy-environments.ts
|
|
767
|
+
const OLD_NAMES = ["Holocron", "Holocron - GitHub Actions variables"];
|
|
768
|
+
/** The old Environment names, as candidates that are never reported when absent. */
|
|
769
|
+
function legacyEnvironments() {
|
|
770
|
+
return OLD_NAMES.map((name) => ({
|
|
771
|
+
name,
|
|
772
|
+
optional: true,
|
|
773
|
+
legacy: true
|
|
774
|
+
}));
|
|
775
|
+
}
|
|
776
|
+
// src/credentials-environments/resolve-environments/resolve-environments.ts
|
|
777
|
+
/**
|
|
778
|
+
* The Environments one `credentials` entry reads. An explicit name (the entry's `environment` option, else the shared
|
|
779
|
+
* `credentials.environment`) is the only candidate and wins. Otherwise a deriving provider gets the names of its layer
|
|
780
|
+
* (`environmentLayers()`) from the repo's `origin` and `detectEnvironment()`, followed by the migration fallback.
|
|
781
|
+
* Nothing is read from a provider here. An empty list means there is nothing to read (the `test` layer).
|
|
782
|
+
*/
|
|
783
|
+
async function resolveEnvironments(provider, explicit, input) {
|
|
784
|
+
if (explicit !== void 0) return [{
|
|
785
|
+
name: explicit,
|
|
786
|
+
optional: false,
|
|
787
|
+
legacy: false
|
|
788
|
+
}];
|
|
789
|
+
if (!derivesEnvironment(provider)) return [];
|
|
790
|
+
const layer = detectEnvironment(input.env);
|
|
791
|
+
if (layer === "test") return [];
|
|
792
|
+
return [...environmentLayers(await repoSlug(input.repoRoot, input.gitExec), layer), ...legacyEnvironments()];
|
|
793
|
+
}
|
|
794
|
+
// src/credentials-environments/try-environments/try-environments.ts
|
|
795
|
+
/** A provider's "no such Environment": its API error with status 404 (`ProviderApiError`, matched by shape). */
|
|
796
|
+
function isNotFound(err) {
|
|
797
|
+
return typeof err === "object" && err !== null && err.status === 404;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Calls `attempt` for each candidate and sorts the answers into found and missing. A 404 is a miss; any other error
|
|
801
|
+
* is thrown. A missing optional Environment is silent. When a required one is missing, the legacy candidates
|
|
802
|
+
* (migration only, #2063) are tried too, and if one exists the miss is forgiven.
|
|
803
|
+
*/
|
|
804
|
+
async function tryEnvironments(candidates, attempt) {
|
|
805
|
+
const found = [];
|
|
806
|
+
const missing = [];
|
|
807
|
+
const ask = async (candidate) => {
|
|
808
|
+
try {
|
|
809
|
+
found.push({
|
|
810
|
+
name: candidate.name,
|
|
811
|
+
legacy: candidate.legacy,
|
|
812
|
+
result: await attempt(candidate.name)
|
|
813
|
+
});
|
|
814
|
+
} catch (err) {
|
|
815
|
+
if (!isNotFound(err)) throw err;
|
|
816
|
+
if (!candidate.optional) missing.push(candidate.name);
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
for (const candidate of candidates.filter((c) => !c.legacy)) await ask(candidate);
|
|
820
|
+
if (missing.length > 0) {
|
|
821
|
+
const before = found.length;
|
|
822
|
+
for (const candidate of candidates.filter((c) => c.legacy)) await ask(candidate);
|
|
823
|
+
if (found.length > before) missing.length = 0;
|
|
824
|
+
}
|
|
825
|
+
return {
|
|
826
|
+
found,
|
|
827
|
+
missing
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
// src/config/resolve-layers/resolve-layers.ts
|
|
831
|
+
/**
|
|
832
|
+
* Turns every `layer` in a loaded config into the `environment` it names (spec `tech-environment-layers`, #2069), so
|
|
833
|
+
* the commands and doctors that read Environments see one literal name and none of them derives it again. The name is
|
|
834
|
+
* `layerEnvironment()` over the `origin` remote of `input.repoRoot`, read at most once and only when an entry names a
|
|
835
|
+
* layer. A remote that cannot be read is a `ConfigError` naming the `environment` option (`repoSlug()`); nothing is
|
|
836
|
+
* guessed. Covers `repo.secrets.sync`, `repo.secrets.deploy`, `repo.variables.sync`, `githubApps`, `dev` and the
|
|
837
|
+
* `vault` provider's `layer` option. Returns a new config; the one passed in is not changed.
|
|
838
|
+
*
|
|
839
|
+
* @param config - The resolved config, validated by `resolveConfig()`.
|
|
840
|
+
* @param input - Where to read the remote, and how.
|
|
841
|
+
* @returns The config with each `layer` replaced by its `environment`.
|
|
842
|
+
*/
|
|
843
|
+
async function resolveLayers(config, input) {
|
|
844
|
+
let slug;
|
|
845
|
+
const named = async (entry) => {
|
|
846
|
+
if (entry.layer === void 0) return entry;
|
|
847
|
+
const { layer, ...rest } = entry;
|
|
848
|
+
slug ??= repoSlug(input.repoRoot, input.gitExec);
|
|
849
|
+
return {
|
|
850
|
+
...rest,
|
|
851
|
+
environment: layerEnvironment(await slug, layer)
|
|
852
|
+
};
|
|
853
|
+
};
|
|
854
|
+
const all = (list) => Promise.all(list.map(named));
|
|
855
|
+
const out = { ...config };
|
|
856
|
+
const { repo } = config;
|
|
857
|
+
if (repo) {
|
|
858
|
+
const next = { ...repo };
|
|
859
|
+
if (repo.secrets) {
|
|
860
|
+
next.secrets = { ...repo.secrets };
|
|
861
|
+
if (repo.secrets.sync) next.secrets.sync = await all(repo.secrets.sync);
|
|
862
|
+
if (repo.secrets.deploy) next.secrets.deploy = await all(repo.secrets.deploy);
|
|
863
|
+
}
|
|
864
|
+
if (repo.variables?.sync) next.variables = {
|
|
865
|
+
...repo.variables,
|
|
866
|
+
sync: await all(repo.variables.sync)
|
|
867
|
+
};
|
|
868
|
+
out.repo = next;
|
|
869
|
+
}
|
|
870
|
+
if (config.githubApps) out.githubApps = await all(config.githubApps);
|
|
871
|
+
if (config.dev) out.dev = await named(config.dev);
|
|
872
|
+
const vault = config.providers.vault;
|
|
873
|
+
if (vault?.cardinality === "single" && vault.tuple.options.layer !== void 0) {
|
|
874
|
+
const { layer, ...options } = vault.tuple.options;
|
|
875
|
+
const resolved = await named({ layer });
|
|
876
|
+
out.providers = {
|
|
877
|
+
...config.providers,
|
|
878
|
+
vault: {
|
|
879
|
+
cardinality: "single",
|
|
880
|
+
tuple: {
|
|
881
|
+
...vault.tuple,
|
|
882
|
+
options: {
|
|
883
|
+
...options,
|
|
884
|
+
environment: resolved.environment
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
return out;
|
|
891
|
+
}
|
|
670
892
|
// src/config/config-system.ts
|
|
671
893
|
/**
|
|
672
894
|
* Holocron's config system: `defineConfig`, `loadConfig` and `compose`, all built from one
|
|
@@ -700,9 +922,34 @@ system$1.defineConfig;
|
|
|
700
922
|
* `@theholocron/datapad`'s own doc comment for the stop conditions).
|
|
701
923
|
* Throws `ConfigFileError` when nothing is found or a file cannot
|
|
702
924
|
* be loaded, or `ConfigError` when the config fails schema checks.
|
|
925
|
+
*
|
|
926
|
+
* Every `layer` an entry names becomes the `environment` it stands for (`resolveLayers()`, spec
|
|
927
|
+
* `tech-environment-layers`, #2069), read from the `origin` remote at `cwd`; `input` lets a test pass a fake remote.
|
|
703
928
|
*/
|
|
704
|
-
|
|
929
|
+
async function loadConfig(cwd, input = {}) {
|
|
930
|
+
const loaded = await system$1.loadConfig(cwd);
|
|
931
|
+
return {
|
|
932
|
+
...loaded,
|
|
933
|
+
resolved: await resolveLayers(loaded.resolved, {
|
|
934
|
+
repoRoot: cwd,
|
|
935
|
+
...input
|
|
936
|
+
})
|
|
937
|
+
};
|
|
938
|
+
}
|
|
705
939
|
system$1.compose;
|
|
940
|
+
// src/config/resolved-environment/resolved-environment.ts
|
|
941
|
+
/**
|
|
942
|
+
* The vault Environment a loaded config entry names. `loadConfig()` has already turned every `layer` into an
|
|
943
|
+
* `environment` (`resolveLayers()`), so a missing one means the config did not come through it; that is an error, never
|
|
944
|
+
* a guess (spec `tech-environment-layers`, #2069).
|
|
945
|
+
*
|
|
946
|
+
* @param entry - A `repo.secrets.sync`, `repo.secrets.deploy`, `repo.variables.sync` or `githubApps` entry.
|
|
947
|
+
* @throws {ConfigError} When the entry still has no `environment`.
|
|
948
|
+
*/
|
|
949
|
+
function resolvedEnvironment(entry) {
|
|
950
|
+
if (entry.environment === void 0) throw new ConfigError(`an entry names the layer ${JSON.stringify(entry.layer)} but its Environment was not derived: load the config with loadConfig()`);
|
|
951
|
+
return entry.environment;
|
|
952
|
+
}
|
|
706
953
|
// src/auth/auth.ts
|
|
707
954
|
/**
|
|
708
955
|
* The CLI's credentials: the OS keyring every plugin's bootstrap token lives in, and the two token resolvers built on
|
|
@@ -1013,103 +1260,6 @@ function applyResolvedConfig(argv, resolved) {
|
|
|
1013
1260
|
buildCliLogger(argv, cliLoggerOpts(argv, resolved));
|
|
1014
1261
|
applyConfig(resolved.telemetry);
|
|
1015
1262
|
}
|
|
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
|
-
}
|
|
1113
1263
|
// src/plugin/workspace/workspace.ts
|
|
1114
1264
|
/**
|
|
1115
1265
|
* The `workspace`-context guard.
|
|
@@ -4912,7 +5062,8 @@ function callerProblems(callers) {
|
|
|
4912
5062
|
const base = file.replace(/\.yml$/, "");
|
|
4913
5063
|
const prefix = base.startsWith(PREFIX$1) ? PREFIX$1 : "";
|
|
4914
5064
|
const stem = base.slice(prefix.length);
|
|
4915
|
-
|
|
5065
|
+
const oldFiles = Object.hasOwn(LEGACY_NAMES, stem) ? workflowKeys(stem).map((id) => `${prefix}${workflowFile(id)}`) : [];
|
|
5066
|
+
if (oldFiles.length > 0 && !(oldFiles.length === 1 && oldFiles[0] === file)) return [`${file}: an old caller name; the flat name is ${oldFiles.join(", ")}`];
|
|
4916
5067
|
const id = CALLER_IDS.find((candidate) => workflowFile(candidate).replace(/\.yml$/, "") === stem);
|
|
4917
5068
|
if (id === void 0) return [];
|
|
4918
5069
|
const problems = [];
|
|
@@ -6380,19 +6531,17 @@ function scrubbed(err, secrets) {
|
|
|
6380
6531
|
async function readCredentials(instance, loader) {
|
|
6381
6532
|
const vault = loader.has("vault") ? loader.get("vault") : void 0;
|
|
6382
6533
|
if (!vault?.readEnvironment) return { reason: vault ? `${vault.providerName} cannot read an environment's variables` : "needs a `vault` provider in holocron.config.ts (1password)" };
|
|
6534
|
+
const environment = resolvedEnvironment(instance);
|
|
6383
6535
|
let values;
|
|
6384
6536
|
try {
|
|
6385
|
-
values = await vault.readEnvironment(
|
|
6537
|
+
values = await vault.readEnvironment(environment);
|
|
6386
6538
|
} catch (err) {
|
|
6387
|
-
return { reason: `cannot read the "${
|
|
6539
|
+
return { reason: `cannot read the "${environment}" environment: ${errorMessage(err)}` };
|
|
6388
6540
|
}
|
|
6389
6541
|
const appId = held(values, APP_ID);
|
|
6390
6542
|
const key = held(values, PRIVATE_KEY);
|
|
6391
6543
|
const missing = [appId ? void 0 : APP_ID, key ? void 0 : PRIVATE_KEY].filter((names) => names !== void 0);
|
|
6392
|
-
if (missing.length > 0) {
|
|
6393
|
-
const named = missing.map(([preferred, older]) => `${preferred} (or ${older})`).join(" or ");
|
|
6394
|
-
return { reason: `"${instance.environment}" does not hold ${named}` };
|
|
6395
|
-
}
|
|
6544
|
+
if (missing.length > 0) return { reason: `"${environment}" does not hold ${missing.map(([preferred, older]) => `${preferred} (or ${older})`).join(" or ")}` };
|
|
6396
6545
|
const privateKey = key.includes("\n") ? key : key.replace(/\\n/g, "\n");
|
|
6397
6546
|
return { creds: {
|
|
6398
6547
|
appId: appId.trim(),
|
|
@@ -10554,7 +10703,7 @@ function splitDeployKeys(vaultKeys, filter) {
|
|
|
10554
10703
|
*/
|
|
10555
10704
|
async function deployKeyRows(entries, vault) {
|
|
10556
10705
|
const rows = [];
|
|
10557
|
-
for (const environment of [...new Set(entries.map(
|
|
10706
|
+
for (const environment of [...new Set(entries.map(resolvedEnvironment))]) {
|
|
10558
10707
|
const id = `deploy-${environment}`;
|
|
10559
10708
|
const title = `${environment} deployment receives only its keys`;
|
|
10560
10709
|
const skip = (detail) => rows.push({
|
|
@@ -10626,8 +10775,9 @@ async function syncedSecrets(entries, vault) {
|
|
|
10626
10775
|
const scopes = [];
|
|
10627
10776
|
const rows = [];
|
|
10628
10777
|
for (const entry of entries) {
|
|
10629
|
-
const
|
|
10630
|
-
const
|
|
10778
|
+
const environment = resolvedEnvironment(entry);
|
|
10779
|
+
const id = `sync-${environment}`;
|
|
10780
|
+
const title = `${environment} vault environment is synced`;
|
|
10631
10781
|
let scope;
|
|
10632
10782
|
try {
|
|
10633
10783
|
scope = parseScope(entry.scope ?? "repo");
|
|
@@ -10660,10 +10810,10 @@ async function syncedSecrets(entries, vault) {
|
|
|
10660
10810
|
else try {
|
|
10661
10811
|
scopes.push({
|
|
10662
10812
|
scope,
|
|
10663
|
-
names: Object.keys(await vault.readEnvironment(
|
|
10813
|
+
names: Object.keys(await vault.readEnvironment(environment))
|
|
10664
10814
|
});
|
|
10665
10815
|
} catch (err) {
|
|
10666
|
-
skip(missingTokenReason(err) ?? `could not read vault environment ${
|
|
10816
|
+
skip(missingTokenReason(err) ?? `could not read vault environment ${environment}: ${describeError(err)}`);
|
|
10667
10817
|
}
|
|
10668
10818
|
}
|
|
10669
10819
|
return {
|
|
@@ -10944,10 +11094,10 @@ function ownerEnvironments(config) {
|
|
|
10944
11094
|
const named = credentialsEnvironment(tuple, config);
|
|
10945
11095
|
if (named !== void 0) names.add(named);
|
|
10946
11096
|
}
|
|
10947
|
-
const instances = new Set((config.githubApps ?? []).map(
|
|
11097
|
+
const instances = new Set((config.githubApps ?? []).map(resolvedEnvironment));
|
|
10948
11098
|
for (const environment of instances) names.add(environment);
|
|
10949
11099
|
if (config.dev?.environment) names.add(config.dev.environment);
|
|
10950
|
-
for (const sync of [...config.repo?.secrets?.sync ?? [], ...config.repo?.variables?.sync ?? []]) names.add(sync
|
|
11100
|
+
for (const sync of [...config.repo?.secrets?.sync ?? [], ...config.repo?.variables?.sync ?? []]) names.add(resolvedEnvironment(sync));
|
|
10951
11101
|
return {
|
|
10952
11102
|
names: [...names],
|
|
10953
11103
|
instances
|
|
@@ -11094,7 +11244,7 @@ function syncFeeds(config) {
|
|
|
11094
11244
|
for (const entry of entries) try {
|
|
11095
11245
|
const target = feedKey(kind, parseScope(entry.scope ?? "repo"));
|
|
11096
11246
|
feeds.push({
|
|
11097
|
-
environment: entry
|
|
11247
|
+
environment: resolvedEnvironment(entry),
|
|
11098
11248
|
target,
|
|
11099
11249
|
...entry.keys ? { keys: entry.keys } : {}
|
|
11100
11250
|
});
|
|
@@ -24267,6 +24417,21 @@ const secretsListCommand = {
|
|
|
24267
24417
|
})).failed > 0) process.exitCode = 1;
|
|
24268
24418
|
}
|
|
24269
24419
|
};
|
|
24420
|
+
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
24421
|
+
/**
|
|
24422
|
+
* The vault Environment `holocron secrets sync <environmentId>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
24423
|
+
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
24424
|
+
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
24425
|
+
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
24426
|
+
*
|
|
24427
|
+
* @param id - The positional the user gave.
|
|
24428
|
+
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
24429
|
+
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
24430
|
+
*/
|
|
24431
|
+
async function resolveEnvironmentId(id, input) {
|
|
24432
|
+
if (!isEnvironmentLayer(id)) return id;
|
|
24433
|
+
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
24434
|
+
}
|
|
24270
24435
|
// src/commands/secrets-sync/secret-routes.ts
|
|
24271
24436
|
/**
|
|
24272
24437
|
* The routes into `secrets` that `repo.secrets.sync` declares for one vault environment: every entry naming it gives
|
|
@@ -24662,7 +24827,7 @@ function variableRoutes(entries, environmentId) {
|
|
|
24662
24827
|
// src/commands/secrets-sync/secrets-sync.args.ts
|
|
24663
24828
|
const secretsSyncArgs = (y) => y.positional("environmentId", {
|
|
24664
24829
|
type: "string",
|
|
24665
|
-
describe: "Vault environment
|
|
24830
|
+
describe: "Vault environment to read: a layer (local, dev, ci, prod) of this repository, or an Environment name"
|
|
24666
24831
|
}).option("project-id", {
|
|
24667
24832
|
type: "string",
|
|
24668
24833
|
describe: "Deployment project id (e.g., Vercel prj_*). Required when deployment is loaded."
|
|
@@ -24692,11 +24857,12 @@ const secretsSyncCommand = {
|
|
|
24692
24857
|
const githubSecretScope = parseScope(argv.githubSecretScope);
|
|
24693
24858
|
const [environmentId] = await promptForPositionals(getEntry("secrets sync"), argv);
|
|
24694
24859
|
const loaded = await loadConfig(argv.cwd);
|
|
24860
|
+
const environment = await resolveEnvironmentId(environmentId, { repoRoot: argv.cwd });
|
|
24695
24861
|
applyResolvedConfig(argv, loaded.resolved);
|
|
24696
|
-
const routes = argv.githubSecret?.length ? [] : secretRoutes(loaded.resolved.repo?.secrets?.sync,
|
|
24697
|
-
const variables = variableRoutes(loaded.resolved.repo?.variables?.sync,
|
|
24862
|
+
const routes = argv.githubSecret?.length ? [] : secretRoutes(loaded.resolved.repo?.secrets?.sync, environment);
|
|
24863
|
+
const variables = variableRoutes(loaded.resolved.repo?.variables?.sync, environment);
|
|
24698
24864
|
const variablesOnly = variables.length > 0 && routes.length === 0 && !argv.githubSecret?.length;
|
|
24699
|
-
const deploy = deployFilter(loaded.resolved.repo?.secrets?.deploy,
|
|
24865
|
+
const deploy = deployFilter(loaded.resolved.repo?.secrets?.deploy, environment);
|
|
24700
24866
|
if ((await runSecretsSync({
|
|
24701
24867
|
loaded,
|
|
24702
24868
|
context: {
|
|
@@ -24705,7 +24871,7 @@ const secretsSyncCommand = {
|
|
|
24705
24871
|
...tokens,
|
|
24706
24872
|
org: resolveOrg(argv, loaded.resolved)
|
|
24707
24873
|
},
|
|
24708
|
-
environmentId,
|
|
24874
|
+
environmentId: environment,
|
|
24709
24875
|
...argv.projectId ? { projectId: argv.projectId } : {},
|
|
24710
24876
|
...argv.worker ? { workerScript: argv.worker } : {},
|
|
24711
24877
|
...deploy ? { deployFilter: deploy } : {},
|