| 1 | import * as sdb from "@distilled.cloud/aws/simpledb"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as Binding from "../../Binding.ts"; |
| 5 | import { isBindingHost } from "../Lambda/Function.ts"; |
| 6 | import { ListDomains } from "./ListDomains.ts"; |
| 7 | |
| 8 | /** |
| 9 | * Account-level binding — bespoke rather than `makeSimpleDbBinding` because |
| 10 | * `ListDomains` targets no single domain: SimpleDB IAM cannot scope it |
| 11 | * narrower than every domain in the account, so the grant is |
| 12 | * `sdb:ListDomains` on `domain/*` (expressed as `*`). |
| 13 | */ |
| 14 | export const ListDomainsHttp = Layer.effect( |
| 15 | ListDomains, |
| 16 | Effect.gen(function* () { |
| 17 | const listDomains = yield* sdb.listDomains; |
| 18 | |
| 19 | return Effect.fn(function* () { |
| 20 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 21 | const host = yield* Binding.Host; |
| 22 | if (isBindingHost(host)) { |
| 23 | yield* host.bind`Allow(${host}, AWS.SimpleDB.ListDomains())`({ |
| 24 | policyStatements: [ |
| 25 | { |
| 26 | Effect: "Allow", |
| 27 | Action: ["sdb:ListDomains"], |
| 28 | Resource: ["*"], |
| 29 | }, |
| 30 | ], |
| 31 | }); |
| 32 | } |
| 33 | } |
| 34 | return Effect.fn("AWS.SimpleDB.ListDomains")(function* ( |
| 35 | request?: sdb.ListDomainsRequest, |
| 36 | ) { |
| 37 | return yield* listDomains({ ...request }); |
| 38 | }); |
| 39 | }); |
| 40 | }), |
| 41 | ); |