1import * as Effect from "effect/Effect";
2import type { CertificateAuthority } from "./CertificateAuthority.ts";
3import { bindGcpHost } from "../Host.ts";
4import { grantFor, type BindingIam, type GcpHttpOp } from "../HttpBinding.ts";
5
6/**
7 * Shared HTTP scaffolding for Certificate Authority Service bindings.
8 * NOT exported from index.ts.
9 */
10export const makeCertificateAuthorityHttpBinding = <
11 I extends { name?: 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* (ca: CertificateAuthority) {
22 // CAs have no IAM policy of their own; access is granted on the parent pool.
23 yield* bindGcpHost({
24 tag: options.tag,
25 resource: ca,
26 iam: [grantFor(options.iam, ca.caPool)],
27 });
28 const name = yield* ca.name;
29 return Effect.fn(`${options.tag}(${ca.LogicalId})`)(function* (
30 request?: Omit<I, "name">,
31 ) {
32 return yield* run({
33 ...(request as I),
34 name: yield* name,
35 } as I);
36 });
37 });
38 });