@theholocron/cli 5.0.0-alpha.425 → 5.0.0-alpha.426
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 +150 -20
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +14 -0
- package/package.json +13 -13
package/dist/cli.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import { readGitRemote, updateGitignore, upsertManagedBlock } from "@theholocron
|
|
|
21
21
|
import { bumpCatalogPins, discoverWorkspacePackages, parseCatalogs, readPackageJson, readPackageJsonSync, resolveWorkspaceGlobs } from "@theholocron/pkg-utils";
|
|
22
22
|
import { createCliLogger, createCliTelemetry } from "@theholocron/kyber/observability";
|
|
23
23
|
import { resolveAxiomFromEnv } from "@theholocron/observability/logger";
|
|
24
|
-
import { Separator, checkbox, confirm, input, select } from "@inquirer/prompts";
|
|
24
|
+
import { Separator, checkbox, confirm, input, password, select } from "@inquirer/prompts";
|
|
25
25
|
import { runCheckAgainstUrl } from "@theholocron/kyber/checks";
|
|
26
26
|
import { access, copyFile, lstat, mkdir, open, readFile, readdir, realpath, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
|
|
27
27
|
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
@@ -19776,6 +19776,9 @@ const probeArgs = (y) => y.positional("provider", {
|
|
|
19776
19776
|
}).option("copy", {
|
|
19777
19777
|
type: "boolean",
|
|
19778
19778
|
describe: "`1password export-environment`: put the variables on the clipboard instead of a file"
|
|
19779
|
+
}).option("environment", {
|
|
19780
|
+
type: "string",
|
|
19781
|
+
describe: "A probe about a token (`cloudflare token`): check the provider's token held in this vault Environment (a layer such as `ci` or `dev`, or a name)"
|
|
19779
19782
|
}).option("yes", {
|
|
19780
19783
|
type: "boolean",
|
|
19781
19784
|
default: false,
|
|
@@ -21254,6 +21257,107 @@ function listProbes(groups) {
|
|
|
21254
21257
|
}
|
|
21255
21258
|
return lines;
|
|
21256
21259
|
}
|
|
21260
|
+
// src/commands/probe/probe-token/choose-token.ts
|
|
21261
|
+
/**
|
|
21262
|
+
* Asks which token a probe that accepts one should check: the configured one, one from an Environment, or one typed in
|
|
21263
|
+
* (hidden as it is typed). Only called on a terminal when neither `--token` nor `--environment` was given.
|
|
21264
|
+
*/
|
|
21265
|
+
async function chooseToken(provider) {
|
|
21266
|
+
const how = await select({
|
|
21267
|
+
message: `Which ${provider} token should it check?`,
|
|
21268
|
+
choices: [
|
|
21269
|
+
{
|
|
21270
|
+
name: "The one this repo is configured to use",
|
|
21271
|
+
value: "configured"
|
|
21272
|
+
},
|
|
21273
|
+
{
|
|
21274
|
+
name: "One from a vault Environment (a layer such as ci or dev, or a name)",
|
|
21275
|
+
value: "environment"
|
|
21276
|
+
},
|
|
21277
|
+
{
|
|
21278
|
+
name: "Type or paste a token",
|
|
21279
|
+
value: "paste"
|
|
21280
|
+
}
|
|
21281
|
+
]
|
|
21282
|
+
});
|
|
21283
|
+
if (how === "environment") return { environment: (await input({
|
|
21284
|
+
message: "Environment (layer or name):",
|
|
21285
|
+
default: "ci"
|
|
21286
|
+
})).trim() };
|
|
21287
|
+
if (how === "paste") return { token: (await password({
|
|
21288
|
+
message: `${provider} token:`,
|
|
21289
|
+
mask: "*"
|
|
21290
|
+
})).trim() };
|
|
21291
|
+
}
|
|
21292
|
+
// src/commands/probe/probe-token/default-provider-tokens.ts
|
|
21293
|
+
/**
|
|
21294
|
+
* Reads the tokens a provider's plugin lists (its module-level `tokens`), resolving the plugin package from the
|
|
21295
|
+
* directory of the config that was loaded so a `--cwd` run finds the plugins installed there.
|
|
21296
|
+
*/
|
|
21297
|
+
function defaultProviderTokens(loaded, importer = createDefaultImporter(dirname(loaded.filepath))) {
|
|
21298
|
+
return async (provider) => (await importer(resolvePluginPackage$1(provider))).tokens ?? [];
|
|
21299
|
+
}
|
|
21300
|
+
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
21301
|
+
/**
|
|
21302
|
+
* The vault Environment `holocron sync secrets <environmentId>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
21303
|
+
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
21304
|
+
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
21305
|
+
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
21306
|
+
*
|
|
21307
|
+
* @param id - The positional the user gave.
|
|
21308
|
+
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
21309
|
+
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
21310
|
+
*/
|
|
21311
|
+
async function resolveEnvironmentId(id, input) {
|
|
21312
|
+
if (!isEnvironmentLayer(id)) return id;
|
|
21313
|
+
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
21314
|
+
}
|
|
21315
|
+
// src/commands/probe/probe-token/environment-token.ts
|
|
21316
|
+
/**
|
|
21317
|
+
* The provider's API token as held in one vault Environment, read in memory. Only an Environment this repo uses is
|
|
21318
|
+
* read: a layer word (`local`, `dev`, `ci`, `prod`) is this repo's `<org/repo> - <layer>`, and any other text must be a
|
|
21319
|
+
* name the config already names (`configured`), so a probe cannot be pointed at an Environment the repo has nothing to
|
|
21320
|
+
* do with. `local` reads the way the CLI does, `- local` over `- dev`, and `- local` may be absent.
|
|
21321
|
+
*
|
|
21322
|
+
* The variables looked for are the ones the provider's plugin lists (`HOLOCRON_CLOUDFLARE_TOKEN`, then the vendor's own
|
|
21323
|
+
* `CLOUDFLARE_API_TOKEN`); the first that holds a value wins.
|
|
21324
|
+
*
|
|
21325
|
+
* @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured, or the
|
|
21326
|
+
* Environment holds none of the variables.
|
|
21327
|
+
*/
|
|
21328
|
+
async function environmentToken(input) {
|
|
21329
|
+
if (!isEnvironmentLayer(input.environment) && !input.configured.includes(input.environment)) {
|
|
21330
|
+
const known = [...ENVIRONMENT_LAYERS, ...input.configured];
|
|
21331
|
+
throw new Error(`${input.environment} is not an Environment this repo's config names; use one of: ${known.join(", ")}`);
|
|
21332
|
+
}
|
|
21333
|
+
const read = input.vault?.readEnvironment?.bind(input.vault);
|
|
21334
|
+
if (!read) throw new Error("--environment needs a vault provider that can read an Environment (1Password); none is configured");
|
|
21335
|
+
const at = {
|
|
21336
|
+
repoRoot: input.repoRoot,
|
|
21337
|
+
gitExec: input.gitExec
|
|
21338
|
+
};
|
|
21339
|
+
const environment = await resolveEnvironmentId(input.environment, at);
|
|
21340
|
+
let values;
|
|
21341
|
+
if (input.environment === "local") {
|
|
21342
|
+
const dev = await read(await resolveEnvironmentId("dev", at));
|
|
21343
|
+
const local = await read(environment).catch(() => ({}));
|
|
21344
|
+
values = {
|
|
21345
|
+
...dev,
|
|
21346
|
+
...local
|
|
21347
|
+
};
|
|
21348
|
+
} else values = await read(environment);
|
|
21349
|
+
const names = input.tokens.flatMap((t) => [t.envName, ...t.vendorEnvName ? [t.vendorEnvName] : []]);
|
|
21350
|
+
if (names.length === 0) throw new Error(`the ${input.provider} plugin lists no token to look for`);
|
|
21351
|
+
for (const variable of names) {
|
|
21352
|
+
const token = values[variable];
|
|
21353
|
+
if (token) return {
|
|
21354
|
+
token,
|
|
21355
|
+
environment,
|
|
21356
|
+
variable
|
|
21357
|
+
};
|
|
21358
|
+
}
|
|
21359
|
+
throw new Error(`${environment} holds none of ${names.join(", ")}`);
|
|
21360
|
+
}
|
|
21257
21361
|
// src/commands/probe/references/clone-org.ts
|
|
21258
21362
|
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
21259
21363
|
const MAX_FILE_BYTES = 5242880;
|
|
@@ -21843,7 +21947,8 @@ function tasksProbes(io, names = legacyReplacements()) {
|
|
|
21843
21947
|
async function runProbeCommand(input) {
|
|
21844
21948
|
const print = input.print ?? ((line) => console.log(line));
|
|
21845
21949
|
/* v8 ignore next -- the real loader is only built outside tests, which always inject one */
|
|
21846
|
-
const
|
|
21950
|
+
const makeLoader = input.makeLoader ?? ((context) => new PluginLoader(input.loaded.resolved, context));
|
|
21951
|
+
const loader = input.loader ?? makeLoader(input.context);
|
|
21847
21952
|
await loader.load();
|
|
21848
21953
|
const groups = new Map(loader.probes());
|
|
21849
21954
|
const comlink = comlinkProbes({
|
|
@@ -21872,17 +21977,55 @@ async function runProbeCommand(input) {
|
|
|
21872
21977
|
for (const line of listProbes(/* @__PURE__ */ new Map([[input.provider, probes]]))) print(line);
|
|
21873
21978
|
return { status: "listed" };
|
|
21874
21979
|
}
|
|
21875
|
-
|
|
21980
|
+
let probe = probes[input.probe];
|
|
21876
21981
|
if (!probe) {
|
|
21877
21982
|
print(statusRow("fail", [`\`${input.provider}\` has no probe \`${input.probe}\``, `try: ${Object.keys(probes).sort().join(", ")}`]));
|
|
21878
21983
|
return { status: "fail" };
|
|
21879
21984
|
}
|
|
21880
|
-
|
|
21985
|
+
let context = input.context;
|
|
21986
|
+
let layer;
|
|
21987
|
+
if (probe.acceptsToken) {
|
|
21988
|
+
const given = context.cliTokens?.[input.provider] ?? context.cliToken;
|
|
21989
|
+
const chosen = input.environment ? { environment: input.environment } : given === void 0 ? await input.chooseToken?.(input.provider) : void 0;
|
|
21990
|
+
let override;
|
|
21991
|
+
try {
|
|
21992
|
+
if (chosen?.environment) {
|
|
21993
|
+
const found = await environmentToken({
|
|
21994
|
+
provider: input.provider,
|
|
21995
|
+
environment: chosen.environment,
|
|
21996
|
+
repoRoot: context.repoRoot,
|
|
21997
|
+
configured: ownerEnvironments(input.loaded.resolved).names,
|
|
21998
|
+
vault: loader.has("vault") ? loader.get("vault") : void 0,
|
|
21999
|
+
/* v8 ignore next -- the real importer reads installed plugin packages, which tests replace with `providerTokens` */
|
|
22000
|
+
tokens: await (input.providerTokens ?? defaultProviderTokens(input.loaded))(input.provider)
|
|
22001
|
+
});
|
|
22002
|
+
override = found.token;
|
|
22003
|
+
if (isEnvironmentLayer(chosen.environment)) layer = chosen.environment;
|
|
22004
|
+
print(statusRow("skip", ["token", `read ${found.variable} from ${found.environment}`]));
|
|
22005
|
+
} else if (chosen?.token) override = chosen.token;
|
|
22006
|
+
} catch (err) {
|
|
22007
|
+
print(statusRow("fail", [`\`${input.provider} ${input.probe}\``, commandFailureMessage(err)]));
|
|
22008
|
+
return { status: "fail" };
|
|
22009
|
+
}
|
|
22010
|
+
if (override !== void 0) {
|
|
22011
|
+
context = {
|
|
22012
|
+
...context,
|
|
22013
|
+
cliTokens: {
|
|
22014
|
+
...context.cliTokens,
|
|
22015
|
+
[input.provider]: override
|
|
22016
|
+
}
|
|
22017
|
+
};
|
|
22018
|
+
const reloaded = makeLoader(context);
|
|
22019
|
+
await reloaded.load();
|
|
22020
|
+
probe = reloaded.probes().get(input.provider)?.[input.probe] ?? probe;
|
|
22021
|
+
}
|
|
22022
|
+
}
|
|
22023
|
+
const tokens = [context.cliToken, ...Object.values(context.cliTokens ?? {})].filter((t) => typeof t === "string");
|
|
21881
22024
|
return { status: (await runProbe({
|
|
21882
22025
|
name: `${input.provider} ${input.probe}`,
|
|
21883
22026
|
provider: input.provider,
|
|
21884
22027
|
probeName: input.probe,
|
|
21885
|
-
args: input.args ?? [],
|
|
22028
|
+
args: [...input.args ?? [], ...layer ? ["--layer", layer] : []],
|
|
21886
22029
|
...input.lcov ? { lcov: input.lcov } : {},
|
|
21887
22030
|
probe,
|
|
21888
22031
|
dryRun: input.dryRun ?? false,
|
|
@@ -21925,6 +22068,8 @@ const probeCommand = {
|
|
|
21925
22068
|
...argv.lcov ? { lcov: argv.lcov } : {},
|
|
21926
22069
|
dryRun: argv.dryRun,
|
|
21927
22070
|
yes: argv.yes,
|
|
22071
|
+
...argv.environment ? { environment: argv.environment } : {},
|
|
22072
|
+
...process.stdin.isTTY ? { chooseToken } : {},
|
|
21928
22073
|
...process.stdin.isTTY ? { pick: (groups) => launchMenu(buildProbeMenuEntries(groups), argv, {
|
|
21929
22074
|
pickMessage: "probe — choose a provider:",
|
|
21930
22075
|
nonInteractiveMessage: "Run `holocron probe` to list the probes.",
|
|
@@ -24106,21 +24251,6 @@ const notificationsSyncRolesCommand = {
|
|
|
24106
24251
|
})).status === "fail") process.exitCode = 1;
|
|
24107
24252
|
}
|
|
24108
24253
|
};
|
|
24109
|
-
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
24110
|
-
/**
|
|
24111
|
-
* The vault Environment `holocron sync secrets <environmentId>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
24112
|
-
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
24113
|
-
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
24114
|
-
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
24115
|
-
*
|
|
24116
|
-
* @param id - The positional the user gave.
|
|
24117
|
-
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
24118
|
-
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
24119
|
-
*/
|
|
24120
|
-
async function resolveEnvironmentId(id, input) {
|
|
24121
|
-
if (!isEnvironmentLayer(id)) return id;
|
|
24122
|
-
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
24123
|
-
}
|
|
24124
24254
|
// src/commands/secrets-sync/secret-routes.ts
|
|
24125
24255
|
/**
|
|
24126
24256
|
* The routes into `secrets` that `repo.secrets.sync` declares for one vault environment: every entry naming it gives
|