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, 06:00 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | import type { PolicyStatement } from "../IAM/Policy.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared HTTP scaffolding for the IAM Roles Anywhere runtime bindings. |
| 7 | * |
| 8 | * Subjects (the certificate identities Roles Anywhere records for every |
| 9 | * authentication attempt) are account-scoped audit records chosen per request |
| 10 | * at runtime, so every binding is account-level and grants its action(s) on |
| 11 | * `Resource: ["*"]`. |
| 12 | * |
| 13 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 14 | * a `Layer.effect(Cap, makeRolesAnywhereHttpBinding({ … }))` over the builder |
| 15 | * below. Everything except the operation and the IAM action list is |
| 16 | * boilerplate. |
| 17 | */ |
| 18 | export const makeRolesAnywhereHttpBinding = <I, A, E, R>(options: { |
| 19 | /** |
| 20 | * Short capability name used in the binding sid and runtime span, e.g. |
| 21 | * `"ListSubjects"`. |
| 22 | */ |
| 23 | capability: string; |
| 24 | /** |
| 25 | * IAM actions granted on `Resource: ["*"]` (the target subjects are chosen |
| 26 | * per request at runtime and unknowable at deploy time). |
| 27 | */ |
| 28 | iamActions: readonly string[]; |
| 29 | /** |
| 30 | * The distilled operation implementing the capability. |
| 31 | */ |
| 32 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 33 | }) => |
| 34 | Effect.gen(function* () { |
| 35 | const bind = yield* AWSBindings.Bind; |
| 36 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 37 | |
| 38 | return Effect.fn(function* () { |
| 39 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 40 | const policyStatements: PolicyStatement[] = [ |
| 41 | { |
| 42 | Effect: "Allow", |
| 43 | Action: [...options.iamActions], |
| 44 | // The target subjects are chosen per request at runtime. |
| 45 | Resource: ["*"], |
| 46 | }, |
| 47 | ]; |
| 48 | yield* bind`AWS.RolesAnywhere.${options.capability}()`({ |
| 49 | policyStatements, |
| 50 | }); |
| 51 | } |
| 52 | return Effect.fn(`AWS.RolesAnywhere.${options.capability}`)(function* (request?: I) { |
| 53 | return yield* op((request ?? {}) as I); |
| 54 | }); |
| 55 | }); |
| 56 | }); |