@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 35 lines 1.34 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 { LocationsSecret } from "./LocationsSecret.ts";
5 import type { Secret } from "./Secret.ts";
6
7 export type SecretBindingTarget = Secret | LocationsSecret;
8
9 /**
10 * Shared HTTP scaffolding for Secret Manager bindings.
11 * NOT exported from index.ts.
12 */
13 export const makeSecretHttpBinding = <I, A, E, Req = void>(options: {
14 tag: string;
15 iam: BindingIam;
16 operation: GcpHttpOp<I, A, E>;
17 toInput: (secretName: string, request: Req | undefined) => I;
18 }) =>
19 Effect.gen(function* () {
20 const bind = yield* GCPBindings.Bind;
21 const run = yield* GCPBindings.withCredentials(options.operation);
22 return Effect.fn(function* (secret: SecretBindingTarget) {
23 // `name` is `projects/p/secrets/s` or, for regional secrets,
24 // `projects/p/locations/l/secrets/s`; both are secret IAM targets.
25 if (!globalThis.__ALCHEMY_RUNTIME__) {
26 yield* bind`${options.tag}(${secret})`({
27 iam: [grantFor(options.iam, secret.name)],
28 });
29 }
30 const name = yield* secret.name;
31 return Effect.fn(`${options.tag}(${secret.LogicalId})`)(function* (request?: Req) {
32 return yield* run(options.toInput(yield* name, request));
33 });
34 });
35 });