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 { type BindingIam, type GcpHttpOp, grantFor } from "../HttpBinding.ts"; |
| 4 | import type { Cluster } from "./Cluster.ts"; |
| 5 | import type { ClustersNodePool } from "./ClustersNodePool.ts"; |
| 6 | import type { NodePool } from "./NodePool.ts"; |
| 7 | |
| 8 | /** |
| 9 | * Shared HTTP scaffolding for GKE cluster and node pool bindings. |
| 10 | * NOT exported from index.ts. |
| 11 | */ |
| 12 | export const makeContainerClusterHttpBinding = <I extends { name?: string }, A, E>(options: { |
| 13 | tag: string; |
| 14 | iam: BindingIam; |
| 15 | operation: GcpHttpOp<I, A, E>; |
| 16 | }) => |
| 17 | Effect.gen(function* () { |
| 18 | const bind = yield* GCPBindings.Bind; |
| 19 | const run = yield* GCPBindings.withCredentials(options.operation); |
| 20 | return Effect.fn(function* (cluster: Cluster) { |
| 21 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 22 | yield* bind`${options.tag}(${cluster})`({ |
| 23 | iam: [grantFor(options.iam, cluster.name)], |
| 24 | }); |
| 25 | } |
| 26 | const name = yield* cluster.name; |
| 27 | return Effect.fn(`${options.tag}(${cluster.LogicalId})`)(function* ( |
| 28 | request?: Omit<I, "name">, |
| 29 | ) { |
| 30 | return yield* run({ |
| 31 | ...(request as I), |
| 32 | name: yield* name, |
| 33 | } as I); |
| 34 | }); |
| 35 | }); |
| 36 | }); |
| 37 | |
| 38 | export const makeContainerNodePoolHttpBinding = <I extends { name?: string }, A, E>(options: { |
| 39 | tag: string; |
| 40 | iam: BindingIam; |
| 41 | operation: GcpHttpOp<I, A, E>; |
| 42 | }) => |
| 43 | Effect.gen(function* () { |
| 44 | const bind = yield* GCPBindings.Bind; |
| 45 | const run = yield* GCPBindings.withCredentials(options.operation); |
| 46 | return Effect.fn(function* (nodePool: NodePool) { |
| 47 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 48 | yield* bind`${options.tag}(${nodePool})`({ |
| 49 | iam: [grantFor(options.iam, nodePool.name)], |
| 50 | }); |
| 51 | } |
| 52 | const name = yield* nodePool.name; |
| 53 | return Effect.fn(`${options.tag}(${nodePool.LogicalId})`)(function* ( |
| 54 | request?: Omit<I, "name">, |
| 55 | ) { |
| 56 | return yield* run({ |
| 57 | ...(request as I), |
| 58 | name: yield* name, |
| 59 | } as I); |
| 60 | }); |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | export const makeContainerClustersNodePoolHttpBinding = < |
| 65 | I extends { |
| 66 | projectId: string; |
| 67 | zone: string; |
| 68 | clusterId: string; |
| 69 | nodePoolId: string; |
| 70 | name?: string; |
| 71 | }, |
| 72 | A, |
| 73 | E, |
| 74 | >(options: { |
| 75 | tag: string; |
| 76 | iam: BindingIam; |
| 77 | operation: GcpHttpOp<I, A, E>; |
| 78 | }) => |
| 79 | Effect.gen(function* () { |
| 80 | const bind = yield* GCPBindings.Bind; |
| 81 | const run = yield* GCPBindings.withCredentials(options.operation); |
| 82 | return Effect.fn(function* (nodePool: ClustersNodePool) { |
| 83 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 84 | yield* bind`${options.tag}(${nodePool})`({ |
| 85 | iam: [grantFor(options.iam, nodePool.name)], |
| 86 | }); |
| 87 | } |
| 88 | const name = yield* nodePool.name; |
| 89 | const project = yield* nodePool.project; |
| 90 | const zone = yield* nodePool.zone; |
| 91 | const clusterId = yield* nodePool.clusterId; |
| 92 | const nodePoolId = yield* nodePool.nodePoolId; |
| 93 | return Effect.fn(`${options.tag}(${nodePool.LogicalId})`)(function* ( |
| 94 | request?: Omit<I, "projectId" | "zone" | "clusterId" | "nodePoolId" | "name">, |
| 95 | ) { |
| 96 | return yield* run({ |
| 97 | ...(request as I), |
| 98 | projectId: yield* project, |
| 99 | zone: yield* zone, |
| 100 | clusterId: yield* clusterId, |
| 101 | nodePoolId: yield* nodePoolId, |
| 102 | name: yield* name, |
| 103 | } as I); |
| 104 | }); |
| 105 | }); |
| 106 | }); |