| 1 | import * as ag from "@distilled.cloud/aws/api-gateway"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as Output from "../../Output.ts"; |
| 5 | import { registerApiGatewayBinding } from "./BindingHttp.ts"; |
| 6 | import { |
| 7 | GetUsagePlanKey, |
| 8 | type GetUsagePlanKeyRequest, |
| 9 | } from "./GetUsagePlanKey.ts"; |
| 10 | import type { UsagePlan } from "./UsagePlan.ts"; |
| 11 | |
| 12 | /** |
| 13 | * HTTP implementation of the {@link GetUsagePlanKey} binding. Grants |
| 14 | * `apigateway:GET` on the plan's per-key paths and calls the API with the |
| 15 | * host Function's credentials. |
| 16 | */ |
| 17 | export const GetUsagePlanKeyHttp = Layer.effect( |
| 18 | GetUsagePlanKey, |
| 19 | Effect.gen(function* () { |
| 20 | const getUsagePlanKey = yield* ag.getUsagePlanKey; |
| 21 | return Effect.fn(function* <P extends UsagePlan>(usagePlan: P) { |
| 22 | const UsagePlanId = yield* usagePlan.id; |
| 23 | yield* registerApiGatewayBinding({ |
| 24 | cap: "AWS.ApiGateway.GetUsagePlanKey", |
| 25 | target: usagePlan, |
| 26 | verb: "GET", |
| 27 | paths: (region) => [ |
| 28 | Output.interpolate`arn:aws:apigateway:${region}::/usageplans/${usagePlan.id}/keys/*`, |
| 29 | ], |
| 30 | }); |
| 31 | return Effect.fn( |
| 32 | `AWS.ApiGateway.GetUsagePlanKey(${usagePlan.LogicalId})`, |
| 33 | )(function* (request: GetUsagePlanKeyRequest) { |
| 34 | return yield* getUsagePlanKey({ |
| 35 | ...request, |
| 36 | usagePlanId: yield* UsagePlanId, |
| 37 | }); |
| 38 | }); |
| 39 | }); |
| 40 | }), |
| 41 | ); |