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 | import type { CertificateAuthority } from "./CertificateAuthority.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Options for {@link makeACMPCAHttpBinding}. |
| 7 | * |
| 8 | * @internal shared HTTP scaffolding for the ACM PCA capability bindings — |
| 9 | * not exported from the service index. |
| 10 | */ |
| 11 | export interface ACMPCAHttpBindingOptions< |
| 12 | Req extends { CertificateAuthorityArn: string }, |
| 13 | A, |
| 14 | E, |
| 15 | R, |
| 16 | > { |
| 17 | /** |
| 18 | * The ACM PCA action name, e.g. `"IssueCertificate"`. Used verbatim for |
| 19 | * the IAM action (`acm-pca:{action}`), the bind label, and the tracing |
| 20 | * span name. |
| 21 | */ |
| 22 | action: string; |
| 23 | /** |
| 24 | * The distilled ACM PCA operation. Every ACM PCA data-plane operation is |
| 25 | * keyed by `CertificateAuthorityArn`, which the binding injects from the |
| 26 | * bound {@link CertificateAuthority}. |
| 27 | */ |
| 28 | operation: Effect.Effect<(request: Req) => Effect.Effect<A, E>, never, R>; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Build the implementation Effect for an ACM PCA HTTP capability binding. |
| 33 | * |
| 34 | * Every ACM PCA capability has the same shape — resolve the CA's ARN, |
| 35 | * register an IAM policy statement for `acm-pca:{action}` scoped to that |
| 36 | * CA at deploy time, and return a runtime callable that injects |
| 37 | * `CertificateAuthorityArn` into the operation's request. Only the |
| 38 | * operation and the action name differ, so each `{Op}Http.ts` is a thin |
| 39 | * `Layer.effect(Cap, makeACMPCAHttpBinding({ ... }))`. |
| 40 | * |
| 41 | * @internal |
| 42 | */ |
| 43 | export const makeACMPCAHttpBinding = <Req extends { CertificateAuthorityArn: string }, A, E, R>( |
| 44 | options: ACMPCAHttpBindingOptions<Req, A, E, R>, |
| 45 | ) => |
| 46 | Effect.gen(function* () { |
| 47 | const bind = yield* AWSBindings.Bind; |
| 48 | const operation = yield* AWSBindings.withCredentials(options.operation); |
| 49 | |
| 50 | return Effect.fn(function* (certificateAuthority: CertificateAuthority) { |
| 51 | const Arn = yield* certificateAuthority.certificateAuthorityArn; |
| 52 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 53 | yield* bind`AWS.ACMPCA.${options.action}(${certificateAuthority})`({ |
| 54 | policyStatements: [ |
| 55 | { |
| 56 | Effect: "Allow", |
| 57 | Action: [`acm-pca:${options.action}`], |
| 58 | Resource: [certificateAuthority.certificateAuthorityArn], |
| 59 | }, |
| 60 | ], |
| 61 | }); |
| 62 | } |
| 63 | return Effect.fn(`AWS.ACMPCA.${options.action}(${certificateAuthority.LogicalId})`)( |
| 64 | function* ( |
| 65 | request: Omit<Req, "CertificateAuthorityArn"> = {} as Omit< |
| 66 | Req, |
| 67 | "CertificateAuthorityArn" |
| 68 | >, |
| 69 | ) { |
| 70 | return yield* operation({ |
| 71 | ...request, |
| 72 | CertificateAuthorityArn: yield* Arn, |
| 73 | } as Req); |
| 74 | }, |
| 75 | ); |
| 76 | }); |
| 77 | }); |