@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 47 lines 1.79 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared scaffolding for AWS Security Hub HTTP bindings.
6 *
7 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
8 * a `Layer.effect(Cap, makeSecurityHubHttpBinding({ … }))` over the builder
9 * below. Everything except the operation and the IAM action list is
10 * boilerplate.
11 *
12 * Security Hub is an account/region singleton service: every operation is
13 * implicitly scoped to the caller's Hub, so there is no identifier to inject —
14 * the caller's request is passed through as-is. The deploy-time half grants
15 * `actions` on `*`: Security Hub IAM actions are evaluated against the
16 * account's `hub/default` ARN (or take no resource at all), which is not
17 * known until runtime and gains nothing from ARN-scoping within one account.
18 */
19 export const makeSecurityHubHttpBinding = <I, A, E, R>(options: {
20 /** Fully-qualified binding tag, e.g. `AWS.SecurityHub.GetFindings`. */
21 tag: string;
22 /** The distilled operation, invoked with the caller's request as-is. */
23 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
24 /** IAM actions granted on `*`. */
25 actions: readonly string[];
26 }) =>
27 Effect.gen(function* () {
28 const bind = yield* AWSBindings.Bind;
29 const op = yield* AWSBindings.withCredentials(options.operation);
30
31 return Effect.fn(function* () {
32 if (!globalThis.__ALCHEMY_RUNTIME__) {
33 yield* bind`${options.tag}()`({
34 policyStatements: [
35 {
36 Effect: "Allow",
37 Action: [...options.actions],
38 Resource: ["*"],
39 },
40 ],
41 });
42 }
43 return Effect.fn(options.tag)(function* (request?: I) {
44 return yield* op((request ?? {}) as I);
45 });
46 });
47 });