1import * as ag from "@distilled.cloud/aws/api-gateway";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import { registerApiGatewayBinding } from "./BindingHttp.ts";
5import { GetApiKey, type GetApiKeyRequest } from "./GetApiKey.ts";
6
7/**
8 * HTTP implementation of the {@link GetApiKey} binding. Grants
9 * `apigateway:GET` on `/apikeys/*` and calls the API with the host
10 * Function's credentials.
11 */
12export const GetApiKeyHttp = Layer.effect(
13 GetApiKey,
14 Effect.gen(function* () {
15 const getApiKey = yield* ag.getApiKey;
16 return Effect.fn(function* () {
17 yield* registerApiGatewayBinding({
18 cap: "AWS.ApiGateway.GetApiKey",
19 target: "",
20 verb: "GET",
21 paths: (region) => [`arn:aws:apigateway:${region}::/apikeys/*`],
22 });
23 return Effect.fn("AWS.ApiGateway.GetApiKey")(function* (
24 request: GetApiKeyRequest,
25 ) {
26 return yield* getApiKey(request);
27 });
28 });
29 }),
30);