@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 46 lines 1.59 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as GCPBindings from "../GCPBindings.ts";
3 import { grantFor, type GcpHttpOp } from "../HttpBinding.ts";
4 import type { Bucket } from "./Bucket.ts";
5
6 /**
7 * Grant `role` on the bound bucket's own IAM policy (not the project), the
8 * way AWS S3 bindings scope statements to the bucket ARN.
9 */
10 export const GrantOnBucket = Effect.gen(function* () {
11 const bind = yield* GCPBindings.Bind;
12 return Effect.fn(function* (tag: string, bucket: Bucket, role: string) {
13 if (globalThis.__ALCHEMY_RUNTIME__) return;
14 yield* bind`${tag}(${bucket})`({
15 iam: [grantFor({ role, on: "storage.bucket" }, bucket.bucketName)],
16 });
17 });
18 });
19
20 /**
21 * Shared HTTP scaffolding for Cloud Storage object metadata bindings
22 * (`DeleteObject`): yields the distilled operation once at Layer
23 * construction and injects the bound bucket's name.
24 * NOT exported from index.ts.
25 */
26 export const makeObjectHttpBinding = <I extends { bucket?: string }, A, E>(options: {
27 tag: string;
28 role: string;
29 operation: GcpHttpOp<I, A, E>;
30 }) =>
31 Effect.gen(function* () {
32 const grantOnBucket = yield* GrantOnBucket;
33 const run = yield* GCPBindings.withCredentials(options.operation);
34 return Effect.fn(function* (bucket: Bucket) {
35 yield* grantOnBucket(options.tag, bucket, options.role);
36 const bucketName = yield* bucket.bucketName;
37 return Effect.fn(`${options.tag}(${bucket.LogicalId})`)(function* (
38 request: Omit<I, "bucket">,
39 ) {
40 return yield* run({
41 ...request,
42 bucket: yield* bucketName,
43 } as I);
44 });
45 });
46 });