The best way to control Claude Code, Codex and more from any computer or phone

main
ts 31 lines 1.18 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as GCPBindings from "../GCPBindings.ts";
3 import { grantFor, type BindingIam, type GcpHttpOp } from "../HttpBinding.ts";
4 import type { CertificateAuthority } from "./CertificateAuthority.ts";
5
6 /**
7 * Shared HTTP scaffolding for Certificate Authority Service bindings.
8 * NOT exported from index.ts.
9 */
10 export const makeCertificateAuthorityHttpBinding = <I extends { name?: string }, A, E>(options: {
11 tag: string;
12 iam: BindingIam;
13 operation: GcpHttpOp<I, A, E>;
14 }) =>
15 Effect.gen(function* () {
16 const bind = yield* GCPBindings.Bind;
17 const run = yield* GCPBindings.withCredentials(options.operation);
18 return Effect.fn(function* (ca: CertificateAuthority) {
19 // CAs have no IAM policy of their own; access is granted on the parent pool.
20 if (!globalThis.__ALCHEMY_RUNTIME__) {
21 yield* bind`${options.tag}(${ca})`({ iam: [grantFor(options.iam, ca.caPool)] });
22 }
23 const name = yield* ca.name;
24 return Effect.fn(`${options.tag}(${ca.LogicalId})`)(function* (request?: Omit<I, "name">) {
25 return yield* run({
26 ...(request as I),
27 name: yield* name,
28 } as I);
29 });
30 });
31 });