@tinycloud/cli 1.5.0-beta.12 → 1.5.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/dist/index.js.map +1 -1
- package/dist/legacy-entry.js +274 -58
- package/dist/legacy-entry.js.map +1 -1
- package/package.json +7 -7
- package/skills/tc-cli/REFERENCE.md +22 -1
package/dist/legacy-entry.js
CHANGED
|
@@ -5733,6 +5733,7 @@ var init_dist = __esm({
|
|
|
5733
5733
|
#now;
|
|
5734
5734
|
#leaseTtlMs;
|
|
5735
5735
|
#onCommit;
|
|
5736
|
+
#contentFetch;
|
|
5736
5737
|
/** Failed repair fetches of this session, by key and ETag hash. Never persisted: a new `Replica` retries afresh. */
|
|
5737
5738
|
#repairTries = /* @__PURE__ */ new Map();
|
|
5738
5739
|
constructor(options) {
|
|
@@ -5742,6 +5743,7 @@ var init_dist = __esm({
|
|
|
5742
5743
|
this.#now = options.now ?? Date.now;
|
|
5743
5744
|
this.#leaseTtlMs = options.leaseTtlMs ?? DEFAULT_LEASE_TTL_MS;
|
|
5744
5745
|
this.#onCommit = options.onCommit;
|
|
5746
|
+
this.#contentFetch = options.contentFetch ?? "eager";
|
|
5745
5747
|
}
|
|
5746
5748
|
async #state() {
|
|
5747
5749
|
const state2 = await this.#store.open();
|
|
@@ -6070,6 +6072,7 @@ var init_dist = __esm({
|
|
|
6070
6072
|
changes[candidate.index].content = true;
|
|
6071
6073
|
return false;
|
|
6072
6074
|
});
|
|
6075
|
+
if (this.#contentFetch === "lazy") return { changes, blobs, fetched: 0 };
|
|
6073
6076
|
let fetched2 = 0;
|
|
6074
6077
|
for (let start = 0; start < needed.length; start += FETCH_CHUNK) {
|
|
6075
6078
|
const chunk = needed.slice(start, start + FETCH_CHUNK);
|
|
@@ -6089,6 +6092,7 @@ var init_dist = __esm({
|
|
|
6089
6092
|
return { changes, blobs, fetched: fetched2 };
|
|
6090
6093
|
}
|
|
6091
6094
|
async #repair(attempt, cursor, nodeDid, coverage, retentionGrantCid) {
|
|
6095
|
+
if (this.#contentFetch === "lazy") return 0;
|
|
6092
6096
|
const all = await this.#store.pendingRepairs(Number.MAX_SAFE_INTEGER);
|
|
6093
6097
|
const now = this.#now();
|
|
6094
6098
|
const pendingIds = new Set(all.map((entry) => repairId(entry)));
|
|
@@ -39188,7 +39192,7 @@ init_constants();
|
|
|
39188
39192
|
import { CLI_NAME as CLI_NAME32 } from "@tinycloud/operations/cli-name";
|
|
39189
39193
|
import { readFile as readFile14 } from "fs/promises";
|
|
39190
39194
|
import { join as join17 } from "path";
|
|
39191
|
-
import { homedir, hostname, userInfo } from "os";
|
|
39195
|
+
import { constants as osConstants, homedir, hostname, userInfo } from "os";
|
|
39192
39196
|
import { appSecretScope } from "@tinycloud/sdk-core";
|
|
39193
39197
|
import { invokeOperation as invokeOperation3 } from "@tinycloud/operations";
|
|
39194
39198
|
import { isLocalOwnerProfile as isLocalOwnerProfile4, ownerSessionLacksProof as ownerSessionLacksProof5 } from "@tinycloud/operations/profile";
|
|
@@ -39209,6 +39213,7 @@ import {
|
|
|
39209
39213
|
} from "@tinycloud/operations/secret-capabilities";
|
|
39210
39214
|
import { invokeSecretsGetWithLocalAuthorityRetry } from "@tinycloud/operations/cli-runtime";
|
|
39211
39215
|
init_sdk();
|
|
39216
|
+
init_replication_registry();
|
|
39212
39217
|
init_session_expired();
|
|
39213
39218
|
init_space();
|
|
39214
39219
|
|
|
@@ -39274,14 +39279,14 @@ function runProbeChild(request, options = {}) {
|
|
|
39274
39279
|
const args = options.argv ?? probeChildArgv(request);
|
|
39275
39280
|
const budgetMs = options.budgetMs ?? ATTEMPT_BUDGET_MS;
|
|
39276
39281
|
const killGraceMs = options.killGraceMs ?? KILL_GRACE_MS;
|
|
39277
|
-
const
|
|
39282
|
+
const spawn3 = options.spawn ?? nodeSpawn;
|
|
39278
39283
|
const signal = options.signal;
|
|
39279
39284
|
return new Promise((resolve9) => {
|
|
39280
39285
|
if (signal?.aborted) {
|
|
39281
39286
|
resolve9({ kind: "cancelled" });
|
|
39282
39287
|
return;
|
|
39283
39288
|
}
|
|
39284
|
-
const child =
|
|
39289
|
+
const child = spawn3(command, args, { env: process.env, stdio: ["ignore", "pipe", "pipe"] });
|
|
39285
39290
|
let outcome;
|
|
39286
39291
|
let stdout = Buffer.alloc(0);
|
|
39287
39292
|
let stderr = Buffer.alloc(0);
|
|
@@ -39393,6 +39398,75 @@ function parseStatusEnvelope(line) {
|
|
|
39393
39398
|
return void 0;
|
|
39394
39399
|
}
|
|
39395
39400
|
|
|
39401
|
+
// src/lib/run-command.ts
|
|
39402
|
+
import { execFileSync, spawn as spawn2 } from "child_process";
|
|
39403
|
+
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
39404
|
+
var FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];
|
|
39405
|
+
var TERMINAL_SIGNALS = { SIGINT: true, SIGQUIT: true, SIGHUP: true };
|
|
39406
|
+
function psGroupArgs(pid) {
|
|
39407
|
+
return ["-o", "pgid=", "-o", "tpgid=", "-p", String(pid)];
|
|
39408
|
+
}
|
|
39409
|
+
function parsePsGroups(output2) {
|
|
39410
|
+
const columns = output2.trim().split(/\s+/);
|
|
39411
|
+
if (columns.length !== 2) return void 0;
|
|
39412
|
+
const group = Number(columns[0]);
|
|
39413
|
+
const foreground = Number(columns[1]);
|
|
39414
|
+
return Number.isSafeInteger(group) && Number.isSafeInteger(foreground) ? { group, foreground } : void 0;
|
|
39415
|
+
}
|
|
39416
|
+
function processGroups() {
|
|
39417
|
+
try {
|
|
39418
|
+
const stat8 = readFileSync2("/proc/self/stat", "utf8");
|
|
39419
|
+
const fields = stat8.slice(stat8.lastIndexOf(")") + 2).split(" ");
|
|
39420
|
+
return { group: Number(fields[2]), foreground: Number(fields[5]) };
|
|
39421
|
+
} catch {
|
|
39422
|
+
}
|
|
39423
|
+
try {
|
|
39424
|
+
const ps = existsSync("/bin/ps") ? "/bin/ps" : "/usr/bin/ps";
|
|
39425
|
+
return parsePsGroups(execFileSync(ps, psGroupArgs(process.pid), {
|
|
39426
|
+
env: {},
|
|
39427
|
+
encoding: "utf8",
|
|
39428
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
39429
|
+
timeout: 2e3
|
|
39430
|
+
}));
|
|
39431
|
+
} catch {
|
|
39432
|
+
return void 0;
|
|
39433
|
+
}
|
|
39434
|
+
}
|
|
39435
|
+
function inTerminalForeground() {
|
|
39436
|
+
const groups = processGroups();
|
|
39437
|
+
return groups !== void 0 && groups.foreground > 0 && groups.group === groups.foreground;
|
|
39438
|
+
}
|
|
39439
|
+
function runCommand(argv, env) {
|
|
39440
|
+
return new Promise((resolve9) => {
|
|
39441
|
+
let child;
|
|
39442
|
+
try {
|
|
39443
|
+
child = spawn2(argv[0], argv.slice(1), { stdio: "inherit", env, shell: false });
|
|
39444
|
+
} catch (error) {
|
|
39445
|
+
const code5 = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
39446
|
+
resolve9({ kind: "not_started", ...code5 === void 0 ? {} : { errno: code5 } });
|
|
39447
|
+
return;
|
|
39448
|
+
}
|
|
39449
|
+
const forward = (signal) => {
|
|
39450
|
+
if (TERMINAL_SIGNALS[signal] && inTerminalForeground()) return;
|
|
39451
|
+
child.kill(signal);
|
|
39452
|
+
};
|
|
39453
|
+
for (const signal of FORWARDED_SIGNALS) process.on(signal, forward);
|
|
39454
|
+
const settle = (outcome) => {
|
|
39455
|
+
for (const signal of FORWARDED_SIGNALS) process.off(signal, forward);
|
|
39456
|
+
resolve9(outcome);
|
|
39457
|
+
};
|
|
39458
|
+
child.on("error", (error) => {
|
|
39459
|
+
if (child.pid === void 0) settle({ kind: "not_started", ...error.code === void 0 ? {} : { errno: error.code } });
|
|
39460
|
+
});
|
|
39461
|
+
child.once("exit", (code5, signal) => {
|
|
39462
|
+
settle(signal !== null ? { kind: "signaled", signal } : { kind: "exited", code: code5 ?? 1 });
|
|
39463
|
+
});
|
|
39464
|
+
});
|
|
39465
|
+
}
|
|
39466
|
+
|
|
39467
|
+
// src/commands/secrets.ts
|
|
39468
|
+
init_safe_text();
|
|
39469
|
+
|
|
39396
39470
|
// src/lib/secrets-wait.ts
|
|
39397
39471
|
init_constants();
|
|
39398
39472
|
init_errors();
|
|
@@ -40347,6 +40421,153 @@ function outputSecretDoctor(result) {
|
|
|
40347
40421
|
process.stdout.write(theme.warn(`${failed} secrets check${failed > 1 ? "s" : ""} need attention.`) + "\n");
|
|
40348
40422
|
}
|
|
40349
40423
|
}
|
|
40424
|
+
async function resolveSecretReadTarget(ctx, name, options) {
|
|
40425
|
+
const scopeOptions = resolveSecretScope(options);
|
|
40426
|
+
const legacySpaceUri = await resolveSecretSpace(options.space, ctx.profile);
|
|
40427
|
+
const resolved = resolveSecretPath2(name, scopeOptions);
|
|
40428
|
+
return { name, scopeOptions, scope: resolved.scope, legacySpaceUri, secretPath: resolved.permissionPaths.vault };
|
|
40429
|
+
}
|
|
40430
|
+
async function readSecret(params) {
|
|
40431
|
+
const { ctx, target, options } = params;
|
|
40432
|
+
const { name } = target;
|
|
40433
|
+
if (options.delegation) {
|
|
40434
|
+
const delegated = await resolveDelegatedSecretSource(
|
|
40435
|
+
options.delegation,
|
|
40436
|
+
target.secretPath,
|
|
40437
|
+
target.legacySpaceUri ?? SECRETS_SPACE2
|
|
40438
|
+
);
|
|
40439
|
+
const effectiveHost = params.host ?? delegated.delegation.host ?? ctx.host;
|
|
40440
|
+
const delegatedCtx = { ...ctx, host: effectiveHost };
|
|
40441
|
+
const local = effectiveLocal(await ProfileManager.getProfile(ctx.profile).catch(() => null), options);
|
|
40442
|
+
const node = await ensureSecretsNode(delegatedCtx, options);
|
|
40443
|
+
const value = await withSpinner(
|
|
40444
|
+
`Getting secret ${name}...`,
|
|
40445
|
+
() => readDelegatedSecretValue({
|
|
40446
|
+
node,
|
|
40447
|
+
delegation: delegated.delegation,
|
|
40448
|
+
delegationCid: delegated.delegation.cid,
|
|
40449
|
+
permissions: delegated.permissions,
|
|
40450
|
+
secretPath: target.secretPath,
|
|
40451
|
+
space: target.legacySpaceUri ?? SECRETS_SPACE2,
|
|
40452
|
+
name,
|
|
40453
|
+
...target.scope === void 0 ? {} : { scope: target.scope },
|
|
40454
|
+
local
|
|
40455
|
+
})
|
|
40456
|
+
);
|
|
40457
|
+
return { value };
|
|
40458
|
+
}
|
|
40459
|
+
const privateKey = authOptions(options)?.privateKey;
|
|
40460
|
+
const spaceUri = privateKey !== void 0 && options.space !== void 0 && !options.space.startsWith("tinycloud:") ? options.space : target.legacySpaceUri;
|
|
40461
|
+
const result = await invokeCanonicalSecretGet({
|
|
40462
|
+
ctx,
|
|
40463
|
+
name,
|
|
40464
|
+
...target.scopeOptions?.scope === void 0 ? {} : { scope: target.scopeOptions.scope },
|
|
40465
|
+
...spaceUri === void 0 ? {} : { space: spaceUri },
|
|
40466
|
+
options,
|
|
40467
|
+
label: `Getting secret ${name}...`,
|
|
40468
|
+
openKeyAcquisition: params.openKeyAcquisition
|
|
40469
|
+
});
|
|
40470
|
+
if (result.status !== "ok") {
|
|
40471
|
+
try {
|
|
40472
|
+
throwCanonicalSecretGetError(result, name);
|
|
40473
|
+
} catch (error) {
|
|
40474
|
+
throw withOperationWarnings(error, result.warnings);
|
|
40475
|
+
}
|
|
40476
|
+
}
|
|
40477
|
+
return { value: result.output.value, warnings: result.warnings };
|
|
40478
|
+
}
|
|
40479
|
+
var ENV_VAR_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
40480
|
+
function argvAfterSeparator(cmd) {
|
|
40481
|
+
let root = cmd;
|
|
40482
|
+
while (root.parent) root = root.parent;
|
|
40483
|
+
const raw = "rawArgs" in root ? root.rawArgs : void 0;
|
|
40484
|
+
if (!Array.isArray(raw)) return void 0;
|
|
40485
|
+
const args = raw.map(String);
|
|
40486
|
+
const withValue = (flag) => root.options.some((option) => option.required && (option.long === flag || option.short === flag));
|
|
40487
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
40488
|
+
const arg = args[index];
|
|
40489
|
+
if (arg === "--") return args.slice(index + 1);
|
|
40490
|
+
if (arg.startsWith("--")) {
|
|
40491
|
+
if (withValue(arg)) index += 1;
|
|
40492
|
+
continue;
|
|
40493
|
+
}
|
|
40494
|
+
if (arg.length < 2 || !arg.startsWith("-")) continue;
|
|
40495
|
+
for (let char = 1; char < arg.length; char += 1) {
|
|
40496
|
+
const option = root.options.find((candidate) => candidate.short === `-${arg[char]}`);
|
|
40497
|
+
if (option === void 0) break;
|
|
40498
|
+
if (option.required) {
|
|
40499
|
+
if (char === arg.length - 1) index += 1;
|
|
40500
|
+
break;
|
|
40501
|
+
}
|
|
40502
|
+
}
|
|
40503
|
+
}
|
|
40504
|
+
return void 0;
|
|
40505
|
+
}
|
|
40506
|
+
function secretRunPlan(cmd, operands, maps) {
|
|
40507
|
+
const usage3 = `${CLI_NAME32} secrets run NAME... [--map NAME=ENV_VAR] -- <command> [args...]`;
|
|
40508
|
+
const after = argvAfterSeparator(cmd);
|
|
40509
|
+
if (after === void 0 || after.length > operands.length) {
|
|
40510
|
+
throw new CLIError("USAGE_ERROR", `Put the command after \`--\`: ${usage3}`, ExitCode.USAGE_ERROR);
|
|
40511
|
+
}
|
|
40512
|
+
const [program, ...args] = after;
|
|
40513
|
+
if (program === void 0) {
|
|
40514
|
+
throw new CLIError("USAGE_ERROR", `Add the command to run after \`--\`: ${usage3}`, ExitCode.USAGE_ERROR);
|
|
40515
|
+
}
|
|
40516
|
+
const exports = [];
|
|
40517
|
+
for (const name of operands.slice(0, operands.length - after.length)) {
|
|
40518
|
+
if (!ENV_VAR_RE.test(name)) {
|
|
40519
|
+
throw new CLIError(
|
|
40520
|
+
"USAGE_ERROR",
|
|
40521
|
+
`${JSON.stringify(name)} can't be used as an environment variable name. Use \`--map ${name}=ENV_VAR\` to choose one.`,
|
|
40522
|
+
ExitCode.USAGE_ERROR
|
|
40523
|
+
);
|
|
40524
|
+
}
|
|
40525
|
+
exports.push({ name, variable: name });
|
|
40526
|
+
}
|
|
40527
|
+
for (const map of maps) {
|
|
40528
|
+
const equals7 = map.indexOf("=");
|
|
40529
|
+
const variable = map.slice(equals7 + 1);
|
|
40530
|
+
if (equals7 <= 0 || !ENV_VAR_RE.test(variable)) {
|
|
40531
|
+
throw new CLIError(
|
|
40532
|
+
"USAGE_ERROR",
|
|
40533
|
+
`Invalid \`--map ${JSON.stringify(map)}\`: use NAME=ENV_VAR, where ENV_VAR starts with a letter or _ and uses only letters, digits and _.`,
|
|
40534
|
+
ExitCode.USAGE_ERROR
|
|
40535
|
+
);
|
|
40536
|
+
}
|
|
40537
|
+
exports.push({ name: map.slice(0, equals7), variable });
|
|
40538
|
+
}
|
|
40539
|
+
if (exports.length === 0) {
|
|
40540
|
+
throw new CLIError("USAGE_ERROR", `Name at least one secret: ${usage3}`, ExitCode.USAGE_ERROR);
|
|
40541
|
+
}
|
|
40542
|
+
const variables = /* @__PURE__ */ new Set();
|
|
40543
|
+
for (const { variable } of exports) {
|
|
40544
|
+
if (variables.has(variable)) {
|
|
40545
|
+
throw new CLIError("USAGE_ERROR", `Two secrets are mapped to ${variable}. Give each its own variable.`, ExitCode.USAGE_ERROR);
|
|
40546
|
+
}
|
|
40547
|
+
variables.add(variable);
|
|
40548
|
+
}
|
|
40549
|
+
return { command: [program, ...args], exports };
|
|
40550
|
+
}
|
|
40551
|
+
var RERAISED_SIGNALS = {
|
|
40552
|
+
SIGINT: true,
|
|
40553
|
+
SIGTERM: true,
|
|
40554
|
+
SIGHUP: true,
|
|
40555
|
+
SIGKILL: true,
|
|
40556
|
+
SIGALRM: true,
|
|
40557
|
+
SIGUSR2: true
|
|
40558
|
+
};
|
|
40559
|
+
var TC_CREDENTIAL_VARIABLES = ["TC_PRIVATE_KEY"];
|
|
40560
|
+
function exitAsCommand(outcome, program) {
|
|
40561
|
+
if (outcome.kind === "exited") return process.exit(outcome.code);
|
|
40562
|
+
if (outcome.kind === "signaled") {
|
|
40563
|
+
if (RERAISED_SIGNALS[outcome.signal]) process.kill(process.pid, outcome.signal);
|
|
40564
|
+
return process.exit(128 + (osConstants.signals[outcome.signal] ?? 0));
|
|
40565
|
+
}
|
|
40566
|
+
const reason = outcome.errno === "ENOENT" ? "command not found" : outcome.errno === "EACCES" ? "permission denied" : `cannot run (${outcome.errno ?? "unknown error"})`;
|
|
40567
|
+
process.stderr.write(`${CLI_NAME32} secrets run: ${safeInline(program)}: ${reason}
|
|
40568
|
+
`);
|
|
40569
|
+
return process.exit(outcome.errno === "ENOENT" ? 127 : 126);
|
|
40570
|
+
}
|
|
40350
40571
|
function registerSecretsCommand(program, openKeyAcquisition) {
|
|
40351
40572
|
const secrets = program.command("secrets").description("Encrypted secrets management");
|
|
40352
40573
|
const network = secrets.command("network").description("Manage the default secrets encryption network");
|
|
@@ -40514,66 +40735,23 @@ function registerSecretsCommand(program, openKeyAcquisition) {
|
|
|
40514
40735
|
try {
|
|
40515
40736
|
const globalOpts = cmd.optsWithGlobals();
|
|
40516
40737
|
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
40517
|
-
const
|
|
40518
|
-
const legacySpaceUri = await resolveSecretSpace(options.space, ctx.profile);
|
|
40519
|
-
const secretPath = resolveSecretPath2(name, scopeOptions).permissionPaths.vault;
|
|
40738
|
+
const target = await resolveSecretReadTarget(ctx, name, options);
|
|
40520
40739
|
if (options.output) await validatePrivateOutput(options.output, "Secret output");
|
|
40740
|
+
const secret = await readSecret({ ctx, host: globalOpts.host, target, options, openKeyAcquisition });
|
|
40741
|
+
const value = secret.value;
|
|
40521
40742
|
if (options.delegation) {
|
|
40522
|
-
const delegated = await resolveDelegatedSecretSource(
|
|
40523
|
-
options.delegation,
|
|
40524
|
-
secretPath,
|
|
40525
|
-
legacySpaceUri ?? SECRETS_SPACE2
|
|
40526
|
-
);
|
|
40527
|
-
const effectiveHost = globalOpts.host ?? delegated.delegation.host ?? ctx.host;
|
|
40528
|
-
const delegatedCtx = { ...ctx, host: effectiveHost };
|
|
40529
|
-
const local = effectiveLocal(await ProfileManager.getProfile(ctx.profile).catch(() => null), options);
|
|
40530
|
-
const scope = resolveSecretPath2(name, scopeOptions).scope;
|
|
40531
|
-
const node = await ensureSecretsNode(delegatedCtx, options);
|
|
40532
|
-
const value2 = await withSpinner(
|
|
40533
|
-
`Getting secret ${name}...`,
|
|
40534
|
-
() => readDelegatedSecretValue({
|
|
40535
|
-
node,
|
|
40536
|
-
delegation: delegated.delegation,
|
|
40537
|
-
delegationCid: delegated.delegation.cid,
|
|
40538
|
-
permissions: delegated.permissions,
|
|
40539
|
-
secretPath,
|
|
40540
|
-
space: legacySpaceUri ?? SECRETS_SPACE2,
|
|
40541
|
-
name,
|
|
40542
|
-
...scope === void 0 ? {} : { scope },
|
|
40543
|
-
local
|
|
40544
|
-
})
|
|
40545
|
-
);
|
|
40546
40743
|
if (options.output) {
|
|
40547
|
-
await writePrivateOutput(options.output,
|
|
40744
|
+
await writePrivateOutput(options.output, value, "Secret output");
|
|
40548
40745
|
outputJson({ name, written: options.output });
|
|
40549
40746
|
return;
|
|
40550
40747
|
}
|
|
40551
40748
|
if (options.raw) {
|
|
40552
|
-
process.stdout.write(
|
|
40749
|
+
process.stdout.write(value);
|
|
40553
40750
|
return;
|
|
40554
40751
|
}
|
|
40555
|
-
outputJson({ name, value
|
|
40752
|
+
outputJson({ name, value });
|
|
40556
40753
|
return;
|
|
40557
40754
|
}
|
|
40558
|
-
const privateKey = authOptions(options)?.privateKey;
|
|
40559
|
-
const spaceUri = privateKey !== void 0 && options.space !== void 0 && !options.space.startsWith("tinycloud:") ? options.space : legacySpaceUri;
|
|
40560
|
-
const result = await invokeCanonicalSecretGet({
|
|
40561
|
-
ctx,
|
|
40562
|
-
name,
|
|
40563
|
-
...scopeOptions?.scope === void 0 ? {} : { scope: scopeOptions.scope },
|
|
40564
|
-
...spaceUri === void 0 ? {} : { space: spaceUri },
|
|
40565
|
-
options,
|
|
40566
|
-
label: `Getting secret ${name}...`,
|
|
40567
|
-
openKeyAcquisition
|
|
40568
|
-
});
|
|
40569
|
-
if (result.status !== "ok") {
|
|
40570
|
-
try {
|
|
40571
|
-
throwCanonicalSecretGetError(result, name);
|
|
40572
|
-
} catch (error) {
|
|
40573
|
-
throw withOperationWarnings(error, result.warnings);
|
|
40574
|
-
}
|
|
40575
|
-
}
|
|
40576
|
-
const value = result.output.value;
|
|
40577
40755
|
try {
|
|
40578
40756
|
if (options.output) {
|
|
40579
40757
|
await writePrivateOutput(options.output, value, "Secret output");
|
|
@@ -40584,9 +40762,47 @@ function registerSecretsCommand(program, openKeyAcquisition) {
|
|
|
40584
40762
|
outputJson({ name, value });
|
|
40585
40763
|
}
|
|
40586
40764
|
} catch (error) {
|
|
40587
|
-
throw withOperationWarnings(error,
|
|
40765
|
+
throw withOperationWarnings(error, secret.warnings);
|
|
40588
40766
|
}
|
|
40589
|
-
outputWarnings(operationWarnings(
|
|
40767
|
+
outputWarnings(operationWarnings(secret.warnings));
|
|
40768
|
+
} catch (error) {
|
|
40769
|
+
return handleError(error);
|
|
40770
|
+
}
|
|
40771
|
+
});
|
|
40772
|
+
secrets.command("run [names...]").description("Run a command with secrets in its environment").usage("[options] [names...] -- <command> [args...]").option(
|
|
40773
|
+
"--map <NAME=ENV_VAR>",
|
|
40774
|
+
"Give secret NAME to the command as environment variable ENV_VAR (repeatable)",
|
|
40775
|
+
(value, previous) => [...previous ?? [], value]
|
|
40776
|
+
).option("--scope <scope>", "Logical secret scope").option("--space <name|uri>", "Target a non-default secrets space (short name or full URI)").option("--delegation <source>", "Delegation file path or imported profile name").option("--private-key <hex>", "Ethereum private key (or set TC_PRIVATE_KEY)").action(async (operands, options, cmd) => {
|
|
40777
|
+
try {
|
|
40778
|
+
const plan = secretRunPlan(cmd, operands, options.map ?? []);
|
|
40779
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
40780
|
+
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
40781
|
+
const targets = [];
|
|
40782
|
+
for (const name of new Set(plan.exports.map((entry) => entry.name))) {
|
|
40783
|
+
targets.push(await resolveSecretReadTarget(ctx, name, options));
|
|
40784
|
+
}
|
|
40785
|
+
const values = /* @__PURE__ */ new Map();
|
|
40786
|
+
let warnings = [];
|
|
40787
|
+
for (const target of targets) {
|
|
40788
|
+
const secret = await readSecret({ ctx, host: globalOpts.host, target, options, openKeyAcquisition });
|
|
40789
|
+
if (secret.value.includes("\0")) {
|
|
40790
|
+
throw new CLIError(
|
|
40791
|
+
"SECRET_NOT_EXPORTABLE",
|
|
40792
|
+
`Secret "${target.name}" contains a NUL character, so it can't be put in an environment variable. The command wasn't started.`,
|
|
40793
|
+
ExitCode.ERROR
|
|
40794
|
+
);
|
|
40795
|
+
}
|
|
40796
|
+
values.set(target.name, secret.value);
|
|
40797
|
+
warnings = mergeWarnings(warnings, secret.warnings ?? []);
|
|
40798
|
+
}
|
|
40799
|
+
outputWarnings(operationWarnings(warnings));
|
|
40800
|
+
await closeReplication();
|
|
40801
|
+
const env = { ...process.env };
|
|
40802
|
+
for (const variable of TC_CREDENTIAL_VARIABLES) delete env[variable];
|
|
40803
|
+
for (const entry of plan.exports) env[entry.variable] = values.get(entry.name);
|
|
40804
|
+
values.clear();
|
|
40805
|
+
exitAsCommand(await runCommand(plan.command, env), plan.command[0]);
|
|
40590
40806
|
} catch (error) {
|
|
40591
40807
|
return handleError(error);
|
|
40592
40808
|
}
|
|
@@ -41048,7 +41264,7 @@ async function writeShareOutput(directory, filename, bytes, force) {
|
|
|
41048
41264
|
init_profiles();
|
|
41049
41265
|
|
|
41050
41266
|
// src/share/html-folder.ts
|
|
41051
|
-
import { constants as constants2, existsSync } from "fs";
|
|
41267
|
+
import { constants as constants2, existsSync as existsSync2 } from "fs";
|
|
41052
41268
|
import { lstat as lstat11, open as open14, readdir as readdir7, realpath as realpath3, stat as stat7 } from "fs/promises";
|
|
41053
41269
|
import { basename as basename5, dirname as dirname9, isAbsolute, join as join19, relative as relativePath, resolve as resolve7, sep as sep4 } from "path";
|
|
41054
41270
|
|
|
@@ -41986,7 +42202,7 @@ function isRaceError(error) {
|
|
|
41986
42202
|
}
|
|
41987
42203
|
var PROC_FD = "/proc/self/fd";
|
|
41988
42204
|
async function linuxDescriptorPath(fd) {
|
|
41989
|
-
if (process.platform !== "linux" || !
|
|
42205
|
+
if (process.platform !== "linux" || !existsSync2(PROC_FD)) return void 0;
|
|
41990
42206
|
return realpath3(`${PROC_FD}/${fd}`);
|
|
41991
42207
|
}
|
|
41992
42208
|
async function parentChainIsRealDirectories(root, path) {
|
|
@@ -43623,11 +43839,11 @@ function plural(count, label) {
|
|
|
43623
43839
|
init_theme();
|
|
43624
43840
|
init_errors();
|
|
43625
43841
|
import { execSync } from "child_process";
|
|
43626
|
-
import { readFileSync as
|
|
43842
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
43627
43843
|
var PACKAGE_NAME = "@tinycloud/cli";
|
|
43628
43844
|
function getCurrentVersion() {
|
|
43629
43845
|
const pkg = JSON.parse(
|
|
43630
|
-
|
|
43846
|
+
readFileSync3(new URL("../package.json", import.meta.url), "utf-8")
|
|
43631
43847
|
);
|
|
43632
43848
|
return pkg.version;
|
|
43633
43849
|
}
|