The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as GCPBindings from "../GCPBindings.ts"; |
| 3 | import { grantFor, type BindingIam, type GcpHttpOp } from "../HttpBinding.ts"; |
| 4 | import type { CryptoKey } from "./CryptoKey.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Shared HTTP scaffolding for Cloud KMS CryptoKey bindings. |
| 8 | * NOT exported from index.ts. |
| 9 | */ |
| 10 | export const makeCryptoKeyHttpBinding = <I extends { name?: string }, A, E>(options: { |
| 11 | tag: string; |
| 12 | iam: BindingIam; |
| 13 | operation: GcpHttpOp<I, A, E>; |
| 14 | }) => |
| 15 | Effect.gen(function* () { |
| 16 | const bind = yield* GCPBindings.Bind; |
| 17 | const run = yield* GCPBindings.withCredentials(options.operation); |
| 18 | return Effect.fn(function* (key: CryptoKey) { |
| 19 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 20 | yield* bind`${options.tag}(${key})`({ iam: [grantFor(options.iam, key.name)] }); |
| 21 | } |
| 22 | const name = yield* key.name; |
| 23 | return Effect.fn(`${options.tag}(${key.LogicalId})`)(function* (request?: Omit<I, "name">) { |
| 24 | return yield* run({ |
| 25 | ...(request as I), |
| 26 | name: yield* name, |
| 27 | } as I); |
| 28 | }); |
| 29 | }); |
| 30 | }); |