passport-bridge 0.48.2 → 0.49.0
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/cliHookAfter.js +10 -1
- package/dist/cliHookDecide.d.ts +9 -3
- package/dist/cliHookDecide.js +182 -28
- package/dist/cliHookSessionState.d.ts +4 -1
- package/dist/cliHookSessionState.js +1 -1
- package/dist/connectorKit/callEffects.generated.d.ts +36 -0
- package/dist/connectorKit/callEffects.generated.js +73 -0
- package/dist/connectorKit/cli.generated.js +5 -2
- package/dist/connectorKit/engine.generated.d.ts +1 -1
- package/dist/connectorKit/engine.generated.js +32 -13
- package/dist/connectorKit/githubIds.generated.d.ts +1 -1
- package/dist/connectorKit/githubIds.generated.js +3 -2
- package/dist/connectorKit/manifest.generated.d.ts +34 -14
- package/dist/connectorKit/manifests/cloudflare.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/cloudflare.generated.js +186 -0
- package/dist/connectorKit/manifests/cloudflareApi.generated.d.ts +4 -0
- package/dist/connectorKit/manifests/cloudflareApi.generated.js +207 -0
- package/dist/connectorKit/manifests/cloudflareCatalog.generated.d.ts +18 -0
- package/dist/connectorKit/manifests/cloudflareCatalog.generated.js +83 -0
- package/dist/connectorKit/manifests/cloudflareCli.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/cloudflareCli.generated.js +441 -0
- package/dist/connectorKit/manifests/githubCapture.generated.js +19 -1
- package/dist/connectorKit/manifests/githubReads.generated.js +0 -3
- package/dist/connectorKit/manifests/kubernetes.generated.d.ts +76 -0
- package/dist/connectorKit/manifests/kubernetes.generated.js +210 -0
- package/dist/connectorKit/manifests/kubernetesArgs.generated.d.ts +21 -0
- package/dist/connectorKit/manifests/kubernetesArgs.generated.js +82 -0
- package/dist/connectorKit/manifests/kubernetesCli.generated.d.ts +30 -0
- package/dist/connectorKit/manifests/kubernetesCli.generated.js +530 -0
- package/dist/connectorKit/manifests/kubernetesEffects.generated.d.ts +15 -0
- package/dist/connectorKit/manifests/kubernetesEffects.generated.js +111 -0
- package/dist/connectorKit/manifests/kubernetesObjects.generated.d.ts +24 -0
- package/dist/connectorKit/manifests/kubernetesObjects.generated.js +154 -0
- package/dist/connectorKit/manifests/railwayHooks.generated.js +11 -5
- package/dist/connectorKit/manifests/sentry.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/sentry.generated.js +27 -0
- package/dist/connectorKit/manifests/sentryApi.generated.d.ts +6 -0
- package/dist/connectorKit/manifests/sentryApi.generated.js +282 -0
- package/dist/connectorKit/manifests/sentryCapture.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/sentryCapture.generated.js +165 -0
- package/dist/connectorKit/manifests/sentryCatalog.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/sentryCatalog.generated.js +70 -0
- package/dist/connectorKit/manifests/sentryCli.generated.d.ts +2 -0
- package/dist/connectorKit/manifests/sentryCli.generated.js +230 -0
- package/dist/connectorKit/manifests/sentryIssues.generated.d.ts +20 -0
- package/dist/connectorKit/manifests/sentryIssues.generated.js +204 -0
- package/dist/connectorKit/manifests/supabase.generated.js +3 -2
- package/dist/connectorKit/manifests/supabaseApi.generated.js +52 -52
- package/dist/connectorKit/manifests/supabaseCapture.generated.js +22 -21
- package/dist/connectorKit/manifests/supabaseCatalog.generated.d.ts +2 -2
- package/dist/connectorKit/manifests/supabaseCatalog.generated.js +8 -7
- package/dist/connectorKit/manifests/supabaseCli.generated.js +32 -32
- package/dist/connectorKit/manifests/supabaseProbes.generated.js +29 -29
- package/dist/connectorKit/manifests/terraform.generated.d.ts +5 -0
- package/dist/connectorKit/manifests/terraform.generated.js +214 -0
- package/dist/connectorKit/manifests/terraformLink.generated.d.ts +30 -0
- package/dist/connectorKit/manifests/terraformLink.generated.js +73 -0
- package/dist/connectorKit/manifests/terraformPlan.generated.d.ts +48 -0
- package/dist/connectorKit/manifests/terraformPlan.generated.js +192 -0
- package/dist/connectorKit/params.generated.js +2 -0
- package/dist/connectorKit/shell.generated.d.ts +5 -1
- package/dist/connectorKit/shell.generated.js +121 -20
- package/dist/connectorKit/sources/cloudflare/api-operations.generated.d.ts +37 -0
- package/dist/connectorKit/sources/cloudflare/api-operations.generated.js +2 -0
- package/dist/connectorKit/sources/cloudflare/cli-flags.generated.d.ts +617 -0
- package/dist/connectorKit/sources/cloudflare/cli-flags.generated.js +2 -0
- package/dist/connectorKit/sources/cloudflare/mcp-tools.generated.d.ts +16 -0
- package/dist/connectorKit/sources/cloudflare/mcp-tools.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/api-operations.generated.d.ts +121 -0
- package/dist/connectorKit/sources/sentry/api-operations.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/cli-commands.generated.d.ts +530 -0
- package/dist/connectorKit/sources/sentry/cli-commands.generated.js +2 -0
- package/dist/connectorKit/sources/sentry/mcp-tools.generated.d.ts +32 -0
- package/dist/connectorKit/sources/sentry/mcp-tools.generated.js +2 -0
- package/dist/connectorKit/template.generated.d.ts +8 -4
- package/dist/connectorKit/template.generated.js +19 -6
- package/dist/controlPlane.generated.d.ts +11 -2
- package/dist/controlPlaneActions.generated.d.ts +52 -12
- package/dist/controlPlaneActions.generated.js +40 -11
- package/dist/controlPlaneCloudflare.d.ts +70 -0
- package/dist/controlPlaneCloudflare.js +188 -0
- package/dist/controlPlaneKubernetes.d.ts +72 -0
- package/dist/controlPlaneKubernetes.js +260 -0
- package/dist/controlPlaneModel.generated.d.ts +6 -0
- package/dist/controlPlaneNpm.generated.d.ts +83 -0
- package/dist/controlPlaneNpm.generated.js +307 -0
- package/dist/controlPlaneNpmCommands.generated.d.ts +35 -0
- package/dist/controlPlaneNpmCommands.generated.js +567 -0
- package/dist/controlPlaneNpmGuard.d.ts +44 -0
- package/dist/controlPlaneNpmGuard.js +210 -0
- package/dist/controlPlaneOffline.d.ts +1 -1
- package/dist/controlPlaneRailway.generated.js +2 -2
- package/dist/controlPlaneRailwayCli.generated.js +13 -2
- package/dist/controlPlaneRailwayModel.generated.d.ts +5 -0
- package/dist/controlPlaneRailwayModel.generated.js +15 -1
- package/dist/controlPlaneSentry.d.ts +68 -0
- package/dist/controlPlaneSentry.js +205 -0
- package/dist/controlPlaneTerraform.d.ts +86 -0
- package/dist/controlPlaneTerraform.js +273 -0
- package/dist/controlPlaneUnnamed.generated.d.ts +41 -2
- package/dist/controlPlaneUnnamed.generated.js +148 -2
- package/dist/cpCli.d.ts +1 -1
- package/dist/cpCli.js +1 -1
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/terraformPlans.d.ts +45 -0
- package/dist/terraformPlans.js +96 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The control plane for npm on this computer (`shared/controlPlaneNpm.ts`, copied as `controlPlaneNpm.generated.ts`):
|
|
3
|
+
* the guard reads each `npm`, `pnpm` and `yarn` command of a line in the folder it runs in (after a `cd`, `--prefix`,
|
|
4
|
+
* `-C` or `--cwd`; inside `sh -c`, `eval` and `env -S`) and asks `POST /api/cp/decide` once per command that acts on a
|
|
5
|
+
* registry. Local work (`install`, `ci`, `run`, `test`, `exec`, `version`, `pack`…) is never asked about.
|
|
6
|
+
*
|
|
7
|
+
* Only the classification leaves this computer: the registry's host, the package's name and version from its
|
|
8
|
+
* `package.json`, the classifier's fixed summaries, and the masked command (every flag value, an `--otp` among them,
|
|
9
|
+
* replaced). `.npmrc` is read for `registry` lines only: a token or password in it is never kept or sent.
|
|
10
|
+
*/
|
|
11
|
+
import { readFileSync, statSync } from "node:fs";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { resolve } from "node:path";
|
|
14
|
+
import { basename, normalizeArgv, splitCommands } from "./cliHookParse.js";
|
|
15
|
+
import { readBoundedJson } from "./boundedResponse.js";
|
|
16
|
+
import { classifyNpm, NPM_PROGRAMS } from "./controlPlaneNpmCommands.generated.js";
|
|
17
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, worstAnswer } from "./controlPlaneGuard.js";
|
|
18
|
+
import { maskCommandArgv } from "./controlPlaneUnnamed.generated.js";
|
|
19
|
+
import { newRequestId } from "./controlPlaneLate.js";
|
|
20
|
+
import { cdTarget } from "./controlPlaneRailwayReach.js";
|
|
21
|
+
import { envScript, shellScript } from "./controlPlaneRailwayGuard.js";
|
|
22
|
+
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
23
|
+
/** At most this many npm commands in one line are asked about; a line doing more is refused. */
|
|
24
|
+
export const MAX_NPM_COMMANDS = 8;
|
|
25
|
+
export const TOO_MANY_NPM = `Blocked by Passport: this command does more than ${MAX_NPM_COMMANDS} things on npm at once. Split it up so each can be checked.`;
|
|
26
|
+
const MAX_SUMMARY = 200;
|
|
27
|
+
const MAX_DEPTH = 3;
|
|
28
|
+
/** A `package.json` or `.npmrc` bigger than this isn't read (the command is decided all the same). */
|
|
29
|
+
const MAX_FILE_BYTES = 256 * 1024;
|
|
30
|
+
/** The only variables read from the line or the agent's environment: where the registry is. */
|
|
31
|
+
const REGISTRY_ENV = /^(?:npm_config_registry|NPM_CONFIG_REGISTRY)$/;
|
|
32
|
+
/** A file's text, bounded; undefined when missing or too big. */
|
|
33
|
+
function readBounded(path) {
|
|
34
|
+
try {
|
|
35
|
+
return statSync(path).size <= MAX_FILE_BYTES ? readFileSync(path, "utf8") : undefined;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Only the registry variables, from the agent's environment and what the line sets in front of the command. */
|
|
42
|
+
function registryEnv(env, assignments) {
|
|
43
|
+
const out = {};
|
|
44
|
+
for (const [name, value] of Object.entries(env))
|
|
45
|
+
if (REGISTRY_ENV.test(name) && value)
|
|
46
|
+
out[name] = value;
|
|
47
|
+
for (const assignment of assignments) {
|
|
48
|
+
const eq = assignment.indexOf("=");
|
|
49
|
+
const name = assignment.slice(0, eq);
|
|
50
|
+
if (REGISTRY_ENV.test(name))
|
|
51
|
+
out[name] = assignment.slice(eq + 1);
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/** The program of an npm-family command: `npm`, `pnpm`, `yarn` (`npm.cmd` and paths too). */
|
|
56
|
+
function programOf(argv0) {
|
|
57
|
+
const name = basename(argv0 ?? "")
|
|
58
|
+
.toLowerCase()
|
|
59
|
+
.replace(/\.(?:cmd|exe|js)$/, "");
|
|
60
|
+
return NPM_PROGRAMS.includes(name) ? name : null;
|
|
61
|
+
}
|
|
62
|
+
function walkLine(command, walk, depth) {
|
|
63
|
+
let split;
|
|
64
|
+
try {
|
|
65
|
+
split = splitCommands(command);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const start = walk.cwd;
|
|
71
|
+
let before = "end";
|
|
72
|
+
for (const shape of split.shapes) {
|
|
73
|
+
const after = before;
|
|
74
|
+
before = shape.next;
|
|
75
|
+
if (!shape.words.length || walk.bundles.length > MAX_NPM_COMMANDS)
|
|
76
|
+
continue;
|
|
77
|
+
if (!moved(shape, after, walk))
|
|
78
|
+
walkCommand(shape.words.map((word) => word.text), walk, depth);
|
|
79
|
+
}
|
|
80
|
+
walk.cwd = walk.cwd === start ? start : null;
|
|
81
|
+
for (const nested of split.nested)
|
|
82
|
+
inner(nested.text, walk, depth);
|
|
83
|
+
}
|
|
84
|
+
function moved(shape, after, walk) {
|
|
85
|
+
const { argv } = normalizeArgv(shape.words.map((word) => word.text));
|
|
86
|
+
const next = cdTarget(argv, shape.words, { depth: shape.depth, before: after, next: shape.next }, walk.cwd, walk.where.home);
|
|
87
|
+
if (next === undefined)
|
|
88
|
+
return false;
|
|
89
|
+
walk.cwd = next;
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
function inner(script, walk, depth) {
|
|
93
|
+
if (depth >= MAX_DEPTH)
|
|
94
|
+
return;
|
|
95
|
+
const saved = walk.cwd;
|
|
96
|
+
walkLine(script, walk, depth + 1);
|
|
97
|
+
walk.cwd = saved;
|
|
98
|
+
}
|
|
99
|
+
function walkCommand(words, walk, depth) {
|
|
100
|
+
const { argv, envInjected } = normalizeArgv(words);
|
|
101
|
+
const script = envScript(words.slice(0, words.length - argv.length)) ??
|
|
102
|
+
shellScript(argv) ??
|
|
103
|
+
(argv[0] === "eval" ? argv.slice(1).join(" ") : null);
|
|
104
|
+
if (script !== null)
|
|
105
|
+
return inner(script, walk, depth);
|
|
106
|
+
const program = programOf(argv[0]);
|
|
107
|
+
if (!program)
|
|
108
|
+
return;
|
|
109
|
+
// `env -C dir npm …` and wrappers that move the folder aren't followed: the folder stays the line's.
|
|
110
|
+
const files = {
|
|
111
|
+
read: readBounded,
|
|
112
|
+
home: walk.where.home,
|
|
113
|
+
env: registryEnv(walk.where.env, envInjected)
|
|
114
|
+
};
|
|
115
|
+
const found = classifyNpm({ program, args: argv.slice(1), cwd: walk.cwd }, files);
|
|
116
|
+
if (!found.length)
|
|
117
|
+
return;
|
|
118
|
+
const command = maskCommandArgv([program, ...argv.slice(1)]);
|
|
119
|
+
walk.bundles.push({ found, ...(command ? { command } : {}) });
|
|
120
|
+
}
|
|
121
|
+
/** Every npm-family command of a line that acts on a registry, in order; one past the cap at most. */
|
|
122
|
+
export function readNpmLine(command, where = {}) {
|
|
123
|
+
const walk = {
|
|
124
|
+
bundles: [],
|
|
125
|
+
cwd: where.cwd ? resolve(where.cwd) : null,
|
|
126
|
+
where: { env: where.env ?? {}, home: where.home ?? homedir() }
|
|
127
|
+
};
|
|
128
|
+
walkLine(command, walk, 0);
|
|
129
|
+
return walk.bundles.slice(0, MAX_NPM_COMMANDS + 1);
|
|
130
|
+
}
|
|
131
|
+
const action = (found) => ({
|
|
132
|
+
nodeId: found.nodeId,
|
|
133
|
+
actionKey: found.actionKey,
|
|
134
|
+
summary: found.summary.slice(0, MAX_SUMMARY),
|
|
135
|
+
...(found.target ? { target: found.target } : {}),
|
|
136
|
+
...(found.unnamed ? { unnamed: found.unnamed } : {})
|
|
137
|
+
});
|
|
138
|
+
/** The decide request for one command. */
|
|
139
|
+
export function npmDecideBody(bundle, sessionId) {
|
|
140
|
+
const [first, ...rest] = bundle.found;
|
|
141
|
+
return {
|
|
142
|
+
...action(first),
|
|
143
|
+
interface: "cli",
|
|
144
|
+
platform: "npm",
|
|
145
|
+
...(rest.length ? { more: rest.map(action) } : {}),
|
|
146
|
+
...(bundle.command ? { command: bundle.command } : {}),
|
|
147
|
+
...(sessionId && /^[A-Za-z0-9._:-]{1,128}$/.test(sessionId) ? { sessionId } : {})
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** Ask about one command under a new request id. A server that doesn't decide npm answers 400: undecided. */
|
|
151
|
+
export async function askNpm(api, bundle, sessionId, signal) {
|
|
152
|
+
const requestId = newRequestId();
|
|
153
|
+
const unreachable = { kind: "unreachable", late: [requestId] };
|
|
154
|
+
let response;
|
|
155
|
+
try {
|
|
156
|
+
response = await api(CP_DECIDE_PATH, {
|
|
157
|
+
method: "POST",
|
|
158
|
+
headers: { "content-type": "application/json" },
|
|
159
|
+
body: JSON.stringify({ ...npmDecideBody(bundle, sessionId), requestId }),
|
|
160
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(CP_DECIDE_TIMEOUT_MS)])
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return unreachable;
|
|
165
|
+
}
|
|
166
|
+
if (response.status >= 500) {
|
|
167
|
+
await response.body?.cancel().catch(() => undefined);
|
|
168
|
+
return unreachable;
|
|
169
|
+
}
|
|
170
|
+
if (NO_ANSWER_STATUSES.has(response.status))
|
|
171
|
+
return noAnswer(response, unreachable);
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
await response.body?.cancel().catch(() => undefined);
|
|
174
|
+
return { kind: "undecided" };
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const body = await readBoundedJson(response);
|
|
178
|
+
if (body.allow === true)
|
|
179
|
+
return { kind: "allow", eventId: typeof body.eventId === "string" ? body.eventId : null };
|
|
180
|
+
return refusalOf(body) ?? { kind: "undecided" };
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return unreachable;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** The guard's question for a line's npm commands: the worst answer, else the last. */
|
|
187
|
+
export async function npmLinePlan(command, where, open, extra, signal) {
|
|
188
|
+
const bundles = readNpmLine(command, where);
|
|
189
|
+
if (!bundles.length)
|
|
190
|
+
return null;
|
|
191
|
+
const label = bundles[0].found[0].summary;
|
|
192
|
+
if (bundles.length > MAX_NPM_COMMANDS)
|
|
193
|
+
return { answer: { kind: "block", message: TOO_MANY_NPM }, label };
|
|
194
|
+
const api = await open();
|
|
195
|
+
if (!api)
|
|
196
|
+
return null;
|
|
197
|
+
const answers = await Promise.all(bundles.map((bundle) => askNpm(api, bundle, extra.sessionId, signal)));
|
|
198
|
+
return { answer: worstAnswer(answers) ?? answers.at(-1) ?? { kind: "allow", eventId: null }, label };
|
|
199
|
+
}
|
|
200
|
+
/** What the line does on npm, for when Passport can't be reached (`controlPlaneOffline.ts`). */
|
|
201
|
+
export function npmFound(command, where) {
|
|
202
|
+
return readNpmLine(command, where)
|
|
203
|
+
.slice(0, MAX_NPM_COMMANDS)
|
|
204
|
+
.flatMap((bundle) => bundle.found.map((one) => ({
|
|
205
|
+
platform: "npm",
|
|
206
|
+
nodeId: one.nodeId,
|
|
207
|
+
actionKey: one.actionKey,
|
|
208
|
+
summary: one.summary
|
|
209
|
+
})));
|
|
210
|
+
}
|
|
@@ -19,7 +19,7 @@ type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
|
19
19
|
export declare const CP_DECIDE_OFFLINE_PATH = "/api/cp/decide/offline";
|
|
20
20
|
/** A copy of the rules older than this says nothing: treated as missing. */
|
|
21
21
|
export declare const BLOCKS_MAX_AGE_MS: number;
|
|
22
|
-
export type OfflinePlatform = "github" | "railway" | "supabase";
|
|
22
|
+
export type OfflinePlatform = "github" | "railway" | "supabase" | "kubernetes" | "terraform" | "sentry" | "cloudflare" | "npm";
|
|
23
23
|
/** One thing a line does, as its classifier named it. */
|
|
24
24
|
export type Found = {
|
|
25
25
|
platform: OfflinePlatform;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* a command, a query or an email address.
|
|
16
16
|
*/
|
|
17
17
|
import { classifyGraphql, classifyRailwayCli, cliGraphql, mutationFields } from "./controlPlaneRailwayCli.generated.js";
|
|
18
|
-
import { applyEnvelope, applyStaged, at, bucketTargets, envIn, everyEnvironment, ids, isBag, listNames, onlyOne, onService, onServiceTarget, projectChain, projectOf, resolveEnv, serviceIn, short, staged, text, volumeTargets } from "./controlPlaneRailwayModel.generated.js";
|
|
18
|
+
import { applyEnvelope, applyStaged, at, bucketTargets, envIn, everyEnvironment, ids, isBag, listNames, onlyOne, onService, onServiceTarget, projectChain, projectOf, resolveEnv, scalePhrase, scalesToZero, serviceIn, short, staged, text, volumeTargets } from "./controlPlaneRailwayModel.generated.js";
|
|
19
19
|
export { mutationFields } from "./controlPlaneRailwayCli.generated.js";
|
|
20
20
|
export { nameKey, railwayIndex, railwayNodeIds } from "./controlPlaneRailwayModel.generated.js";
|
|
21
21
|
/* ------------------------------------------------------------------ */
|
|
@@ -119,7 +119,7 @@ function updateService(args, context, isStaged) {
|
|
|
119
119
|
found.push(...(Array.isArray(result) ? result : [result]));
|
|
120
120
|
};
|
|
121
121
|
if (isBag(args.regions) || isBag(args.limits)) {
|
|
122
|
-
add(serviceTool(args, context, "railway.service.scale", (where) => staged(
|
|
122
|
+
add(serviceTool(args, context, "railway.service.scale", (where) => staged(scalePhrase(where, scalesToZero(args.regions)), isStaged), true));
|
|
123
123
|
}
|
|
124
124
|
if (SOURCE_FIELDS.some((field) => args[field] !== undefined)) {
|
|
125
125
|
add(serviceTool(args, context, "railway.service.deploy", (where) => staged(`Change what runs on ${where}`, isStaged), true));
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* The Railway classifier for `railway` command lines and GraphQL calls
|
|
4
4
|
* (docs/design/control-plane.md, Part 3b). Pure; see `controlPlaneRailway.ts`.
|
|
5
5
|
*/
|
|
6
|
-
import { applyEnvelope, applyStaged, at, bucketTargets, classifyRailwayPatch, ids, isBag, listNames, onlyOne, onService, onServiceTarget, own, projectChain, projectOf, resolveEnv, resolveService, short, volumeTargets } from "./controlPlaneRailwayModel.generated.js";
|
|
6
|
+
import { applyEnvelope, applyStaged, at, bucketTargets, classifyRailwayPatch, ids, isBag, listNames, onlyOne, onService, onServiceTarget, own, projectChain, projectOf, resolveEnv, resolveService, scalePhrase, scalesToZero, short, volumeTargets } from "./controlPlaneRailwayModel.generated.js";
|
|
7
7
|
/* ------------------------------------------------------------------ */
|
|
8
8
|
/* GraphQL (`railway api`, and API calls Passport forwards) */
|
|
9
9
|
/* ------------------------------------------------------------------ */
|
|
@@ -304,6 +304,17 @@ const cliInit = (call) => hasFlag(call.parsed, "-h", "--help")
|
|
|
304
304
|
? null
|
|
305
305
|
: at({ nodeId: ids.projects, name: "Projects", chain: [] }, OTHER_CHANGE, "Create project");
|
|
306
306
|
const serviceCommand = (actionKey, phrase) => (call) => call.onSvc(actionKey, phrase);
|
|
307
|
+
/** A region flag of `railway scale` (`--us-west1 0`, `--europe-west4-drams3a=2`). */
|
|
308
|
+
const REGION_FLAG = /^--[a-z]+-[a-z]+\d[a-z0-9-]*$/;
|
|
309
|
+
/** Whether `railway scale` sets zero replicas in every region it names: its region flags' values, and the words after
|
|
310
|
+
* them when they take none of their own. */
|
|
311
|
+
function scaleToZero(parsed) {
|
|
312
|
+
const regions = parsed.opts.filter(([name]) => REGION_FLAG.test(name));
|
|
313
|
+
const counts = regions.flatMap(([, value]) => (value === true ? [] : [value]));
|
|
314
|
+
if (regions.some(([, value]) => value === true))
|
|
315
|
+
counts.push(...parsed.pos.slice(1));
|
|
316
|
+
return regions.length > 0 && scalesToZero(Object.fromEntries(counts.map((count, index) => [index, count])));
|
|
317
|
+
}
|
|
307
318
|
function cliProjectDelete(call) {
|
|
308
319
|
if (call.projectId === null)
|
|
309
320
|
return null;
|
|
@@ -389,7 +400,7 @@ const CLI_COMMANDS = {
|
|
|
389
400
|
"tcp-proxy": (call) => call.sub === "create" || call.sub === "add"
|
|
390
401
|
? call.onSvc("railway.service.tcp", (where) => `Add TCP proxy to ${where}`, undefined, (service) => onServiceTarget(service, "tcp_proxy", lastValue(call.parsed, "--port")))
|
|
391
402
|
: null,
|
|
392
|
-
scale:
|
|
403
|
+
scale: (call) => call.onSvc("railway.service.scale", (where) => scalePhrase(where, scaleToZero(call.parsed))),
|
|
393
404
|
service: (call) => isRemove(call.sub)
|
|
394
405
|
? call.onSvc("railway.service.delete", (where) => `Delete service ${where}`, call.rest[0])
|
|
395
406
|
: null,
|
|
@@ -187,3 +187,8 @@ export declare const applyEnvelope: (env: EnvTarget, phrase?: string) => Classif
|
|
|
187
187
|
export declare function applyStaged(env: EnvTarget, context: RailwayContext): Classification | Classification[];
|
|
188
188
|
export type Result = Classification | Classification[] | null;
|
|
189
189
|
export declare const own: <T>(table: Record<string, T>, key: string) => T | undefined;
|
|
190
|
+
/** Whether a scale sets zero replicas in every region it names (`regions` of `update-service`, a patch's
|
|
191
|
+
* `multiRegionConfig`, or `railway scale`'s region flags): the service stops, read as "Scale … to zero". */
|
|
192
|
+
export declare function scalesToZero(regions: unknown): boolean;
|
|
193
|
+
/** A scale's summary: "Scale … to zero" when it stops the service, else "Change scale of …". */
|
|
194
|
+
export declare const scalePhrase: (where: string, toZero: boolean) => string;
|
|
@@ -312,7 +312,7 @@ export function classifyRailwayPatch(env, patch, context) {
|
|
|
312
312
|
found.push(at(service, "railway.service.domain", `Add a domain to ${where}`, onServiceTarget(service, "domain", onlyOne(domains))));
|
|
313
313
|
const deploy = bagAt(raw, "deploy");
|
|
314
314
|
if (deploy && ("multiRegionConfig" in deploy || "limitOverride" in deploy))
|
|
315
|
-
found.push(at(service, "railway.service.scale",
|
|
315
|
+
found.push(at(service, "railway.service.scale", scalePhrase(where, scalesToZero(deploy.multiRegionConfig))));
|
|
316
316
|
for (const [volumeId, mount] of Object.entries(bagAt(raw, "volumeMounts") ?? {})) {
|
|
317
317
|
if (!isBag(mount) || !("backupSchedules" in mount))
|
|
318
318
|
continue;
|
|
@@ -353,3 +353,17 @@ export function applyStaged(env, context) {
|
|
|
353
353
|
return found.length > 0 ? found : applyEnvelope(env);
|
|
354
354
|
}
|
|
355
355
|
export const own = (table, key) => Object.prototype.hasOwnProperty.call(table, key) ? table[key] : undefined;
|
|
356
|
+
/** Whether a scale sets zero replicas in every region it names (`regions` of `update-service`, a patch's
|
|
357
|
+
* `multiRegionConfig`, or `railway scale`'s region flags): the service stops, read as "Scale … to zero". */
|
|
358
|
+
export function scalesToZero(regions) {
|
|
359
|
+
if (!isBag(regions))
|
|
360
|
+
return false;
|
|
361
|
+
const counts = Object.values(regions).map((region) => typeof region === "number" || typeof region === "string"
|
|
362
|
+
? Number(region)
|
|
363
|
+
: isBag(region)
|
|
364
|
+
? Number(region.numReplicas)
|
|
365
|
+
: Number.NaN);
|
|
366
|
+
return counts.length > 0 && counts.every((count) => count === 0);
|
|
367
|
+
}
|
|
368
|
+
/** A scale's summary: "Scale … to zero" when it stops the service, else "Change scale of …". */
|
|
369
|
+
export const scalePhrase = (where, toZero) => toZero ? `Scale ${where} to zero` : `Change scale of ${where}`;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The control plane for Sentry on this computer, through the connector kit (2026-11-21; `shared/connectorKit/`, copied
|
|
3
|
+
* to `connectorKit/` by scripts/generate-control-plane-classifier.mjs). The guard classifies a `sentry-cli` command
|
|
4
|
+
* (its target from its flags, `SENTRY_ORG` / `SENTRY_PROJECT`, or the folder's `.sentryclirc`) and a `curl`, `wget`
|
|
5
|
+
* or httpie call to Sentry's API with the kit's Sentry manifest, and asks `POST /api/cp/decide` once per command:
|
|
6
|
+
* everything one command does is one bundle, decided as a whole.
|
|
7
|
+
*
|
|
8
|
+
* Fails closed: what the manifest doesn't name, a flag it doesn't know, a target it can't read, and an API call whose
|
|
9
|
+
* body it can't read are the Unclassified action, with the coarse hit only. Only the classification leaves this
|
|
10
|
+
* computer: nodes, catalog actions, the manifest's fixed summaries filled with safe names, and the SHA-256 of an exact
|
|
11
|
+
* target. Never the command line's values, a request body, a token or an email.
|
|
12
|
+
*/
|
|
13
|
+
import type { Classification } from "./controlPlane.generated.js";
|
|
14
|
+
import { type Request } from "./connectorKit/engine.generated.js";
|
|
15
|
+
import { type Guard } from "./connectorKit/shell.generated.js";
|
|
16
|
+
import { type CpAnswer } from "./controlPlaneGuard.js";
|
|
17
|
+
type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
|
|
18
|
+
/** At most this many Sentry commands in one line are asked about; a line doing more is refused. */
|
|
19
|
+
export declare const MAX_SENTRY_COMMANDS = 8;
|
|
20
|
+
/** A bundle holds at most this many actions (the server's bound). */
|
|
21
|
+
export declare const MAX_SENTRY_BUNDLE = 32;
|
|
22
|
+
export declare const TOO_MANY_SENTRY = "Blocked by Passport: this command changes more than 32 things on Sentry at once. Split it up so each can be checked.";
|
|
23
|
+
export type SentryWhere = {
|
|
24
|
+
cwd?: string | null;
|
|
25
|
+
env: Record<string, string | undefined>;
|
|
26
|
+
};
|
|
27
|
+
/** Everything one command does. */
|
|
28
|
+
export type SentryBundle = {
|
|
29
|
+
found: Classification[];
|
|
30
|
+
command?: string;
|
|
31
|
+
};
|
|
32
|
+
/** What the kit's resolver may read here: the folder, the variables the manifest names, and small link files. */
|
|
33
|
+
export declare function sentryGuard(where: SentryWhere): Guard;
|
|
34
|
+
/** An HTTP line to Sentry's API as the kit's API request, or null when it isn't Sentry's. `unread`: it sends a body
|
|
35
|
+
* Passport can't read, or names its target in a way Passport can't read. */
|
|
36
|
+
export declare function sentryHttpRequest(argv: readonly string[]): {
|
|
37
|
+
request: Extract<Request, {
|
|
38
|
+
interface: "api";
|
|
39
|
+
}>;
|
|
40
|
+
unread: boolean;
|
|
41
|
+
} | null;
|
|
42
|
+
/** Every Sentry command of a line, each with what it does: `sentry-cli` commands as the kit's resolver reads them,
|
|
43
|
+
* then HTTP calls to Sentry's API. Reads leave nothing. */
|
|
44
|
+
export declare function classifySentryLine(command: string, where: SentryWhere): SentryBundle[];
|
|
45
|
+
/** What a line's Sentry commands do, classified locally (for when Passport can't be reached). */
|
|
46
|
+
export declare function sentryFound(command: string, where: SentryWhere): {
|
|
47
|
+
platform: "sentry";
|
|
48
|
+
nodeId: string;
|
|
49
|
+
actionKey: string;
|
|
50
|
+
summary: string;
|
|
51
|
+
}[];
|
|
52
|
+
export type SentryAsk = {
|
|
53
|
+
sessionId?: string;
|
|
54
|
+
};
|
|
55
|
+
/** The decide request for one bundle: the person's own sign-in (Passport holds no Sentry key). */
|
|
56
|
+
export declare function sentryDecideBody(bundle: SentryBundle, ask: SentryAsk): Record<string, unknown>;
|
|
57
|
+
/** Ask about one bundle under a new request id. A server that doesn't decide Sentry answers 400: undecided, never a
|
|
58
|
+
* block. */
|
|
59
|
+
export declare function askSentry(api: ApiCall, bundle: SentryBundle, ask: SentryAsk, signal: AbortSignal): Promise<CpAnswer>;
|
|
60
|
+
export type SentryLinePlan = {
|
|
61
|
+
answer: CpAnswer;
|
|
62
|
+
label: string;
|
|
63
|
+
};
|
|
64
|
+
/** The guard's question for a line's Sentry commands: the worst answer of its bundles. */
|
|
65
|
+
export declare function sentryLinePlan(command: string, where: SentryWhere, open: () => Promise<ApiCall | null>, extra: {
|
|
66
|
+
sessionId?: string;
|
|
67
|
+
}, signal: AbortSignal): Promise<SentryLinePlan | null>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The control plane for Sentry on this computer, through the connector kit (2026-11-21; `shared/connectorKit/`, copied
|
|
3
|
+
* to `connectorKit/` by scripts/generate-control-plane-classifier.mjs). The guard classifies a `sentry-cli` command
|
|
4
|
+
* (its target from its flags, `SENTRY_ORG` / `SENTRY_PROJECT`, or the folder's `.sentryclirc`) and a `curl`, `wget`
|
|
5
|
+
* or httpie call to Sentry's API with the kit's Sentry manifest, and asks `POST /api/cp/decide` once per command:
|
|
6
|
+
* everything one command does is one bundle, decided as a whole.
|
|
7
|
+
*
|
|
8
|
+
* Fails closed: what the manifest doesn't name, a flag it doesn't know, a target it can't read, and an API call whose
|
|
9
|
+
* body it can't read are the Unclassified action, with the coarse hit only. Only the classification leaves this
|
|
10
|
+
* computer: nodes, catalog actions, the manifest's fixed summaries filled with safe names, and the SHA-256 of an exact
|
|
11
|
+
* target. Never the command line's values, a request body, a token or an email.
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync, statSync } from "node:fs";
|
|
14
|
+
import { normalizeArgv, splitCommands } from "./cliHookParse.js";
|
|
15
|
+
import { readBoundedJson } from "./boundedResponse.js";
|
|
16
|
+
import { explain } from "./connectorKit/engine.generated.js";
|
|
17
|
+
import { httpLineOf, urlParts } from "./connectorKit/http.generated.js";
|
|
18
|
+
import { SENTRY } from "./connectorKit/manifests/sentry.generated.js";
|
|
19
|
+
import { resolveCommand } from "./connectorKit/shell.generated.js";
|
|
20
|
+
import { CP_DECIDE_PATH, CP_DECIDE_TIMEOUT_MS, targetDigest, worstAnswer } from "./controlPlaneGuard.js";
|
|
21
|
+
import { maskCommandArgv, unnamedApi } from "./controlPlaneUnnamed.generated.js";
|
|
22
|
+
import { newRequestId } from "./controlPlaneLate.js";
|
|
23
|
+
import { NO_ANSWER_STATUSES, noAnswer, refusalOf } from "./cpRefusal.js";
|
|
24
|
+
/** At most this many Sentry commands in one line are asked about; a line doing more is refused. */
|
|
25
|
+
export const MAX_SENTRY_COMMANDS = 8;
|
|
26
|
+
/** A bundle holds at most this many actions (the server's bound). */
|
|
27
|
+
export const MAX_SENTRY_BUNDLE = 32;
|
|
28
|
+
export const TOO_MANY_SENTRY = `Blocked by Passport: this command changes more than ${MAX_SENTRY_BUNDLE} things on Sentry at once. Split it up so each can be checked.`;
|
|
29
|
+
const MAX_SUMMARY = 200;
|
|
30
|
+
/** A `.sentryclirc` is a few lines: anything bigger isn't read. */
|
|
31
|
+
const MAX_LINK_BYTES = 16 * 1024;
|
|
32
|
+
/** Sentry's own hosts: sentry.io, its regions (us., de.) and an organization's subdomain. Never ingest. */
|
|
33
|
+
const SENTRY_HOST = /^(?:(?!o\d+\.ingest\.)[a-z0-9-]+\.)*sentry\.io$/i;
|
|
34
|
+
function readSmall(path) {
|
|
35
|
+
try {
|
|
36
|
+
if (statSync(path).size > MAX_LINK_BYTES)
|
|
37
|
+
return undefined;
|
|
38
|
+
return readFileSync(path, "utf8");
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** What the kit's resolver may read here: the folder, the variables the manifest names, and small link files. */
|
|
45
|
+
export function sentryGuard(where) {
|
|
46
|
+
const env = Object.fromEntries(Object.entries(where.env).filter((entry) => typeof entry[1] === "string"));
|
|
47
|
+
return { cwd: where.cwd || process.cwd(), env, readFile: readSmall };
|
|
48
|
+
}
|
|
49
|
+
/** An HTTP line to Sentry's API as the kit's API request, or null when it isn't Sentry's. `unread`: it sends a body
|
|
50
|
+
* Passport can't read, or names its target in a way Passport can't read. */
|
|
51
|
+
export function sentryHttpRequest(argv) {
|
|
52
|
+
const line = httpLineOf(argv);
|
|
53
|
+
if (!line?.url)
|
|
54
|
+
return null;
|
|
55
|
+
const parts = urlParts(line.url);
|
|
56
|
+
if (!parts || !SENTRY_HOST.test(parts.host) || /(^|\.)ingest\./i.test(parts.host))
|
|
57
|
+
return null;
|
|
58
|
+
return {
|
|
59
|
+
request: { interface: "api", method: line.method, url: line.url, ...(line.body ? { body: line.body } : {}) },
|
|
60
|
+
unread: Boolean(line.opaque || line.problem)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** A write whose body Passport couldn't read may do more than its route says (delete and discard): Unclassified,
|
|
64
|
+
* on the node it named, with its coarse hit. */
|
|
65
|
+
function unread(found, request) {
|
|
66
|
+
const path = (() => {
|
|
67
|
+
try {
|
|
68
|
+
return new URL(request.url).pathname;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
return {
|
|
75
|
+
nodeId: found.nodeId,
|
|
76
|
+
actionKey: SENTRY.capture.unclassified,
|
|
77
|
+
summary: `Unclassified action: ${found.summary} (a body Passport can't read)`.slice(0, MAX_SUMMARY),
|
|
78
|
+
...(found.nodes?.length ? { nodes: found.nodes } : {}),
|
|
79
|
+
unnamed: unnamedApi("sentry", request.method, path)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** Every Sentry command of a line, each with what it does: `sentry-cli` commands as the kit's resolver reads them,
|
|
83
|
+
* then HTTP calls to Sentry's API. Reads leave nothing. */
|
|
84
|
+
export function classifySentryLine(command, where) {
|
|
85
|
+
const bundles = [];
|
|
86
|
+
const guard = sentryGuard(where);
|
|
87
|
+
for (const resolved of resolveCommand(SENTRY, command, guard)) {
|
|
88
|
+
const found = explain(SENTRY, resolved.request, resolved.context).found;
|
|
89
|
+
const masked = resolved.request.interface === "cli" ? maskCommandArgv(resolved.request.argv) : undefined;
|
|
90
|
+
if (found.length)
|
|
91
|
+
bundles.push({ found, ...(masked ? { command: masked } : {}) });
|
|
92
|
+
}
|
|
93
|
+
let commands = [];
|
|
94
|
+
try {
|
|
95
|
+
commands = /sentry\.io/i.test(command) ? splitCommands(command).commands : [];
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
commands = [];
|
|
99
|
+
}
|
|
100
|
+
for (const words of commands) {
|
|
101
|
+
const argv = normalizeArgv(words).argv;
|
|
102
|
+
const http = sentryHttpRequest(argv);
|
|
103
|
+
if (!http)
|
|
104
|
+
continue;
|
|
105
|
+
const found = explain(SENTRY, http.request).found;
|
|
106
|
+
const masked = maskCommandArgv(argv);
|
|
107
|
+
if (found.length)
|
|
108
|
+
bundles.push({
|
|
109
|
+
found: http.unread ? found.map((one) => unread(one, http.request)) : found,
|
|
110
|
+
...(masked ? { command: masked } : {})
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return bundles;
|
|
114
|
+
}
|
|
115
|
+
/** What a line's Sentry commands do, classified locally (for when Passport can't be reached). */
|
|
116
|
+
export function sentryFound(command, where) {
|
|
117
|
+
return classifySentryLine(command, where).flatMap((bundle) => bundle.found.map((found) => ({
|
|
118
|
+
platform: "sentry",
|
|
119
|
+
nodeId: found.nodeId,
|
|
120
|
+
actionKey: found.actionKey,
|
|
121
|
+
summary: found.summary.slice(0, MAX_SUMMARY)
|
|
122
|
+
})));
|
|
123
|
+
}
|
|
124
|
+
/** The exact target's digest, when the first action has one: the event records only its keyed hash. */
|
|
125
|
+
function exactDigest(first) {
|
|
126
|
+
const exact = SENTRY.actions.find((action) => action.key === first.actionKey)?.exactTarget;
|
|
127
|
+
return exact && first.target?.type === exact ? targetDigest(first.target.key) : undefined;
|
|
128
|
+
}
|
|
129
|
+
const action = (found) => ({
|
|
130
|
+
nodeId: found.nodeId,
|
|
131
|
+
actionKey: found.actionKey,
|
|
132
|
+
summary: found.summary.slice(0, MAX_SUMMARY),
|
|
133
|
+
...(found.target ? { target: found.target } : {}),
|
|
134
|
+
...(found.nodes?.length ? { nodes: found.nodes } : {}),
|
|
135
|
+
// What an unnamed action hit, coarse; the server makes it coarse again (`sanitizeUnnamed`).
|
|
136
|
+
...(found.unnamed ? { unnamed: found.unnamed } : {})
|
|
137
|
+
});
|
|
138
|
+
/** The decide request for one bundle: the person's own sign-in (Passport holds no Sentry key). */
|
|
139
|
+
export function sentryDecideBody(bundle, ask) {
|
|
140
|
+
const [first, ...rest] = bundle.found;
|
|
141
|
+
const digest = exactDigest(first);
|
|
142
|
+
return {
|
|
143
|
+
...action(first),
|
|
144
|
+
interface: "cli",
|
|
145
|
+
platform: "sentry",
|
|
146
|
+
credential: "own",
|
|
147
|
+
...(rest.length ? { more: rest.map(action) } : {}),
|
|
148
|
+
...(digest ? { targetDigest: digest } : {}),
|
|
149
|
+
...(bundle.command ? { command: bundle.command } : {}),
|
|
150
|
+
...(ask.sessionId && /^[A-Za-z0-9._:-]{1,128}$/.test(ask.sessionId) ? { sessionId: ask.sessionId } : {})
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** Ask about one bundle under a new request id. A server that doesn't decide Sentry answers 400: undecided, never a
|
|
154
|
+
* block. */
|
|
155
|
+
export async function askSentry(api, bundle, ask, signal) {
|
|
156
|
+
if (bundle.found.length > MAX_SENTRY_BUNDLE)
|
|
157
|
+
return { kind: "block", message: TOO_MANY_SENTRY };
|
|
158
|
+
const requestId = newRequestId();
|
|
159
|
+
const unreachable = { kind: "unreachable", late: [requestId] };
|
|
160
|
+
let response;
|
|
161
|
+
try {
|
|
162
|
+
response = await api(CP_DECIDE_PATH, {
|
|
163
|
+
method: "POST",
|
|
164
|
+
headers: { "content-type": "application/json" },
|
|
165
|
+
body: JSON.stringify({ ...sentryDecideBody(bundle, ask), requestId }),
|
|
166
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(CP_DECIDE_TIMEOUT_MS)])
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return unreachable;
|
|
171
|
+
}
|
|
172
|
+
if (response.status >= 500)
|
|
173
|
+
return unreachable;
|
|
174
|
+
if (NO_ANSWER_STATUSES.has(response.status))
|
|
175
|
+
return noAnswer(response, unreachable);
|
|
176
|
+
if (!response.ok) {
|
|
177
|
+
await response.body?.cancel().catch(() => undefined);
|
|
178
|
+
return { kind: "undecided" };
|
|
179
|
+
}
|
|
180
|
+
let body;
|
|
181
|
+
try {
|
|
182
|
+
body = await readBoundedJson(response);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
// A 200 that isn't Passport's JSON (a captive portal, a proxy): no answer.
|
|
186
|
+
return unreachable;
|
|
187
|
+
}
|
|
188
|
+
if (body.allow === true)
|
|
189
|
+
return { kind: "allow", eventId: typeof body.eventId === "string" ? body.eventId : null };
|
|
190
|
+
return refusalOf(body) ?? { kind: "undecided" };
|
|
191
|
+
}
|
|
192
|
+
/** The guard's question for a line's Sentry commands: the worst answer of its bundles. */
|
|
193
|
+
export async function sentryLinePlan(command, where, open, extra, signal) {
|
|
194
|
+
const bundles = classifySentryLine(command, where);
|
|
195
|
+
if (!bundles.length)
|
|
196
|
+
return null;
|
|
197
|
+
const label = bundles[0].found[0].summary;
|
|
198
|
+
if (bundles.length > MAX_SENTRY_COMMANDS)
|
|
199
|
+
return { answer: { kind: "block", message: TOO_MANY_SENTRY }, label };
|
|
200
|
+
const api = await open();
|
|
201
|
+
if (!api)
|
|
202
|
+
return null;
|
|
203
|
+
const answers = await Promise.all(bundles.map((bundle) => askSentry(api, bundle, extra, signal)));
|
|
204
|
+
return { answer: worstAnswer(answers) ?? answers.at(-1) ?? { kind: "allow", eventId: null }, label };
|
|
205
|
+
}
|