| 1 | import * as privateca from "@distilled.cloud/gcp/privateca_v1"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import type { CaPool } from "./CaPool.ts"; |
| 5 | import { FetchCaCerts, type FetchCaCertsRequest } from "./FetchCaCerts.ts"; |
| 6 | import { bindGcpHost } from "../Host.ts"; |
| 7 | import { grantFor } from "../HttpBinding.ts"; |
| 8 | |
| 9 | /** |
| 10 | * HTTP implementation of {@link FetchCaCerts}. |
| 11 | * |
| 12 | * @layer |
| 13 | * @provides GCP.PrivateCA.FetchCaCerts |
| 14 | */ |
| 15 | export const FetchCaCertsHttp = Layer.effect( |
| 16 | FetchCaCerts, |
| 17 | Effect.gen(function* () { |
| 18 | const fetchCaCertsProjectsLocationsCaPools = |
| 19 | yield* privateca.fetchCaCertsProjectsLocationsCaPools; |
| 20 | return Effect.fn(function* <P extends CaPool>(pool: P) { |
| 21 | yield* bindGcpHost({ |
| 22 | tag: "GCP.PrivateCA.FetchCaCerts", |
| 23 | resource: pool, |
| 24 | iam: [ |
| 25 | grantFor( |
| 26 | { role: "roles/privateca.poolReader", on: "privateca.caPool" }, |
| 27 | pool.name, |
| 28 | ), |
| 29 | ], |
| 30 | }); |
| 31 | const name = yield* pool.name; |
| 32 | return Effect.fn(`GCP.PrivateCA.FetchCaCerts(${pool.LogicalId})`)( |
| 33 | function* (request?: FetchCaCertsRequest) { |
| 34 | return yield* fetchCaCertsProjectsLocationsCaPools({ |
| 35 | caPool: yield* name, |
| 36 | body: |
| 37 | request?.requestId !== undefined |
| 38 | ? { requestId: request.requestId } |
| 39 | : {}, |
| 40 | }); |
| 41 | }, |
| 42 | ); |
| 43 | }); |
| 44 | }), |
| 45 | ); |