| 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 | GetUsagePlanKeys, |
| 8 | type GetUsagePlanKeysRequest, |
| 9 | } from "./GetUsagePlanKeys.ts"; |
| 10 | import type { UsagePlan } from "./UsagePlan.ts"; |
| 11 | |
| 12 | /** |
| 13 | * HTTP implementation of the {@link GetUsagePlanKeys} binding. Grants |
| 14 | * `apigateway:GET` on the plan's `/keys` path and calls the API with the |
| 15 | * host Function's credentials. |
| 16 | */ |
| 17 | export const GetUsagePlanKeysHttp = Layer.effect( |
| 18 | GetUsagePlanKeys, |
| 19 | Effect.gen(function* () { |
| 20 | const getUsagePlanKeys = yield* ag.getUsagePlanKeys; |
| 21 | return Effect.fn(function* <P extends UsagePlan>(usagePlan: P) { |
| 22 | const UsagePlanId = yield* usagePlan.id; |
| 23 | yield* registerApiGatewayBinding({ |
| 24 | cap: "AWS.ApiGateway.GetUsagePlanKeys", |
| 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.GetUsagePlanKeys(${usagePlan.LogicalId})`, |
| 33 | )(function* (request?: GetUsagePlanKeysRequest) { |
| 34 | return yield* getUsagePlanKeys({ |
| 35 | ...request, |
| 36 | usagePlanId: yield* UsagePlanId, |
| 37 | }); |
| 38 | }); |
| 39 | }); |
| 40 | }), |
| 41 | ); |