@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, 06:00 UTC

main
ts 66 lines 2.12 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import * as Effect from "effect/Effect";
3 import { serveProbes } from "../../bindingHost.ts";
4
5 /** Object seeded into the source bucket; the transfer copies it. */
6 export const SEED_KEY = "transfer/hello.txt";
7 export const SEED_TEXT = "hello from the transfer source";
8
9 export const Source = Effect.gen(function* () {
10 const source = yield* GCP.Storage.Bucket("Src", {
11 location: "US-CENTRAL1",
12 forceDestroy: true,
13 });
14 yield* GCP.Storage.Object("SrcSeed", {
15 bucketName: source.bucketName,
16 key: SEED_KEY,
17 content: SEED_TEXT,
18 contentType: "text/plain",
19 });
20 return source;
21 });
22
23 export const Sink = GCP.Storage.Bucket("Dst", {
24 location: "US-CENTRAL1",
25 forceDestroy: true,
26 });
27
28 /** A manual (unscheduled) job copying the source bucket into the sink. */
29 export const Copy = Effect.gen(function* () {
30 const source = yield* Source;
31 const sink = yield* Sink;
32 return yield* GCP.StorageTransfer.TransferJob("Copy", {
33 description: "binding probe",
34 status: "ENABLED",
35 transferSpec: {
36 gcsDataSource: { bucketName: source.bucketName },
37 gcsDataSink: { bucketName: sink.bucketName },
38 },
39 });
40 });
41
42 /**
43 * Effect-native Cloud Run service exercising every Storage Transfer
44 * binding as its own runtime service account. Deployed from
45 * {@link ../Bindings.test.ts}.
46 */
47 export default class StorageTransferBindingsHost extends GCP.Function<StorageTransferBindingsHost>()(
48 "StorageTransferBindingsHost",
49 { main: import.meta.url, invokerIamDisabled: true },
50 Effect.gen(function* () {
51 const getAccount = yield* GCP.StorageTransfer.GetGoogleServiceAccount(Copy);
52 const runJob = yield* GCP.StorageTransfer.RunTransferJob(Copy);
53
54 return {
55 fetch: serveProbes({
56 getGoogleServiceAccount: getAccount().pipe(
57 Effect.map((account) => ({ accountEmail: account.accountEmail })),
58 ),
59 runTransferJob: runJob().pipe(Effect.map((operation) => ({ name: operation.name }))),
60 }),
61 };
62 }).pipe(
63 Effect.provide(GCP.StorageTransfer.GetGoogleServiceAccountHttp),
64 Effect.provide(GCP.StorageTransfer.RunTransferJobHttp),
65 ),
66 ) {}