strfry-policies/scripts/filter.ts
2023-03-28 16:14:19 -05:00

33 lines
757 B
TypeScript

import { readLines } from '../src/deps.ts';
import type { Event, InputMessage, OutputMessage } from '../mod.ts';
for await (const line of readLines(Deno.stdin)) {
const event: Event = JSON.parse(line);
const input: InputMessage = {
type: 'new',
event: event,
receivedAt: Date.now() / 1000,
sourceType: 'IP4',
sourceInfo: '127.0.0.1',
};
const policy = Deno.run({
cmd: Deno.args,
stdin: 'piped',
stdout: 'piped',
});
await policy.stdin.write(new TextEncoder().encode(JSON.stringify(input)));
policy.stdin.close();
for await (const out of readLines(policy.stdout)) {
const msg: OutputMessage = JSON.parse(out);
if (msg.action === 'accept') {
console.log(JSON.stringify(event));
}
}
}