| 1 | import * as emrc from "@distilled.cloud/aws/emr-containers"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as Binding from "../../Binding.ts"; |
| 5 | import { toWireSeconds } from "../../Util/Duration.ts"; |
| 6 | import { isBindingHost } from "../Lambda/Function.ts"; |
| 7 | import { virtualClusterPolicyStatement } from "./BindingHttp.ts"; |
| 8 | import { |
| 9 | GetManagedEndpointSessionCredentials, |
| 10 | type GetManagedEndpointSessionCredentialsRequest, |
| 11 | } from "./GetManagedEndpointSessionCredentials.ts"; |
| 12 | import type { VirtualCluster } from "./VirtualCluster.ts"; |
| 13 | |
| 14 | export const GetManagedEndpointSessionCredentialsHttp = Layer.effect( |
| 15 | GetManagedEndpointSessionCredentials, |
| 16 | Effect.gen(function* () { |
| 17 | const op = yield* emrc.getManagedEndpointSessionCredentials; |
| 18 | |
| 19 | // Bespoke (not the shared builder): the request addresses the cluster as |
| 20 | // `virtualClusterIdentifier` (not `virtualClusterId`) and carries a |
| 21 | // `duration` that converts to the wire's `durationInSeconds`. |
| 22 | return Effect.fn(function* (virtualCluster: VirtualCluster) { |
| 23 | const VirtualClusterId = yield* virtualCluster.virtualClusterId; |
| 24 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 25 | const host = yield* Binding.Host; |
| 26 | if (isBindingHost(host)) { |
| 27 | yield* host.bind`Allow(${host}, AWS.EMRContainers.GetManagedEndpointSessionCredentials(${virtualCluster}))`( |
| 28 | { |
| 29 | policyStatements: [ |
| 30 | virtualClusterPolicyStatement(virtualCluster, [ |
| 31 | "emr-containers:GetManagedEndpointSessionCredentials", |
| 32 | "emr-containers:DescribeManagedEndpoint", |
| 33 | ]), |
| 34 | ], |
| 35 | }, |
| 36 | ); |
| 37 | } |
| 38 | } |
| 39 | return Effect.fn( |
| 40 | `AWS.EMRContainers.GetManagedEndpointSessionCredentials(${virtualCluster.LogicalId})`, |
| 41 | )(function* (request: GetManagedEndpointSessionCredentialsRequest) { |
| 42 | const { duration, ...rest } = request; |
| 43 | return yield* op({ |
| 44 | ...rest, |
| 45 | durationInSeconds: toWireSeconds(duration), |
| 46 | virtualClusterIdentifier: yield* VirtualClusterId, |
| 47 | }); |
| 48 | }); |
| 49 | }); |
| 50 | }), |
| 51 | ); |