| 1 | import * as storagetransfer from "@distilled.cloud/gcp/storagetransfer_v1"; |
| 2 | import { Credentials } from "@distilled.cloud/gcp/Credentials"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as HttpClient from "effect/http/HttpClient"; |
| 6 | import { GetGoogleServiceAccount } from "./GetGoogleServiceAccount.ts"; |
| 7 | import type { TransferJob } from "./TransferJob.ts"; |
| 8 | import { bindGcpHost } from "../Host.ts"; |
| 9 | |
| 10 | /** |
| 11 | * HTTP implementation of {@link GetGoogleServiceAccount}. |
| 12 | * |
| 13 | * @layer |
| 14 | * @provides GCP.StorageTransfer.GetGoogleServiceAccount |
| 15 | */ |
| 16 | export const GetGoogleServiceAccountHttp: Layer.Layer< |
| 17 | GetGoogleServiceAccount, |
| 18 | never, |
| 19 | Credentials | HttpClient.HttpClient |
| 20 | > = Layer.effect( |
| 21 | GetGoogleServiceAccount, |
| 22 | Effect.gen(function* () { |
| 23 | const run = yield* storagetransfer.getGoogleServiceAccounts; |
| 24 | return Effect.fn(function* (job: TransferJob) { |
| 25 | yield* bindGcpHost({ |
| 26 | tag: "GCP.StorageTransfer.GetGoogleServiceAccount", |
| 27 | resource: job, |
| 28 | iam: [{ role: "roles/storagetransfer.viewer" }], |
| 29 | }); |
| 30 | const project = yield* job.project; |
| 31 | return Effect.fn( |
| 32 | `GCP.StorageTransfer.GetGoogleServiceAccount(${job.LogicalId})`, |
| 33 | )(function* () { |
| 34 | return yield* run({ projectId: yield* project }); |
| 35 | }); |
| 36 | }); |
| 37 | }), |
| 38 | ); |