hopwire 0.1.9 → 0.2.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/agent/redact.js +38 -0
- package/dist/cli.js +60 -1
- package/dist/commands/doctor.js +37 -1
- package/dist/commands/http.js +19 -4
- package/dist/commands/init.js +28 -2
- package/dist/commands/up.js +16 -3
- package/dist/commands/watch.js +33 -4
- package/dist/config-template.js +11 -1
- package/dist/config.js +58 -4
- package/dist/control-plane-client.js +42 -0
- package/dist/inspector/assets/index-CIOfyIbK.js +5 -0
- package/dist/inspector/assets/index-Du4-DCNN.css +2 -0
- package/dist/inspector/index.html +2 -2
- package/dist/inspector-api.js +145 -0
- package/dist/interceptor.js +19 -4
- package/dist/log-follow.js +473 -0
- package/dist/log.js +178 -11
- package/dist/mcp/logs.js +46 -0
- package/dist/mcp/tools.js +136 -3
- package/dist/output.js +38 -0
- package/dist/serve.js +49 -2
- package/node_modules/@hopwire/protocol/dist/constants.d.ts +10 -0
- package/node_modules/@hopwire/protocol/dist/constants.js +10 -0
- package/node_modules/@hopwire/protocol/dist/index.d.ts +1 -0
- package/node_modules/@hopwire/protocol/dist/index.js +1 -0
- package/node_modules/@hopwire/protocol/dist/inspector.d.ts +18 -0
- package/node_modules/@hopwire/protocol/dist/log-entries.d.ts +72 -0
- package/node_modules/@hopwire/protocol/dist/log-entries.js +147 -0
- package/node_modules/@hopwire/protocol/dist/ws-messages.d.ts +2 -1
- package/package.json +1 -1
- package/dist/inspector/assets/index-D3yNjmSA.js +0 -2
- package/dist/inspector/assets/index-XotF7D1X.css +0 -2
package/dist/agent/redact.js
CHANGED
|
@@ -126,3 +126,41 @@ function decodeComponent(text) {
|
|
|
126
126
|
export function redactJsonText(text) {
|
|
127
127
|
return text.replace(/"((?:[^"\\]|\\.)*)"(\s*:\s*)("(?:[^"\\]|\\.)*"?|[^,}\]\s"{[]+)/g, (whole, key, colon, value) => isRedactedField(key) ? `"${key}"${colon}"${redacted(value.replace(/^"|"$/g, ''))}"` : whole);
|
|
128
128
|
}
|
|
129
|
+
/** Shapes of keys and tokens that are redacted wherever they stand in a log entry */
|
|
130
|
+
const KNOWN_SECRETS = [
|
|
131
|
+
/\b[sr]k_(?:live|test)_[A-Za-z0-9]{6,}/g,
|
|
132
|
+
/\bwhsec_[A-Za-z0-9+/=]{8,}/g,
|
|
133
|
+
/\bgh[pousr]_[A-Za-z0-9]{20,}/g,
|
|
134
|
+
/\bgithub_pat_[A-Za-z0-9_]{20,}/g,
|
|
135
|
+
/\bxox[abprs]-[A-Za-z0-9-]{10,}/g,
|
|
136
|
+
/\bAKIA[0-9A-Z]{16}\b/g,
|
|
137
|
+
/\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}/g,
|
|
138
|
+
];
|
|
139
|
+
/** `Bearer abc…` and `Basic abc…`: the scheme stays, the credential goes */
|
|
140
|
+
const AUTH_SCHEME = /\b(Bearer|Basic|Token)\s+([A-Za-z0-9._~+/=-]{6,})/g;
|
|
141
|
+
/**
|
|
142
|
+
* `password=secret`, `token: abc`, `api_key="x y"` in free text: a sensitive name, `=` or `:`, and a value up to the
|
|
143
|
+
* next space, comma or semicolon (or its closing quote). A value that is already redacted, or a scheme whose
|
|
144
|
+
* credential was, is left alone.
|
|
145
|
+
*/
|
|
146
|
+
const KEY_VALUE = /([A-Za-z0-9_.-]+)(\s*[=:]\s*)(?!\[redacted|(?:Bearer|Basic|Token)\s)("[^"\n]*"|'[^'\n]*'|[^\s,;&}\])"']+)/g;
|
|
147
|
+
/**
|
|
148
|
+
* A log entry as an agent is shown it (phase 15, decision 144): JSON keys and `key=value` / `key: value` pairs with a
|
|
149
|
+
* sensitive name, Bearer and Basic credentials, and the known shapes of keys (Stripe, GitHub, Slack, AWS, JWTs)
|
|
150
|
+
* redacted. Best effort: a log may hold secrets no pattern recognises, and the docs say so.
|
|
151
|
+
*/
|
|
152
|
+
export function redactLogText(text) {
|
|
153
|
+
let shown = redactJsonText(text);
|
|
154
|
+
shown = shown.replace(AUTH_SCHEME, (_whole, scheme, credential) => `${scheme} ${redacted(credential)}`);
|
|
155
|
+
for (const pattern of KNOWN_SECRETS) {
|
|
156
|
+
shown = shown.replace(pattern, (secret) => redacted(secret));
|
|
157
|
+
}
|
|
158
|
+
return shown.replace(KEY_VALUE, (whole, key, separator, value) => {
|
|
159
|
+
if (!isRedactedField(key)) {
|
|
160
|
+
return whole;
|
|
161
|
+
}
|
|
162
|
+
const quote = /^["']/.exec(value)?.[0] ?? '';
|
|
163
|
+
const inner = quote === '' ? value : value.slice(1, -1);
|
|
164
|
+
return `${key}${separator}${quote}${redacted(inner)}${quote}`;
|
|
165
|
+
});
|
|
166
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -17,6 +17,7 @@ import { startWatch } from './commands/watch.js';
|
|
|
17
17
|
import { ConfigError, isServiceName, loadConfig } from './config.js';
|
|
18
18
|
import { HopwireError, TemporaryError, UsageError, errorCode } from './errors.js';
|
|
19
19
|
import { loadOrCreateIdentity } from './identity.js';
|
|
20
|
+
import { defaultLogName, isFollowablePath } from './log-follow.js';
|
|
20
21
|
import { DOCS_URL, printable } from './output.js';
|
|
21
22
|
import { createUpdateNotice } from './update-notice.js';
|
|
22
23
|
import { parseControlPlaneUrl, parseEdgeUrl, parseLocalTarget } from './urls.js';
|
|
@@ -93,6 +94,15 @@ Options for http:
|
|
|
93
94
|
model provider; exchanges captured without it stay closed to agents
|
|
94
95
|
--no-ws-capture Log the handshake of a WebSocket but not its messages (by default both directions
|
|
95
96
|
are recorded, up to 64 KiB per message and 2 MB or 10,000 messages per WebSocket)
|
|
97
|
+
--log <path> Follow a log file of the service (storage/logs/laravel.log) and show its new entries
|
|
98
|
+
next to the traffic, linked to the requests they were written during. Nothing written
|
|
99
|
+
before the start is read; a * in the file name follows the newest match. Can be given
|
|
100
|
+
several times. The entries stay on this machine unless --share-logs
|
|
101
|
+
--share-logs With --share and --log: teammates who watch the log also see the new entries of the
|
|
102
|
+
--log files (their coding agents only with --allow-agents). Logs often hold secrets and
|
|
103
|
+
other people's data. Neither the edge nor the control plane ever sees them
|
|
104
|
+
--log-request-id With --log: every request forwarded to the service carries X-Hopwire-Exchange-Id; a
|
|
105
|
+
service that writes it into its log gets exact links when requests overlap
|
|
96
106
|
|
|
97
107
|
Options for init:
|
|
98
108
|
--config <path> The file to write (default ${HOPWIRE_YAML_FILE} in the working directory). An existing file
|
|
@@ -156,6 +166,8 @@ Options for watch:
|
|
|
156
166
|
--agent Let a coding agent on this machine read the exchanges your teammate allowed for
|
|
157
167
|
agents (they share with --allow-agents) through hopwire mcp; never on without it.
|
|
158
168
|
What the agent reads goes to its model provider
|
|
169
|
+
--log <path> As for http: follow a log file of your own service, so the entries of your replays
|
|
170
|
+
show next to them. They stay on this machine
|
|
159
171
|
--force As for http: stop the tunnel that holds the data directory first
|
|
160
172
|
|
|
161
173
|
Global options:
|
|
@@ -189,6 +201,9 @@ const COMMAND_OPTIONS = {
|
|
|
189
201
|
'relay',
|
|
190
202
|
'allow-agents',
|
|
191
203
|
'no-ws-capture',
|
|
204
|
+
'log',
|
|
205
|
+
'share-logs',
|
|
206
|
+
'log-request-id',
|
|
192
207
|
'public',
|
|
193
208
|
'subdomain',
|
|
194
209
|
'agent',
|
|
@@ -199,7 +214,7 @@ const COMMAND_OPTIONS = {
|
|
|
199
214
|
id: [],
|
|
200
215
|
rotate: [],
|
|
201
216
|
connect: ['port', 'service', 'allow-host', 'team', 'relay'],
|
|
202
|
-
watch: ['replay-target', 'inspect', 'team', 'relay', 'agent', 'force'],
|
|
217
|
+
watch: ['replay-target', 'inspect', 'team', 'relay', 'agent', 'log', 'force'],
|
|
203
218
|
login: ['api', 'token', 'no-browser'],
|
|
204
219
|
logout: [],
|
|
205
220
|
mcp: ['read-only'],
|
|
@@ -336,8 +351,13 @@ export async function run(argv, io) {
|
|
|
336
351
|
const replayTarget = values['replay-target'] === undefined ? null : parseReplayTarget(values['replay-target']);
|
|
337
352
|
const inspectPort = parsePort(values.inspect ?? String(INSPECTOR_DEFAULT_PORT), '--inspect', 0);
|
|
338
353
|
relayNeedsTeam(values);
|
|
354
|
+
if (values.log !== undefined && replayTarget === null) {
|
|
355
|
+
throw new UsageError('--log of hopwire watch only works together with --replay-target: it shows the entries of your replays');
|
|
356
|
+
}
|
|
339
357
|
return startWatch({
|
|
340
358
|
force: values.force ?? false,
|
|
359
|
+
logs: parseLogs(values.log, io.cwd ?? process.cwd()),
|
|
360
|
+
cwd: io.cwd ?? process.cwd(),
|
|
341
361
|
logKey,
|
|
342
362
|
replayTarget,
|
|
343
363
|
inspectPort,
|
|
@@ -397,6 +417,16 @@ export async function run(argv, io) {
|
|
|
397
417
|
if (values['allow-agents'] && !values.share) {
|
|
398
418
|
throw new UsageError('--allow-agents only works together with --share');
|
|
399
419
|
}
|
|
420
|
+
if (values['share-logs'] && !values.share) {
|
|
421
|
+
throw new UsageError('--share-logs only works together with --share');
|
|
422
|
+
}
|
|
423
|
+
if (values['share-logs'] && values.log === undefined) {
|
|
424
|
+
throw new UsageError('--share-logs only works together with --log <path>');
|
|
425
|
+
}
|
|
426
|
+
if (values['log-request-id'] && values.log === undefined) {
|
|
427
|
+
throw new UsageError('--log-request-id only works together with --log <path>');
|
|
428
|
+
}
|
|
429
|
+
const logs = parseLogs(values.log, io.cwd ?? process.cwd());
|
|
400
430
|
relayNeedsTeam(values);
|
|
401
431
|
if (values.team && allow.length > 0) {
|
|
402
432
|
throw new UsageError('--team and --allow cannot be combined: with --team the team is the list');
|
|
@@ -431,12 +461,38 @@ export async function run(argv, io) {
|
|
|
431
461
|
public: values.public ? update.watch(await parsePublic(values.subdomain, io.env, dataDir)) : undefined,
|
|
432
462
|
agent: agentChoice(values),
|
|
433
463
|
captureWebSocket: !(values['no-ws-capture'] ?? false),
|
|
464
|
+
logs,
|
|
465
|
+
shareLogs: values['share-logs'] ?? false,
|
|
466
|
+
logRequestId: values['log-request-id'] ?? false,
|
|
467
|
+
cwd: io.cwd ?? process.cwd(),
|
|
434
468
|
signal: io.signal,
|
|
435
469
|
});
|
|
436
470
|
// After the lines of the start, so the mode stays the first line of every tunnel
|
|
437
471
|
update.print(io.print);
|
|
438
472
|
return running;
|
|
439
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* The files of --log, resolved against the working directory and named after themselves. Two files with the same name
|
|
476
|
+
* would label their entries alike; hopwire.yaml can name them apart.
|
|
477
|
+
*/
|
|
478
|
+
function parseLogs(values, cwd) {
|
|
479
|
+
const logs = [];
|
|
480
|
+
for (const value of values ?? []) {
|
|
481
|
+
if (value === '') {
|
|
482
|
+
throw new UsageError('--log needs the path of a log file');
|
|
483
|
+
}
|
|
484
|
+
const file = path.resolve(cwd, value);
|
|
485
|
+
if (!isFollowablePath(file)) {
|
|
486
|
+
throw new UsageError('--log takes a * only in the file name, not in a directory of the path');
|
|
487
|
+
}
|
|
488
|
+
const name = defaultLogName(file);
|
|
489
|
+
if (logs.some((log) => log.name === name)) {
|
|
490
|
+
throw new UsageError(`Two --log files are both named ${name}; give them names of their own under logs: in hopwire.yaml`);
|
|
491
|
+
}
|
|
492
|
+
logs.push({ path: file, name });
|
|
493
|
+
}
|
|
494
|
+
return logs;
|
|
495
|
+
}
|
|
440
496
|
/** The data directory: --data-dir, else HOPWIRE_HOME, else ~/.hopwire. */
|
|
441
497
|
function resolveDataDir(option, env) {
|
|
442
498
|
// A variable that is set but empty counts as not set; as a path it would be the working directory
|
|
@@ -578,6 +634,9 @@ function parse(argv) {
|
|
|
578
634
|
agent: { type: 'boolean' },
|
|
579
635
|
'no-agent': { type: 'boolean' },
|
|
580
636
|
'no-ws-capture': { type: 'boolean' },
|
|
637
|
+
log: { type: 'string', multiple: true },
|
|
638
|
+
'share-logs': { type: 'boolean' },
|
|
639
|
+
'log-request-id': { type: 'boolean' },
|
|
581
640
|
'read-only': { type: 'boolean' },
|
|
582
641
|
api: { type: 'string' },
|
|
583
642
|
token: { type: 'boolean' },
|
package/dist/commands/doctor.js
CHANGED
|
@@ -31,9 +31,14 @@ export async function doctor(options) {
|
|
|
31
31
|
print(`Network ${options.network ? await network(options) : NOT_CHECKED}`);
|
|
32
32
|
const edge = options.network ? await relayEdge(dataDir) : null;
|
|
33
33
|
print(`Relay ${options.network ? await relay(edge) : RELAY_NOT_CHECKED}`);
|
|
34
|
+
// Only with --network: the list comes from the control plane, and without it nothing leaves the machine
|
|
35
|
+
const domains = options.network ? await customDomains(dataDir, options.signal) : null;
|
|
36
|
+
for (const line of domains ?? []) {
|
|
37
|
+
print(line);
|
|
38
|
+
}
|
|
34
39
|
print('');
|
|
35
40
|
print(options.network
|
|
36
|
-
? `${edge === null ? 'Nothing was sent to us. ' : ''}The network check joined the DHT for a moment; its nodes saw the IP address of this machine.${edge === null ? '' : ' It also asked the edge of your account whether its relay answers, without a token: the edge saw the IP address, nothing else.'}`
|
|
41
|
+
? `${edge === null && domains === null ? 'Nothing was sent to us. ' : ''}The network check joined the DHT for a moment; its nodes saw the IP address of this machine.${edge === null ? '' : ' It also asked the edge of your account whether its relay answers, without a token: the edge saw the IP address, nothing else.'}${domains === null ? '' : ' It asked the control plane of your account for its custom domains, with your API token.'}`
|
|
37
42
|
: 'Nothing was sent anywhere: this report was put together on this machine without a network connection.');
|
|
38
43
|
print('It holds no keys, no tokens and no traffic. If you paste it into a bug report, read it first: the paths can name your user.');
|
|
39
44
|
}
|
|
@@ -146,6 +151,37 @@ async function relay(edge) {
|
|
|
146
151
|
? `the relay of ${edge.origin} can be reached from here: --team --relay works on this network when direct P2P does not`
|
|
147
152
|
: `the relay of ${edge.origin} cannot be reached from here (${found.problem})`;
|
|
148
153
|
}
|
|
154
|
+
/** What the control plane says about the status of a custom domain, in plain words. */
|
|
155
|
+
const DOMAIN_STATUS_WORDS = {
|
|
156
|
+
active: 'active',
|
|
157
|
+
pending_dns: 'waiting for DNS',
|
|
158
|
+
pending_certificate: 'waiting for certificate',
|
|
159
|
+
failed: 'failed',
|
|
160
|
+
offline_plan: 'off (beyond plan)',
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* The custom domains of the account, one line each, from GET /api/v1/me; null when this machine is not logged in (nothing was asked), nothing when
|
|
164
|
+
* the account has none or the control plane cannot be asked right now (the report is not about that).
|
|
165
|
+
*/
|
|
166
|
+
async function customDomains(dataDir, signal) {
|
|
167
|
+
try {
|
|
168
|
+
const stored = await readAccount(dataDir);
|
|
169
|
+
if (stored === null) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
// Loaded only here: doctor without --network never contacts the control plane
|
|
173
|
+
const { createControlPlaneClient } = await import('../control-plane-client.js');
|
|
174
|
+
const { customDomains: domains } = await createControlPlaneClient({
|
|
175
|
+
url: stored.controlPlaneUrl,
|
|
176
|
+
apiToken: stored.apiToken,
|
|
177
|
+
}).me(signal);
|
|
178
|
+
return domains.map((domain, index) => `${index === 0 ? 'Domains' : ''}`.padEnd(13) +
|
|
179
|
+
printable(`${domain.host} (${DOMAIN_STATUS_WORDS[domain.status]}; ${domain.subdomain})`));
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
149
185
|
function message(error) {
|
|
150
186
|
return printable(error instanceof Error ? error.message : String(error));
|
|
151
187
|
}
|
package/dist/commands/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, formatExchange, formatLimitReached, formatMeteredUsage, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, } from '../output.js';
|
|
1
|
+
import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, formatExchange, formatLimitReached, formatLogNotice, logLines, formatMeteredUsage, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, mainPublicUrl, publicUrlText, } from '../output.js';
|
|
2
2
|
import { startServing } from '../serve.js';
|
|
3
3
|
export { INSPECTOR_FILES } from '../serve.js';
|
|
4
4
|
/**
|
|
@@ -12,7 +12,18 @@ export async function startHttpTunnel(options) {
|
|
|
12
12
|
// The line about a tunnel --force stopped follows the startup lines: the mode stays the first line
|
|
13
13
|
const stopped = [];
|
|
14
14
|
const serving = await startServing({
|
|
15
|
-
services: [
|
|
15
|
+
services: [
|
|
16
|
+
{
|
|
17
|
+
name: options.serviceName,
|
|
18
|
+
target,
|
|
19
|
+
listenPort: options.listenPort,
|
|
20
|
+
public: options.public,
|
|
21
|
+
logs: options.logs,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
shareLogs: options.shareLogs ?? false,
|
|
25
|
+
logRequestId: options.logRequestId ?? false,
|
|
26
|
+
onLogNotice: (serviceName, line) => options.print(formatLogNotice(serviceName, line)),
|
|
16
27
|
inspectPort: options.inspectPort,
|
|
17
28
|
dataDir: options.dataDir,
|
|
18
29
|
force: options.force ?? false,
|
|
@@ -38,6 +49,7 @@ export async function startHttpTunnel(options) {
|
|
|
38
49
|
const { inspectorUrl, agentSocket, logKey, peerKey, ended, close } = serving;
|
|
39
50
|
const url = serving.services[0]?.url ?? '';
|
|
40
51
|
const publicUrl = serving.services[0]?.publicUrl ?? null;
|
|
52
|
+
const customDomains = serving.services[0]?.customDomains ?? [];
|
|
41
53
|
const subdomain = serving.services[0]?.subdomain ?? '';
|
|
42
54
|
const usage = serving.services[0]?.usage ?? null;
|
|
43
55
|
const access = serving.team === null
|
|
@@ -53,7 +65,7 @@ export async function startHttpTunnel(options) {
|
|
|
53
65
|
}
|
|
54
66
|
options.print(`Forwarding ${url} -> ${target.origin}`);
|
|
55
67
|
if (options.public !== undefined) {
|
|
56
|
-
options.print(`Public URL ${publicUrl ?? `subdomain ${subdomain} (the edge did not report its URL)`}`);
|
|
68
|
+
options.print(`Public URL ${publicUrlText(publicUrl, customDomains) ?? `subdomain ${subdomain} (the edge did not report its URL)`}`);
|
|
57
69
|
if (usage !== null) {
|
|
58
70
|
options.print(formatUsage(usage));
|
|
59
71
|
}
|
|
@@ -69,6 +81,9 @@ export async function startHttpTunnel(options) {
|
|
|
69
81
|
options.print(AGENTS_ALLOWED_LINE);
|
|
70
82
|
}
|
|
71
83
|
}
|
|
84
|
+
for (const line of logLines(serving.logs, peerKey !== null && options.shareLogs === true, options.cwd ?? process.cwd())) {
|
|
85
|
+
options.print(line);
|
|
86
|
+
}
|
|
72
87
|
if (inspectorUrl !== null) {
|
|
73
88
|
options.print(`Inspector ${inspectorUrl}`);
|
|
74
89
|
}
|
|
@@ -84,7 +99,7 @@ export async function startHttpTunnel(options) {
|
|
|
84
99
|
name: options.serviceName,
|
|
85
100
|
url,
|
|
86
101
|
target: target.origin,
|
|
87
|
-
publicUrl,
|
|
102
|
+
publicUrl: mainPublicUrl(publicUrl, customDomains),
|
|
88
103
|
stableUrl: options.public?.connectTokens !== undefined,
|
|
89
104
|
},
|
|
90
105
|
],
|
package/dist/commands/init.js
CHANGED
|
@@ -80,7 +80,7 @@ async function fromFlags(flags, dataDir) {
|
|
|
80
80
|
if (local === null) {
|
|
81
81
|
throw new UsageError(`--service ${printable(name)} needs a port or an http URL on this machine without a path, for example ${printable(name)}=3000 or ${printable(name)}=http://127.0.0.1:3000`);
|
|
82
82
|
}
|
|
83
|
-
return { name, local, public: false, subdomain: null };
|
|
83
|
+
return { name, local, public: false, subdomain: null, logs: [] };
|
|
84
84
|
});
|
|
85
85
|
const byName = new Map();
|
|
86
86
|
for (const service of services) {
|
|
@@ -147,6 +147,7 @@ async function fromFlags(flags, dataDir) {
|
|
|
147
147
|
share: flags.share,
|
|
148
148
|
team: flags.team,
|
|
149
149
|
allowAgents: flags.allowAgents,
|
|
150
|
+
shareLogs: false,
|
|
150
151
|
};
|
|
151
152
|
}
|
|
152
153
|
/** A port (`3000` becomes http://127.0.0.1:3000) or a loopback http URL without a path; null for anything else. */
|
|
@@ -208,7 +209,7 @@ async function interview(options) {
|
|
|
208
209
|
}
|
|
209
210
|
say('Give a port, for example 3000, or an http URL on this machine without a path, for example http://127.0.0.1:3000.');
|
|
210
211
|
}
|
|
211
|
-
const service = { name, local, public: false, subdomain: null };
|
|
212
|
+
const service = { name, local, public: false, subdomain: null, logs: [] };
|
|
212
213
|
if (typeof urls === 'object') {
|
|
213
214
|
service.public = await yesNo('Serve it under a public URL?');
|
|
214
215
|
if (service.public) {
|
|
@@ -234,15 +235,37 @@ async function interview(options) {
|
|
|
234
235
|
say(urls === 'logged-out' ? PUBLIC_NEEDS_LOGIN : NO_EDGE);
|
|
235
236
|
toldAboutPublic = true;
|
|
236
237
|
}
|
|
238
|
+
// Phase 15: nothing is followed that was not named here
|
|
239
|
+
for (;;) {
|
|
240
|
+
const suggested = services.length === 0 && (await present(path.join(options.cwd, LARAVEL_LOG)));
|
|
241
|
+
const answer = await question('Log file to show next to the traffic (empty for none)', suggested ? LARAVEL_LOG : null);
|
|
242
|
+
if (answer === '') {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
if (printable(answer) !== answer || path.dirname(answer).includes('*')) {
|
|
246
|
+
say('Give the path of a log file, with a * at most in the file name, or nothing.');
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
// In the file the path is relative to its folder
|
|
250
|
+
const absolute = path.resolve(options.cwd, answer);
|
|
251
|
+
const relative = path.relative(path.dirname(options.file), absolute);
|
|
252
|
+
service.logs.push(path.isAbsolute(answer) || relative.startsWith('..') ? absolute : relative);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
237
255
|
services.push(service);
|
|
238
256
|
} while (await yesNo('Another service?'));
|
|
239
257
|
const share = await yesNo('Share with teammates over P2P (hopwire watch, hopwire connect)?');
|
|
240
258
|
let team = false;
|
|
241
259
|
let allowAgents = false;
|
|
260
|
+
let shareLogs = false;
|
|
242
261
|
if (share) {
|
|
243
262
|
if (urls !== 'logged-out') {
|
|
244
263
|
team = await yesNo("Only machines of your organisation's members (Team plan)?");
|
|
245
264
|
}
|
|
265
|
+
if (services.some((service) => service.logs.length > 0)) {
|
|
266
|
+
say("Logs often hold secrets and other people's data.");
|
|
267
|
+
shareLogs = await yesNo('Show the log entries to teammates who watch too?');
|
|
268
|
+
}
|
|
246
269
|
say("What a teammate's coding agent reads goes to its model provider.");
|
|
247
270
|
allowAgents = await yesNo("Let teammates' coding agents read what is captured?");
|
|
248
271
|
}
|
|
@@ -254,8 +277,11 @@ async function interview(options) {
|
|
|
254
277
|
share,
|
|
255
278
|
team,
|
|
256
279
|
allowAgents,
|
|
280
|
+
shareLogs,
|
|
257
281
|
};
|
|
258
282
|
}
|
|
283
|
+
/** The log file `hopwire init` suggests when the working directory has it. */
|
|
284
|
+
const LARAVEL_LOG = 'storage/logs/laravel.log';
|
|
259
285
|
// --- The port suggestion ---
|
|
260
286
|
/**
|
|
261
287
|
* The port suggested for the first service, never used with --yes: PORT=<n> in .env of the working directory (only
|
package/dist/commands/up.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
import { LOCAL_ENTRY_DEFAULT_PORT, RANDOM_SUBDOMAIN_BYTES, randomSubdomain } from '@hopwire/protocol';
|
|
3
4
|
import { HopwireError } from '../errors.js';
|
|
4
|
-
import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, formatExchange, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, } from '../output.js';
|
|
5
|
+
import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, relayLine, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, formatExchange, formatLogNotice, logLines, formatRelayEvent, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, mainPublicUrl, publicUrlText, } from '../output.js';
|
|
5
6
|
import { startServing } from '../serve.js';
|
|
6
7
|
import { formatBridgeEvent } from './http.js';
|
|
7
8
|
/**
|
|
@@ -30,6 +31,11 @@ export async function startUp(options) {
|
|
|
30
31
|
listenPort: port > 65535 ? 0 : port,
|
|
31
32
|
listenFallback: true,
|
|
32
33
|
public: publicOptions(service, config, options),
|
|
34
|
+
// Relative to the folder of hopwire.yaml
|
|
35
|
+
logs: service.logs.map((log) => ({
|
|
36
|
+
name: log.name,
|
|
37
|
+
path: path.resolve(path.dirname(path.resolve(options.configFile)), log.path),
|
|
38
|
+
})),
|
|
33
39
|
};
|
|
34
40
|
});
|
|
35
41
|
// The line about a tunnel --force stopped follows the startup lines: the mode stays the first line
|
|
@@ -51,6 +57,9 @@ export async function startUp(options) {
|
|
|
51
57
|
inspectorFiles: options.inspectorFiles,
|
|
52
58
|
agent: options.agent,
|
|
53
59
|
captureWebSocketMessages: config.captureWebSocket,
|
|
60
|
+
shareLogs: config.shareLogs,
|
|
61
|
+
logRequestId: config.logRequestId,
|
|
62
|
+
onLogNotice: (name, line) => options.print(formatLogNotice(name, line, config.services.length)),
|
|
54
63
|
signal: options.signal,
|
|
55
64
|
listenOption: 'a free port',
|
|
56
65
|
inspectOption: 'inspector.port in hopwire.yaml',
|
|
@@ -76,7 +85,8 @@ export async function startUp(options) {
|
|
|
76
85
|
}
|
|
77
86
|
options.print(`Forwarding ${service.url} -> ${service.target}`);
|
|
78
87
|
if (service.subdomain !== null) {
|
|
79
|
-
const url = service.publicUrl
|
|
88
|
+
const url = publicUrlText(service.publicUrl, service.customDomains) ??
|
|
89
|
+
`subdomain ${service.subdomain} (the edge did not report its URL)`;
|
|
80
90
|
options.print(`Public URL ${url}${settings?.basicAuth == null ? '' : ' (asks for the user and password of auth.basic)'}`);
|
|
81
91
|
if (service.usage !== null) {
|
|
82
92
|
options.print(formatUsage(service.usage));
|
|
@@ -94,6 +104,9 @@ export async function startUp(options) {
|
|
|
94
104
|
options.print(AGENTS_ALLOWED_LINE);
|
|
95
105
|
}
|
|
96
106
|
}
|
|
107
|
+
for (const line of logLines(serving.logs, serving.peerKey !== null && config.shareLogs, path.dirname(path.resolve(options.configFile)), config.services.length)) {
|
|
108
|
+
options.print(line);
|
|
109
|
+
}
|
|
97
110
|
options.print(`Inspector ${serving.inspectorUrl ?? ''}`);
|
|
98
111
|
if (serving.agentSocket !== null) {
|
|
99
112
|
const [first, ...rest] = serving.services;
|
|
@@ -107,7 +120,7 @@ export async function startUp(options) {
|
|
|
107
120
|
name: service.name,
|
|
108
121
|
url: service.url,
|
|
109
122
|
target: service.target,
|
|
110
|
-
publicUrl: service.publicUrl,
|
|
123
|
+
publicUrl: mainPublicUrl(service.publicUrl, service.customDomains),
|
|
111
124
|
basicAuth: config.services[index]?.basicAuth != null,
|
|
112
125
|
stableUrl: options.connectTokens !== undefined,
|
|
113
126
|
})),
|
package/dist/commands/watch.js
CHANGED
|
@@ -2,11 +2,12 @@ import { openOwnLog } from '../data-dir-holder.js';
|
|
|
2
2
|
import { startAgentSocket } from '../agent-socket.js';
|
|
3
3
|
import { HopwireError, listenError } from '../errors.js';
|
|
4
4
|
import { loadOrCreateIdentity } from '../identity.js';
|
|
5
|
-
import { agentsOnly, createInspectorApi } from '../inspector-api.js';
|
|
5
|
+
import { agentsOnly, createInspectorApi, withLocalLogs } from '../inspector-api.js';
|
|
6
6
|
import { startInspectorServer } from '../inspector-server.js';
|
|
7
7
|
import { createInterceptor } from '../interceptor.js';
|
|
8
|
+
import { InFlightExchanges, followLogFile } from '../log-follow.js';
|
|
8
9
|
import { REMOTE_LOG_BUDGET_BYTES } from '../log.js';
|
|
9
|
-
import { MODE_P2P, MODE_P2P_RELAYED, MODE_P2P_TEAM, formatExchange, printable, relayedLine, shortKey, watchAgentLine, watchGuide, } from '../output.js';
|
|
10
|
+
import { MODE_P2P, MODE_P2P_RELAYED, MODE_P2P_TEAM, formatExchange, formatLogNotice, logLines, printable, relayedLine, shortKey, watchAgentLine, watchGuide, } from '../output.js';
|
|
10
11
|
import { INSPECTOR_FILES } from '../serve.js';
|
|
11
12
|
import { Supervisor, unlessAborted } from '../supervisor.js';
|
|
12
13
|
/**
|
|
@@ -76,6 +77,30 @@ export async function startWatch(options) {
|
|
|
76
77
|
// here, instead of an inspector that stays empty
|
|
77
78
|
throw joinError('no_connection', logKey, peerKey, options.team !== undefined);
|
|
78
79
|
}
|
|
80
|
+
// The watcher's own log files: never shared, so into the local-only core
|
|
81
|
+
const logs = options.replayTarget === null ? [] : (options.logs ?? []);
|
|
82
|
+
let localLogs = null;
|
|
83
|
+
const inFlight = logs.length > 0 ? new InFlightExchanges() : undefined;
|
|
84
|
+
const followed = [];
|
|
85
|
+
if (inFlight !== undefined && options.replayTarget !== null) {
|
|
86
|
+
const local = await own.openLocalLogs();
|
|
87
|
+
localLogs = local;
|
|
88
|
+
supervisor.add('store', () => local.close());
|
|
89
|
+
const serviceName = options.replayTarget.host;
|
|
90
|
+
for (const file of logs) {
|
|
91
|
+
proceed();
|
|
92
|
+
const follower = await followLogFile({
|
|
93
|
+
...file,
|
|
94
|
+
serviceName,
|
|
95
|
+
inFlight,
|
|
96
|
+
append: (block) => local.append(block),
|
|
97
|
+
onNotice: (line) => options.print(formatLogNotice(serviceName, line)),
|
|
98
|
+
});
|
|
99
|
+
supervisor.add('servers', () => follower.stop());
|
|
100
|
+
followed.push({ serviceName, name: file.name, path: file.path, waiting: follower.waiting });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const ownSource = withLocalLogs(own, localLogs);
|
|
79
104
|
// Replays keep the service name of the exchange they repeat
|
|
80
105
|
const interceptors = new Map();
|
|
81
106
|
const replayThrough = (serviceName) => {
|
|
@@ -88,6 +113,7 @@ export async function startWatch(options) {
|
|
|
88
113
|
target: options.replayTarget,
|
|
89
114
|
serviceName,
|
|
90
115
|
log: own,
|
|
116
|
+
inFlight,
|
|
91
117
|
onExchange: (exchange) => options.print(formatExchange(exchange)),
|
|
92
118
|
onLogError: () => options.print('Could not write to the traffic log; the replay was still sent'),
|
|
93
119
|
});
|
|
@@ -109,7 +135,7 @@ export async function startWatch(options) {
|
|
|
109
135
|
staticDir: options.inspectorFiles ?? INSPECTOR_FILES,
|
|
110
136
|
sources: [
|
|
111
137
|
{ origin: 'remote', log: remote },
|
|
112
|
-
{ origin: 'own', log:
|
|
138
|
+
{ origin: 'own', log: ownSource },
|
|
113
139
|
],
|
|
114
140
|
status: () => status,
|
|
115
141
|
replayThrough: (exchange) => replayThrough(exchange.serviceName),
|
|
@@ -124,7 +150,7 @@ export async function startWatch(options) {
|
|
|
124
150
|
const api = createInspectorApi({
|
|
125
151
|
sources: [
|
|
126
152
|
{ origin: 'remote', log: agentsOnly(remote) },
|
|
127
|
-
{ origin: 'own', log:
|
|
153
|
+
{ origin: 'own', log: ownSource },
|
|
128
154
|
],
|
|
129
155
|
status: () => status,
|
|
130
156
|
replayThrough: (exchange) => replayThrough(exchange.serviceName),
|
|
@@ -151,6 +177,9 @@ export async function startWatch(options) {
|
|
|
151
177
|
options.print(options.replayTarget === null
|
|
152
178
|
? 'Replay off; start hopwire watch with --replay-target <url> to replay to a local service'
|
|
153
179
|
: `Replay to ${options.replayTarget.origin}`);
|
|
180
|
+
for (const line of logLines(followed, false, options.cwd ?? process.cwd())) {
|
|
181
|
+
options.print(line);
|
|
182
|
+
}
|
|
154
183
|
options.print(`Inspector ${inspector.url}`);
|
|
155
184
|
if (agentSocket !== null) {
|
|
156
185
|
options.print(watchAgentLine(agentSocket, options.replayTarget?.origin ?? null));
|
package/dist/config-template.js
CHANGED
|
@@ -23,6 +23,9 @@ export function renderConfig(answers) {
|
|
|
23
23
|
'# 2 MB or 10,000 messages per WebSocket). Uncomment to record the handshake only, as --no-ws-capture does.',
|
|
24
24
|
'# capture:',
|
|
25
25
|
'# websocket: false',
|
|
26
|
+
'# # Every request forwarded to a service carries X-Hopwire-Exchange-Id; a service that writes it into its',
|
|
27
|
+
'# # log (Log::withContext in Laravel) gets exact links between its log entries and the requests.',
|
|
28
|
+
'# logRequestId: true',
|
|
26
29
|
'',
|
|
27
30
|
];
|
|
28
31
|
if (answers.edgeUrl !== null && answers.controlPlaneUrl !== null) {
|
|
@@ -38,13 +41,20 @@ export function renderConfig(answers) {
|
|
|
38
41
|
else {
|
|
39
42
|
lines.push(`${INDENT}# Only these public keys may watch and connect (each teammate prints theirs with \`hopwire id\`).`, `${INDENT}# Without the list everyone who has the keys gets in.`, `${INDENT}# allow:`, `${INDENT}# - 0000000000000000000000000000000000000000000000000000000000000000`, `${INDENT}# Instead of the list: only machines of the members of your organisation (Team plan, \`hopwire login\`).`, `${INDENT}# The control plane of your account then names the keys of the team; your traffic still passes no server.`, `${INDENT}# team: true`);
|
|
40
43
|
}
|
|
41
|
-
lines.push(`${INDENT}# With team: teammates whose network allows no direct connection (UDP blocked, strict NAT on both sides) come`, `${INDENT}# in through the relay of your account's edge on port 443, end-to-end encrypted. Direct P2P is tried first.`, `${INDENT}# relay: true`, `${INDENT}# With share: the coding agents of teammates who watch the log (\`hopwire watch --agent\`) may read the`, `${INDENT}# exchanges captured from now on. What an agent reads goes to its model provider.`, answers.allowAgents ? `${INDENT}allowAgents: true` : `${INDENT}# allowAgents: true`, '', '# One entry per local service; the name shows in the inspector and is what a teammate passes to --service.', '# Every service gets a loopback entry point, counted up from 4041 in the order of this file (the port of the', '# inspector is left out).', 'services:');
|
|
44
|
+
lines.push(`${INDENT}# With team: teammates whose network allows no direct connection (UDP blocked, strict NAT on both sides) come`, `${INDENT}# in through the relay of your account's edge on port 443, end-to-end encrypted. Direct P2P is tried first.`, `${INDENT}# relay: true`, `${INDENT}# With share: the coding agents of teammates who watch the log (\`hopwire watch --agent\`) may read the`, `${INDENT}# exchanges captured from now on. What an agent reads goes to its model provider.`, answers.allowAgents ? `${INDENT}allowAgents: true` : `${INDENT}# allowAgents: true`, `${INDENT}# With share: teammates who watch the log also see the new entries of the services' log files (logs:).`, `${INDENT}# Logs often hold secrets and other people's data; their coding agents read them only with allowAgents.`, answers.shareLogs ? `${INDENT}shareLogs: true` : `${INDENT}# shareLogs: true`, '', '# One entry per local service; the name shows in the inspector and is what a teammate passes to --service.', '# Every service gets a loopback entry point, counted up from 4041 in the order of this file (the port of the', '# inspector is left out).', 'services:');
|
|
42
45
|
answers.services.forEach((service, index) => {
|
|
43
46
|
if (index > 0) {
|
|
44
47
|
lines.push('');
|
|
45
48
|
}
|
|
46
49
|
lines.push(`${INDENT}${yamlKey(service.name)}:`, `${INDENT}${INDENT}# An http URL on this machine without a path.`);
|
|
47
50
|
lines.push(`${INDENT}${INDENT}local: ${service.local.origin}`);
|
|
51
|
+
lines.push(`${INDENT}${INDENT}# Log files whose new entries are shown next to the traffic, linked to the requests they were written`, `${INDENT}${INDENT}# during (nothing written before the start is read). Relative to this file; a * in the file name follows`, `${INDENT}${INDENT}# the newest match. They stay on this machine unless p2p.shareLogs.`);
|
|
52
|
+
if (service.logs.length > 0) {
|
|
53
|
+
lines.push(`${INDENT}${INDENT}logs:`, ...service.logs.map((log) => `${INDENT}${INDENT}${INDENT}- ${JSON.stringify(log)}`));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
lines.push(`${INDENT}${INDENT}# logs:`, `${INDENT}${INDENT}# - storage/logs/laravel.log`);
|
|
57
|
+
}
|
|
48
58
|
if (!service.public) {
|
|
49
59
|
return;
|
|
50
60
|
}
|
package/dist/config.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
import { parseDocument } from 'yaml';
|
|
3
4
|
import { INSPECTOR_DEFAULT_PORT, HOPWIRE_YAML_FILE, HOPWIRE_YAML_VERSION, isBasicCredentials, isPublicKeyHex, isReservableSubdomain, } from '@hopwire/protocol';
|
|
4
5
|
import { HopwireError } from './errors.js';
|
|
6
|
+
import { defaultLogName } from './log-follow.js';
|
|
5
7
|
import { printable } from './output.js';
|
|
6
8
|
import { parseControlPlaneUrl, parseEdgeUrl, parseLocalTarget } from './urls.js';
|
|
7
9
|
/** A hopwire.yaml that cannot be used. `path` is the offending field, null when the file as a whole is at fault. */
|
|
@@ -24,7 +26,7 @@ class Problem {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
const ROOT_KEYS = ['version', 'inspector', 'agent', 'capture', 'edge', 'controlPlane', 'p2p', 'services'];
|
|
27
|
-
const SERVICE_KEYS = ['local', 'public', 'subdomain', 'auth'];
|
|
29
|
+
const SERVICE_KEYS = ['local', 'public', 'subdomain', 'auth', 'logs'];
|
|
28
30
|
const LOCAL_RULE = 'must be an http URL on this machine without a path, for example http://127.0.0.1:3000; Hopwire only forwards to loopback addresses.';
|
|
29
31
|
const SUBDOMAIN_RULE = 'must be 3 to 63 lowercase letters, digits or hyphens, must not start or end with a hyphen, must not start with t- and must not be a reserved name such as www or api.';
|
|
30
32
|
/**
|
|
@@ -144,9 +146,14 @@ function validate(value, ordered) {
|
|
|
144
146
|
let team = false;
|
|
145
147
|
let allowAgents = false;
|
|
146
148
|
let relay = false;
|
|
149
|
+
let shareLogs = false;
|
|
147
150
|
if (root.p2p !== undefined) {
|
|
148
|
-
const p2p = mapping(root.p2p, ['p2p'], ['share', 'allow', 'team', 'allowAgents', 'relay'], 'p2p');
|
|
151
|
+
const p2p = mapping(root.p2p, ['p2p'], ['share', 'allow', 'team', 'allowAgents', 'relay', 'shareLogs'], 'p2p');
|
|
149
152
|
share = boolean(p2p.share, ['p2p', 'share']);
|
|
153
|
+
shareLogs = boolean(p2p.shareLogs, ['p2p', 'shareLogs']);
|
|
154
|
+
if (shareLogs && !share) {
|
|
155
|
+
throw new Problem(['p2p', 'shareLogs'], 'needs p2p.share: true; it lets teammates who watch the shared log see the entries of the log files.');
|
|
156
|
+
}
|
|
150
157
|
team = boolean(p2p.team, ['p2p', 'team']);
|
|
151
158
|
allowAgents = boolean(p2p.allowAgents, ['p2p', 'allowAgents']);
|
|
152
159
|
relay = boolean(p2p.relay, ['p2p', 'relay']);
|
|
@@ -201,13 +208,18 @@ function validate(value, ordered) {
|
|
|
201
208
|
if (edgeUrl === null && services.some((service) => service.public)) {
|
|
202
209
|
throw new Problem(['edge', 'url'], 'is missing, and a service is public; add the URL of the edge, for example ws://127.0.0.1:8787 for a local edge.');
|
|
203
210
|
}
|
|
211
|
+
if (shareLogs && services.every((service) => service.logs.length === 0)) {
|
|
212
|
+
throw new Problem(['p2p', 'shareLogs'], 'needs a service with logs; name the log files to share under services.<name>.logs.');
|
|
213
|
+
}
|
|
204
214
|
const agent = root.agent === undefined ? null : boolean(root.agent, ['agent']);
|
|
205
215
|
let captureWebSocket = true;
|
|
216
|
+
let logRequestId = false;
|
|
206
217
|
if (root.capture !== undefined) {
|
|
207
|
-
const capture = mapping(root.capture, ['capture'], ['websocket'], 'capture');
|
|
218
|
+
const capture = mapping(root.capture, ['capture'], ['websocket', 'logRequestId'], 'capture');
|
|
208
219
|
if (capture.websocket !== undefined) {
|
|
209
220
|
captureWebSocket = boolean(capture.websocket, ['capture', 'websocket']);
|
|
210
221
|
}
|
|
222
|
+
logRequestId = boolean(capture.logRequestId, ['capture', 'logRequestId']);
|
|
211
223
|
}
|
|
212
224
|
return {
|
|
213
225
|
inspectorPort,
|
|
@@ -220,6 +232,8 @@ function validate(value, ordered) {
|
|
|
220
232
|
relay,
|
|
221
233
|
agent,
|
|
222
234
|
captureWebSocket,
|
|
235
|
+
logRequestId,
|
|
236
|
+
shareLogs,
|
|
223
237
|
services,
|
|
224
238
|
};
|
|
225
239
|
}
|
|
@@ -284,7 +298,47 @@ function validateService(name, value) {
|
|
|
284
298
|
basicAuth = auth.basic;
|
|
285
299
|
}
|
|
286
300
|
}
|
|
287
|
-
return {
|
|
301
|
+
return {
|
|
302
|
+
name,
|
|
303
|
+
local,
|
|
304
|
+
public: boolean(service.public, [...path, 'public']),
|
|
305
|
+
subdomain,
|
|
306
|
+
basicAuth,
|
|
307
|
+
logs: validateLogs(service.logs, [...path, 'logs']),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
const LOG_PATH_RULE = 'must be the path of a log file, relative to the folder of this file or absolute, with a * at most in the file name.';
|
|
311
|
+
/** services.<name>.logs: a list of paths, or of mappings with path and name. */
|
|
312
|
+
function validateLogs(value, at) {
|
|
313
|
+
if (value === undefined) {
|
|
314
|
+
return [];
|
|
315
|
+
}
|
|
316
|
+
if (!Array.isArray(value)) {
|
|
317
|
+
throw new Problem(at, 'must be a list of log files, each a path or a mapping with path and name.');
|
|
318
|
+
}
|
|
319
|
+
const logs = [];
|
|
320
|
+
for (const [index, item] of value.entries()) {
|
|
321
|
+
let file = item;
|
|
322
|
+
let name;
|
|
323
|
+
if (isMapping(item)) {
|
|
324
|
+
const log = mapping(item, [...at, index], ['path', 'name'], 'a log file');
|
|
325
|
+
file = log.path;
|
|
326
|
+
name = log.name;
|
|
327
|
+
}
|
|
328
|
+
if (typeof file !== 'string' || file === '' || printable(file) !== file || path.dirname(file).includes('*')) {
|
|
329
|
+
throw new Problem(isMapping(item) ? [...at, index, 'path'] : [...at, index], LOG_PATH_RULE);
|
|
330
|
+
}
|
|
331
|
+
if (name !== undefined &&
|
|
332
|
+
(typeof name !== 'string' || name === '' || name.length > 255 || printable(name) !== name)) {
|
|
333
|
+
throw new Problem([...at, index, 'name'], 'must be a name of 1 to 255 characters without control characters.');
|
|
334
|
+
}
|
|
335
|
+
const named = typeof name === 'string' ? name : defaultLogName(file);
|
|
336
|
+
if (logs.some((log) => log.name === named)) {
|
|
337
|
+
throw new Problem([...at, index], `is named ${printable(named)} like another log file of this service; give it a name of its own with name:.`);
|
|
338
|
+
}
|
|
339
|
+
logs.push({ path: file, name: named });
|
|
340
|
+
}
|
|
341
|
+
return logs;
|
|
288
342
|
}
|
|
289
343
|
function isMapping(value) {
|
|
290
344
|
return typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date);
|