mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
279c590ef6
Adapt the forwarding proposal in #4652 with a required signal before optional resource diagnostics. Migrate all callers and cover actual command registration during final close. Refs #4939. Co-authored-by: Tapraj-Pathak <165466587+Tapraj-Pathak@users.noreply.github.com>
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { z } from "incur";
|
|
import { PcapAnalysisService } from "../application/pcap/PcapAnalysisService.js";
|
|
import type { PcapAnalysisPort } from "../application/pcap/PcapAnalysisPort.js";
|
|
import { createPcapAnalysisProvider } from "../composition/pcap.js";
|
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
|
import { logCliCommand } from "../cliLogging.js";
|
|
import type { PcapOperation } from "../domain/pcap/pcapAnalysis.js";
|
|
import type { Logger } from "pino";
|
|
import type { CliInstance } from "./types.js";
|
|
import { withCommandCancellation } from "./commandCancellation.js";
|
|
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
|
|
/** Expose the same explicit pcap requests through one-shot CLI commands. */
|
|
export const registerPcapCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
environment: Readonly<Record<string, string | undefined>>,
|
|
provider: PcapAnalysisPort = createPcapAnalysisProvider(environment),
|
|
): void => {
|
|
const service = new PcapAnalysisService(provider);
|
|
const execute = (name: string, operation: PcapOperation, input: unknown) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, name, () =>
|
|
finishAnalysisCommand(
|
|
() => service.execute(operation, input, { signal }),
|
|
{ close: () => provider.close() },
|
|
"pcap",
|
|
operation,
|
|
signal,
|
|
),
|
|
),
|
|
);
|
|
|
|
cli.command(CLI_COMMANDS.inspectPcapClient, {
|
|
description:
|
|
"Inspect the caller-selected tshark and capinfos binaries without reading a capture",
|
|
args: z.object({}),
|
|
run: () =>
|
|
execute(CLI_COMMANDS.inspectPcapClient, "inspect_pcap_client", {}),
|
|
});
|
|
cli.command(CLI_COMMANDS.inspectPcapCapture, {
|
|
description:
|
|
"Inspect one pcap/pcapng capture: endpoints, DNS, TLS SNI, and protocol distribution",
|
|
args: z.object({
|
|
path: z
|
|
.string()
|
|
.min(1)
|
|
.describe("Local pcap or pcapng capture file to inspect"),
|
|
}),
|
|
run: ({ args }) =>
|
|
execute(CLI_COMMANDS.inspectPcapCapture, "inspect_pcap_capture", {
|
|
path: args.path,
|
|
}),
|
|
});
|
|
};
|