1import * as Effect from "effect/Effect";
2import type { Cluster } from "./Cluster.ts";
3import { bindGcpHost } from "../Host.ts";
4import { type BindingIam, type GcpHttpOp, grantFor } from "../HttpBinding.ts";
5
6/**
7 * Shared HTTP scaffolding for Dataproc cluster bindings.
8 * NOT exported from index.ts.
9 */
10export const makeDataprocClusterHttpBinding = <
11 I extends { projectId?: string; region?: string; clusterName?: string },
12 A,
13 E,
14>(options: {
15 tag: string;
16 iam: BindingIam;
17 operation: GcpHttpOp<I, A, E>;
18}) =>
19 Effect.gen(function* () {
20 const run = yield* options.operation;
21 return Effect.fn(function* (cluster: Cluster) {
22 yield* bindGcpHost({
23 tag: options.tag,
24 resource: cluster,
25 iam: [grantFor(options.iam, cluster.name)],
26 });
27 const clusterName = yield* cluster.clusterName;
28 const region = yield* cluster.region;
29 const project = yield* cluster.project;
30 return Effect.fn(`${options.tag}(${cluster.LogicalId})`)(function* (
31 request?: Omit<I, "projectId" | "region" | "clusterName">,
32 ) {
33 return yield* run({
34 ...(request as I),
35 clusterName: yield* clusterName,
36 region: yield* region,
37 projectId: yield* project,
38 } as I);
39 });
40 });
41 });