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
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | |
| 4 | /** |
| 5 | * Shared scaffolding for Amazon Inspector (Inspector2) HTTP bindings. |
| 6 | * |
| 7 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 8 | * a `Layer.effect(Cap, makeInspector2AccountHttpBinding({ … }))` over the |
| 9 | * builder below. Everything except the operation and the IAM action list is |
| 10 | * boilerplate. |
| 11 | * |
| 12 | * All Inspector2 runtime operations are account-scoped: the service's IAM |
| 13 | * actions do not support resource-level scoping (Inspector evaluates them |
| 14 | * against `*`), so the deploy-time half always grants `actions` on `*`. |
| 15 | */ |
| 16 | export const makeInspector2AccountHttpBinding = <I, A, E, R>(options: { |
| 17 | /** Fully-qualified binding tag, e.g. `AWS.Inspector2.ListFindings`. */ |
| 18 | tag: string; |
| 19 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 20 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 21 | /** IAM actions granted on `*`. */ |
| 22 | actions: readonly string[]; |
| 23 | }) => |
| 24 | Effect.gen(function* () { |
| 25 | const bind = yield* AWSBindings.Bind; |
| 26 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 27 | |
| 28 | return Effect.fn(function* () { |
| 29 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 30 | yield* bind`${options.tag}()`({ |
| 31 | policyStatements: [ |
| 32 | { |
| 33 | Effect: "Allow", |
| 34 | Action: [...options.actions], |
| 35 | Resource: ["*"], |
| 36 | }, |
| 37 | ], |
| 38 | }); |
| 39 | } |
| 40 | return Effect.fn(options.tag)(function* (request?: I) { |
| 41 | return yield* op((request ?? {}) as I); |
| 42 | }); |
| 43 | }); |
| 44 | }); |