insta 0.0.64 → 0.0.65
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 +8 -0
- package/dist/commands/deploy.js +7 -1
- package/dist/commands/run.js +91 -16
- package/dist/commands/secrets.js +106 -17
- package/dist/index.js +8 -2
- package/dist/util.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,6 +119,14 @@ only. Provider-minted service credentials (`DATABASE_URL`, `BUCKET_NAME`,
|
|
|
119
119
|
`insta secrets bind` rules, and the postgres connection string is read directly with
|
|
120
120
|
`insta db url` (or `insta db connect` for a psql session).
|
|
121
121
|
|
|
122
|
+
Secrets can be scoped per compute service, so several services may each define the same name — and
|
|
123
|
+
a flat bundle cannot carry two values for one name. Such a name is **withheld** from the bundle and
|
|
124
|
+
reported on stderr (which services define it, and how to read one). `insta run` then **refuses to
|
|
125
|
+
start the command** rather than let it inherit a stale value for that name from your shell; re-run
|
|
126
|
+
it as `insta run --service compute/<name>` to inject exactly what that one service receives, or
|
|
127
|
+
`--ignore-collisions` to run with the name removed from the child environment altogether.
|
|
128
|
+
`insta secrets --service compute/<name>` reads the same scoped env into `.env`.
|
|
129
|
+
|
|
122
130
|
### Destructive actions can require approval
|
|
123
131
|
|
|
124
132
|
Agent requests are governed by the project's `agent-policy`; human requests use normal RBAC.
|
package/dist/commands/deploy.js
CHANGED
|
@@ -71,7 +71,8 @@ export async function deploy(dir, opts) {
|
|
|
71
71
|
}
|
|
72
72
|
const effOpts = { ...opts, port: port?.toString() };
|
|
73
73
|
const image = dir ? await buildFromSource(api, p.projectId, dir, branch, effOpts) : opts.image;
|
|
74
|
-
const res = await api.rawRequest('POST', `/projects/${p.projectId}/deploy`, deployRequestBody(image, branch, effOpts))
|
|
74
|
+
const res = await api.rawRequest('POST', `/projects/${p.projectId}/deploy`, deployRequestBody(image, branch, effOpts))
|
|
75
|
+
.catch((e) => { throw e instanceof ApiError && e.status === 409 ? new ApiError(e.status, repoConnectedHint(e.message), e.body) : e; });
|
|
75
76
|
if (handleApproval(res, opts.json))
|
|
76
77
|
return;
|
|
77
78
|
if (opts.json)
|
|
@@ -79,6 +80,11 @@ export async function deploy(dir, opts) {
|
|
|
79
80
|
info(`deployed ${image} -> ${res.body.url} (branch ${res.body.branch}, group ${res.body.group})`);
|
|
80
81
|
renderNextActions(res.body.nextActions);
|
|
81
82
|
}
|
|
83
|
+
// The platform refuses an image deploy onto a repo-connected service and names the body field it
|
|
84
|
+
// wants; a CLI user can only pass the flag. Pure, so it's unit-tested.
|
|
85
|
+
export function repoConnectedHint(message) {
|
|
86
|
+
return message.replace(/pass replaceSource: true/g, 'pass --replace-source');
|
|
87
|
+
}
|
|
82
88
|
// The local image tag a daemon-side deploy runs: unique per build so a redeploy replaces, and
|
|
83
89
|
// legible in `docker images`. Pure, so it's unit-tested.
|
|
84
90
|
export function localImageTag(projectId, group, now = Date.now()) {
|
package/dist/commands/run.js
CHANGED
|
@@ -4,16 +4,93 @@
|
|
|
4
4
|
// as the process does.
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { ApiClient, requireProject } from '../api.js';
|
|
7
|
-
import { CliExit, die,
|
|
7
|
+
import { CliExit, die, refuse, relayExitCode } from '../util.js';
|
|
8
|
+
import { assertServiceRef, branchHint, collisionLines, fetchSecretBundle } from './secrets.js';
|
|
9
|
+
/** The bundle read, as run does it: the same GET as `insta secrets`, general or --service. */
|
|
10
|
+
export function bundleFetcher(api, projectId, opts) {
|
|
11
|
+
return async () => {
|
|
12
|
+
const b = await fetchSecretBundle(api, projectId, opts);
|
|
13
|
+
if (!b)
|
|
14
|
+
throw new CliExit(); // gated (202): handleApproval already said how to unblock it
|
|
15
|
+
return b;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** The child's environment: the parent's, plus the bundle, MINUS every colliding name.
|
|
19
|
+
* Deleting is not belt-and-braces. A withheld name is simply ABSENT from the bundle, so the
|
|
20
|
+
* spread would let the parent's own export stand in for it — the developer who once exported
|
|
21
|
+
* codex's password would run hermes' command against it, with no sign anything was withheld.
|
|
22
|
+
*
|
|
23
|
+
* Windows needs more than an exact-key delete, for both halves. Env names there are
|
|
24
|
+
* case-insensitive; a plain JS object's keys are not, so this object can hold `Database_Url` from
|
|
25
|
+
* the shell and `DATABASE_URL` from the bundle as two keys for one variable — and CreateProcess,
|
|
26
|
+
* which does collapse them, picks. That makes a stale shell export able to beat the injected
|
|
27
|
+
* credential, which is the whole point of `insta run`, not just a hazard for a colliding name.
|
|
28
|
+
* So on win32 every name we DECIDE — injected or withheld — wins over whatever casings the parent
|
|
29
|
+
* had: the parent's are removed, then the bundle's own casing is written back. Off win32 nothing
|
|
30
|
+
* changes: POSIX names really are case-sensitive, so `Database_Url` there is a different variable
|
|
31
|
+
* that is none of our business, and collapsing the two would itself be the bug. */
|
|
32
|
+
export function childEnv(parent, bundle, collisions, platform = process.platform) {
|
|
33
|
+
const withheld = new Set(collisions.map((c) => c.name.toLowerCase()));
|
|
34
|
+
if (platform === 'win32') {
|
|
35
|
+
const env = { ...parent };
|
|
36
|
+
// Every name this run decides, whether it ends up injected or withheld.
|
|
37
|
+
const claimed = new Set([...Object.keys(bundle), ...collisions.map((c) => c.name)].map((n) => n.toLowerCase()));
|
|
38
|
+
for (const key of Object.keys(env))
|
|
39
|
+
if (claimed.has(key.toLowerCase()))
|
|
40
|
+
delete env[key];
|
|
41
|
+
// A withheld name stays gone in every casing — including one the bundle itself carried, which
|
|
42
|
+
// is a platform that answered `collisions` while still merging the values.
|
|
43
|
+
//
|
|
44
|
+
// defineProperty, not `env[k] = v`: a key of `__proto__` would otherwise set the prototype
|
|
45
|
+
// instead of creating an entry, and the secret would vanish silently. The platform's name rule
|
|
46
|
+
// (`^[A-Z][A-Z0-9_]{0,63}$`) makes that unreachable today — and that is exactly why it is worth
|
|
47
|
+
// one call rather than a trusted invariant: this CLI points at whatever `INSTA_API_URL` names,
|
|
48
|
+
// including a self-hosted insta-oss daemon whose validation is not this repo's to guarantee.
|
|
49
|
+
//
|
|
50
|
+
// The same rule is what makes two bundle keys differing ONLY by case impossible (case-differing
|
|
51
|
+
// needs a lowercase letter, which the rule forbids). If it ever loosens, this loop is where it
|
|
52
|
+
// bites: both variants would be written and Windows would resolve one of them arbitrarily.
|
|
53
|
+
for (const [k, v] of Object.entries(bundle)) {
|
|
54
|
+
if (withheld.has(k.toLowerCase()))
|
|
55
|
+
continue;
|
|
56
|
+
Object.defineProperty(env, k, { value: v, enumerable: true, configurable: true, writable: true });
|
|
57
|
+
}
|
|
58
|
+
return env;
|
|
59
|
+
}
|
|
60
|
+
const env = { ...parent, ...bundle };
|
|
61
|
+
for (const c of collisions)
|
|
62
|
+
delete env[c.name];
|
|
63
|
+
return env;
|
|
64
|
+
}
|
|
65
|
+
/** Pure: why run stopped, and the two ways forward. `branchHint` is the branch to name in the
|
|
66
|
+
* suggested commands — set only when the run was NOT on the linked branch, since a hint that
|
|
67
|
+
* drops an explicit --branch would send the user to read a different branch's secrets. */
|
|
68
|
+
export function refusalLines(collisions, branchHint) {
|
|
69
|
+
const n = collisions.length;
|
|
70
|
+
const b = branchHint ? ` --branch ${branchHint}` : '';
|
|
71
|
+
return [
|
|
72
|
+
`refusing to run: ${n} secret name${n === 1 ? '' : 's'} ${n === 1 ? 'is' : 'are'} defined by more than one service, so the bundle cannot say which value the command should get:`,
|
|
73
|
+
...collisionLines(collisions, branchHint),
|
|
74
|
+
`pick one service's env: insta run --service ${collisions[0]?.services[0] ?? '<type>/<name>'}${b} -- <cmd>`,
|
|
75
|
+
`or run without the name: insta run --ignore-collisions${b} -- <cmd>`,
|
|
76
|
+
];
|
|
77
|
+
}
|
|
8
78
|
/** Core, dependency-injected for tests: spawn cmd with the bundle in env, return its exit code. */
|
|
9
79
|
export async function runWithSecrets(cmd, args, deps) {
|
|
10
80
|
const bundle = await deps.fetchBundle();
|
|
81
|
+
const collisions = bundle.collisions ?? [];
|
|
82
|
+
if (collisions.length) {
|
|
83
|
+
// Refuse rather than warn: with the name missing from the bundle the child would silently
|
|
84
|
+
// inherit the parent's value, and even clearing it isn't enough — the child may hold a
|
|
85
|
+
// compiled-in default or load its own .env, so a missing credential need not be observable.
|
|
86
|
+
if (!deps.ignoreCollisions)
|
|
87
|
+
refuse(refusalLines(collisions, deps.branchHint));
|
|
88
|
+
process.stderr.write(`warning: --ignore-collisions — ${collisions.map((c) => c.name).join(', ')} removed from the child environment (${collisions.length} name${collisions.length === 1 ? '' : 's'} defined by more than one service)\n`);
|
|
89
|
+
}
|
|
90
|
+
const env = childEnv(process.env, bundle.secrets, collisions);
|
|
91
|
+
deps.announce?.(bundle);
|
|
11
92
|
return await new Promise((resolve, reject) => {
|
|
12
|
-
const child = (deps.spawnImpl ?? spawn)(cmd, args, {
|
|
13
|
-
stdio: 'inherit',
|
|
14
|
-
cwd: deps.cwd,
|
|
15
|
-
env: { ...process.env, ...bundle },
|
|
16
|
-
});
|
|
93
|
+
const child = (deps.spawnImpl ?? spawn)(cmd, args, { stdio: 'inherit', cwd: deps.cwd, env });
|
|
17
94
|
child.on('error', reject);
|
|
18
95
|
child.on('close', (code) => resolve(code ?? 1));
|
|
19
96
|
});
|
|
@@ -21,20 +98,18 @@ export async function runWithSecrets(cmd, args, deps) {
|
|
|
21
98
|
export async function run(cmdAndArgs, opts) {
|
|
22
99
|
const [cmd, ...rest] = cmdAndArgs;
|
|
23
100
|
if (!cmd)
|
|
24
|
-
die('usage: insta run [--branch <b>] -- <command> [args…]');
|
|
101
|
+
die('usage: insta run [--branch <b>] [--service <type/name>] -- <command> [args…]');
|
|
102
|
+
assertServiceRef(opts.service);
|
|
25
103
|
const api = await ApiClient.load();
|
|
26
104
|
const p = await requireProject();
|
|
27
105
|
const branch = opts.branch ?? p.branch;
|
|
28
106
|
const code = await runWithSecrets(cmd, rest, {
|
|
29
|
-
fetchBundle:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
process.stderr.write(`running with ${Object.keys(res.body.secrets).length} injected secrets (branch ${branch}) — nothing written to disk\n`);
|
|
36
|
-
return res.body.secrets;
|
|
37
|
-
},
|
|
107
|
+
fetchBundle: bundleFetcher(api, p.projectId, { branch, service: opts.service }),
|
|
108
|
+
ignoreCollisions: opts.ignoreCollisions,
|
|
109
|
+
branchHint: branchHint(branch, p.branch),
|
|
110
|
+
// stderr, not stdout: `insta run`'s stdout belongs entirely to the child command (that's why
|
|
111
|
+
// run has no --json — wrapping would break the child's own output contract).
|
|
112
|
+
announce: (b) => process.stderr.write(`running with ${Object.keys(b.secrets).length} injected secrets (${opts.service ? `${opts.service}, ` : ''}branch ${branch}) — nothing written to disk\n`),
|
|
38
113
|
});
|
|
39
114
|
relayExitCode(code);
|
|
40
115
|
}
|
package/dist/commands/secrets.js
CHANGED
|
@@ -3,27 +3,99 @@ import { appendFileSync, existsSync, readFileSync } from 'node:fs';
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { ApiClient, requireProject } from '../api.js';
|
|
5
5
|
import { info, printJson, serializeEnv, handleApproval, die } from '../util.js';
|
|
6
|
-
function
|
|
7
|
-
return branch ? `?branch=${encodeURIComponent(branch)}` : '';
|
|
8
|
-
}
|
|
9
|
-
// Fetch the credential bundle (the secret seam) and write it to .env (or print).
|
|
10
|
-
export async function secrets(opts) {
|
|
6
|
+
async function loadDeps() {
|
|
11
7
|
const api = await ApiClient.load();
|
|
12
8
|
const p = await requireProject();
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
return { api, projectId: p.projectId, linkedBranch: p.branch };
|
|
10
|
+
}
|
|
11
|
+
/** A `--service` that arrived empty (`--service ""`, or an unset variable in a script) is a typo,
|
|
12
|
+
* not a request: the platform 400s it, and silently falling back to the branch-wide read would
|
|
13
|
+
* answer a different question than the one asked. Fail locally, naming the shape. */
|
|
14
|
+
export function assertServiceRef(service) {
|
|
15
|
+
if (service !== undefined && service.trim() === '')
|
|
16
|
+
die('--service requires <type>/<name>, e.g. compute/api');
|
|
17
|
+
}
|
|
18
|
+
/** Query for a bundle read. `--service` asks for the env ONE compute service actually receives
|
|
19
|
+
* (unambiguous by construction, so no collision can arise); a general read asks the platform to
|
|
20
|
+
* WITHHOLD any name several services define rather than silently returning one of the values. */
|
|
21
|
+
export function bundleQuery(opts) {
|
|
22
|
+
const parts = [];
|
|
23
|
+
if (opts.branch)
|
|
24
|
+
parts.push(`branch=${encodeURIComponent(opts.branch)}`);
|
|
25
|
+
// A bare/empty --service is a 400 on the platform; the flag is only ever sent with a value.
|
|
26
|
+
if (opts.service)
|
|
27
|
+
parts.push(`service=${encodeURIComponent(opts.service)}`);
|
|
28
|
+
else
|
|
29
|
+
parts.push('on_collision=withhold');
|
|
30
|
+
return `?${parts.join('&')}`;
|
|
31
|
+
}
|
|
32
|
+
/** GET the bundle. Returns null when the platform gated the read (202). A platform that doesn't
|
|
33
|
+
* know `collisions` reads back as none.
|
|
34
|
+
*
|
|
35
|
+
* That fallback FAILS OPEN and is deliberate: such a platform also ignores `on_collision`, so it
|
|
36
|
+
* answers a colliding name with a merged value and no report, and `insta run` would spawn against
|
|
37
|
+
* it believing nothing was withheld. It is safe only by shipping order — insta-platform#388 merges
|
|
38
|
+
* before this CLI is released, so no released build ever talks to a platform without the field
|
|
39
|
+
* (repo owner's call). Do not read the `?? []` as unconditionally safe: if that ordering ever
|
|
40
|
+
* changes, this is where capability detection belongs. */
|
|
41
|
+
export async function fetchSecretBundle(api, projectId, opts) {
|
|
42
|
+
const res = await api.rawRequest('GET', `/projects/${projectId}/secrets${bundleQuery(opts)}`);
|
|
15
43
|
if (handleApproval(res, opts.json))
|
|
44
|
+
return null;
|
|
45
|
+
return { secrets: res.body.secrets, collisions: (res.body.collisions ?? []) };
|
|
46
|
+
}
|
|
47
|
+
/** The branch a remediation hint has to name: the one that was actually read, whenever that is not
|
|
48
|
+
* the linked branch. A hint that silently dropped an explicit `--branch feat-x` would send the
|
|
49
|
+
* user to read the linked branch instead — a different set of secrets, and no sign of the swap. */
|
|
50
|
+
export function branchHint(read, linked) {
|
|
51
|
+
return read && read !== linked ? read : undefined;
|
|
52
|
+
}
|
|
53
|
+
/** Pure: the report for each withheld name — who defines it, and how to read one of them. */
|
|
54
|
+
export function collisionLines(collisions, hintBranch) {
|
|
55
|
+
return collisions.flatMap((c) => [
|
|
56
|
+
`${c.name} omitted — ${c.services.length} services define it:`,
|
|
57
|
+
` ${c.services.join(', ')}`,
|
|
58
|
+
` read one with: insta secrets --service ${c.services[0] ?? '<type>/<name>'}${hintBranch ? ` --branch ${hintBranch}` : ''}`,
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
// STDERR, always: `secrets --print` writes the env to stdout and `insta run`'s stdout belongs to
|
|
62
|
+
// the child command, so a collision report on stdout would corrupt both.
|
|
63
|
+
export function warnCollisions(collisions, hintBranch) {
|
|
64
|
+
for (const line of collisionLines(collisions, hintBranch))
|
|
65
|
+
process.stderr.write(line + '\n');
|
|
66
|
+
}
|
|
67
|
+
// The same report for a machine reader, on stderr for the same reason: stdout carries the payload,
|
|
68
|
+
// which under --json is the bare `{NAME: value}` map every existing consumer parses. Nothing is
|
|
69
|
+
// written when there is nothing to choose between — a quiet stream is the signal, not `[]`.
|
|
70
|
+
export function warnCollisionsJson(collisions) {
|
|
71
|
+
if (collisions.length)
|
|
72
|
+
process.stderr.write(JSON.stringify({ collisions }) + '\n');
|
|
73
|
+
}
|
|
74
|
+
// Fetch the credential bundle (the secret seam) and write it to .env (or print). --service reads
|
|
75
|
+
// one compute service's own env instead of the branch-wide merge.
|
|
76
|
+
export async function secrets(opts, deps) {
|
|
77
|
+
assertServiceRef(opts.service);
|
|
78
|
+
const d = deps ?? (await loadDeps());
|
|
79
|
+
const branch = opts.branch ?? d.linkedBranch;
|
|
80
|
+
const b = await fetchSecretBundle(d.api, d.projectId, { branch, service: opts.service, json: opts.json });
|
|
81
|
+
if (!b)
|
|
16
82
|
return;
|
|
17
|
-
const bundle =
|
|
18
|
-
|
|
83
|
+
const bundle = b.secrets;
|
|
84
|
+
// --json's stdout stays the bare map it has always been; the collisions ride stderr as one JSON
|
|
85
|
+
// line, so a consumer that passes none of the new flags parses exactly what it parsed before.
|
|
86
|
+
if (opts.json) {
|
|
87
|
+
warnCollisionsJson(b.collisions);
|
|
19
88
|
return printJson(bundle);
|
|
89
|
+
}
|
|
90
|
+
warnCollisions(b.collisions, branchHint(branch, d.linkedBranch));
|
|
20
91
|
if (opts.print) {
|
|
21
92
|
process.stdout.write(serializeEnv(bundle));
|
|
22
93
|
return;
|
|
23
94
|
}
|
|
24
95
|
const out = opts.output ?? '.env';
|
|
25
96
|
await writeFile(out, serializeEnv(bundle));
|
|
26
|
-
|
|
97
|
+
const scope = opts.service ? `${opts.service}, branch ${branch}` : `branch ${branch}`;
|
|
98
|
+
info(`wrote ${Object.keys(bundle).length} secrets to ${out} (${scope})`);
|
|
27
99
|
if (ensureIgnored(process.cwd(), out))
|
|
28
100
|
info(` .gitignore += ${out} (credentials must never be committed)`);
|
|
29
101
|
info(' tip: `insta run -- <cmd>` injects these per-run with nothing written to disk');
|
|
@@ -94,6 +166,10 @@ async function readStdin() {
|
|
|
94
166
|
// it to a branch service instead, which implies the current branch (binding requires one). Value
|
|
95
167
|
// comes from the argument, or stdin when omitted (keeps secret values out of shell history).
|
|
96
168
|
export async function secretsSet(name, value, opts) {
|
|
169
|
+
// An empty --service must not fall through to a project-wide WRITE. The scoping test below is a
|
|
170
|
+
// truthiness check, so `--service ''` (a client interpolating an absent variable) would have put
|
|
171
|
+
// the secret at a WIDER scope than the caller asked for, visible to every service on the branch.
|
|
172
|
+
assertServiceRef(opts.service);
|
|
97
173
|
const api = await ApiClient.load();
|
|
98
174
|
const p = await requireProject();
|
|
99
175
|
const v = value ?? (await readStdin());
|
|
@@ -108,16 +184,29 @@ export async function secretsSet(name, value, opts) {
|
|
|
108
184
|
return printJson({ ok: true, name, branch: branch ?? null, service: opts.service ?? null });
|
|
109
185
|
info(`set ${name}${opts.service ? ` → ${opts.service}` : ''} (${branch ? `branch ${branch}` : 'project-wide'})`);
|
|
110
186
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
187
|
+
// Remove a user secret. --service removes only THAT service's copy (the platform has always
|
|
188
|
+
// honoured ?service= here; without the flag a name several services define stays defined).
|
|
189
|
+
export async function secretsUnset(name, opts, deps) {
|
|
190
|
+
assertServiceRef(opts.service);
|
|
191
|
+
const d = deps ?? (await loadDeps());
|
|
192
|
+
// Service scoping REQUIRES a branch (a service exists on a branch, so the platform rejects the
|
|
193
|
+
// pair without one) — so --service defaults to the linked branch, exactly as `secrets set` does.
|
|
194
|
+
const branch = opts.service ? (opts.branch ?? d.linkedBranch) : opts.branch;
|
|
195
|
+
const parts = [];
|
|
196
|
+
if (branch)
|
|
197
|
+
parts.push(`branch=${encodeURIComponent(branch)}`);
|
|
198
|
+
if (opts.service)
|
|
199
|
+
parts.push(`service=${encodeURIComponent(opts.service)}`);
|
|
200
|
+
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
201
|
+
const res = await d.api.rawRequest('DELETE', `/projects/${d.projectId}/secrets/${encodeURIComponent(name)}${qs}`);
|
|
116
202
|
if (handleApproval(res, opts.json))
|
|
117
203
|
return;
|
|
204
|
+
// The EFFECTIVE branch, not the flag: with --service and no --branch the scope that was deleted
|
|
205
|
+
// is the linked branch's, and the output has to say which scope it actually touched.
|
|
118
206
|
if (opts.json)
|
|
119
|
-
return printJson({ ok: true, name, branch: opts.
|
|
120
|
-
|
|
207
|
+
return printJson({ ok: true, name, branch: branch ?? null, service: opts.service ?? null });
|
|
208
|
+
const scope = opts.service ? `${opts.service}, branch ${branch}` : branch ? `branch ${branch}` : 'project-wide';
|
|
209
|
+
info(`unset ${name} (${scope})`);
|
|
121
210
|
}
|
|
122
211
|
export async function secretsBind(envName, source, opts) {
|
|
123
212
|
if (!opts.to)
|
package/dist/index.js
CHANGED
|
@@ -98,6 +98,8 @@ envCmd.command('use <name>').description(`Switch environment (${ENV_NAMES.join('
|
|
|
98
98
|
// ---- run (per-request secret injection — nothing written to disk) ----
|
|
99
99
|
program.command('run <cmd> [args...]').description('Run a command with the branch credential bundle injected into its environment (no .env written)')
|
|
100
100
|
.option('--branch <b>', 'branch bundle to inject (default: linked branch)')
|
|
101
|
+
.option('--service <type/name>', "inject one compute service's own slice of the branch bundle, e.g. compute/api — the unambiguous read when several services define the same name (NOT the container's env: it also carries the branch's provider credentials, which a container gets only where bound)")
|
|
102
|
+
.option('--ignore-collisions', 'run even when several services define the same name; every such name is REMOVED from the child environment (never inherited from your shell)')
|
|
101
103
|
.passThroughOptions().allowUnknownOption()
|
|
102
104
|
.action(guard((cmd, args, o) => runCmd.run([cmd, ...(args ?? [])], o)));
|
|
103
105
|
// ---- agent setup (the `curl … | sh --agents` target) ----
|
|
@@ -170,14 +172,18 @@ svc.command('secrets <type> <name>').description("List a service's secret names"
|
|
|
170
172
|
.option('--branch <b>').option('--json').action(guard((type, name, o) => services.servicesSecrets(type, name, o)));
|
|
171
173
|
// ---- secrets (seam) ----
|
|
172
174
|
const sec = program.command('secrets').description('Fetch the credential bundle (secret seam) into .env')
|
|
173
|
-
.option('--branch <branch>')
|
|
175
|
+
.option('--branch <branch>')
|
|
176
|
+
.option('--service <type/name>', "read one compute service's own slice of the bundle instead of the branch-wide merge, e.g. compute/api")
|
|
177
|
+
.option('-o, --output <file>', 'output file (default .env)').option('--print', 'print instead of writing').option('--json')
|
|
174
178
|
.action(guard((o) => secretsCmd.secrets(o)));
|
|
175
179
|
sec.command('list').description('List secret names, grouped by service').option('--branch <branch>').option('--json').action(guard((o) => secretsCmd.secretsList(o)));
|
|
176
180
|
sec.command('set <name> [value]').description('Set a user secret (project-wide; value from stdin if omitted)')
|
|
177
181
|
.option('--branch <branch>', 'scope to one branch').option('--service <type/name>', 'bind to a branch service (implies current branch)')
|
|
178
182
|
.option('--json').action(guard((n, v, o) => secretsCmd.secretsSet(n, v, o)));
|
|
179
183
|
sec.command('unset <name>').description('Remove a user secret')
|
|
180
|
-
.option('--branch <branch>', 'scope to one branch')
|
|
184
|
+
.option('--branch <branch>', 'scope to one branch')
|
|
185
|
+
.option('--service <type/name>', "remove only that service's copy, e.g. compute/api")
|
|
186
|
+
.option('--json').action(guard((n, o) => secretsCmd.secretsUnset(n, o)));
|
|
181
187
|
sec.command('bind <env-name> <source>').description('Bind a service credential into a compute env var')
|
|
182
188
|
.option('--branch <branch>', 'branch (default: current)')
|
|
183
189
|
.option('--to <compute-service>', 'target compute service, e.g. compute/api')
|
package/dist/util.js
CHANGED
|
@@ -81,6 +81,16 @@ export function die(msg) {
|
|
|
81
81
|
fail(msg);
|
|
82
82
|
throw new CliExit();
|
|
83
83
|
}
|
|
84
|
+
// The CLI declined to act and the caller must choose how to proceed — the same shape as the 202
|
|
85
|
+
// approval gate below, so it takes the same exit code 2: not success (a redirected stdout must
|
|
86
|
+
// never read the refusal as output), and not a plain failure either (die owns 1). Nothing ran,
|
|
87
|
+
// and re-running with the flag the message names will work.
|
|
88
|
+
export function refuse(lines) {
|
|
89
|
+
for (const line of lines)
|
|
90
|
+
process.stderr.write(line + '\n');
|
|
91
|
+
process.exitCode = 2;
|
|
92
|
+
throw new CliExit();
|
|
93
|
+
}
|
|
84
94
|
export function printJson(v) {
|
|
85
95
|
process.stdout.write(JSON.stringify(v, null, 2) + '\n');
|
|
86
96
|
}
|