| 1 | import * as cloudrun from "@distilled.cloud/gcp/run_v2"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import { GetWorkerPool, type GetWorkerPoolRequest } from "./GetWorkerPool.ts"; |
| 5 | import type { WorkerPool } from "./WorkerPool.ts"; |
| 6 | import { bindGcpHost } from "../Host.ts"; |
| 7 | import { grantFor } from "../HttpBinding.ts"; |
| 8 | |
| 9 | /** |
| 10 | * HTTP implementation of {@link GetWorkerPool}. |
| 11 | * |
| 12 | * @layer |
| 13 | * @provides GCP.Run.GetWorkerPool |
| 14 | */ |
| 15 | export const GetWorkerPoolHttp = Layer.effect( |
| 16 | GetWorkerPool, |
| 17 | Effect.gen(function* () { |
| 18 | const getProjectsLocationsWorkerPools = |
| 19 | yield* cloudrun.getProjectsLocationsWorkerPools; |
| 20 | return Effect.fn(function* <T extends WorkerPool>(pool: T) { |
| 21 | yield* bindGcpHost({ |
| 22 | tag: "GCP.Run.GetWorkerPool", |
| 23 | resource: pool, |
| 24 | iam: [ |
| 25 | grantFor( |
| 26 | { role: "roles/run.viewer", on: "run.workerPool" }, |
| 27 | pool.name, |
| 28 | ), |
| 29 | ], |
| 30 | }); |
| 31 | const name = yield* pool.name; |
| 32 | return Effect.fn(`GCP.Run.GetWorkerPool(${pool.LogicalId})`)(function* ( |
| 33 | request?: GetWorkerPoolRequest, |
| 34 | ) { |
| 35 | return yield* getProjectsLocationsWorkerPools({ |
| 36 | ...request, |
| 37 | name: yield* name, |
| 38 | }); |
| 39 | }); |
| 40 | }); |
| 41 | }), |
| 42 | ); |