| 1 | import * as GCP from "@/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( |
| 60 | Effect.map((operation) => ({ name: operation.name })), |
| 61 | ), |
| 62 | }), |
| 63 | }; |
| 64 | }).pipe( |
| 65 | Effect.provide(GCP.StorageTransfer.GetGoogleServiceAccountHttp), |
| 66 | Effect.provide(GCP.StorageTransfer.RunTransferJobHttp), |
| 67 | ), |
| 68 | ) {} |