@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 46 lines 1.96 KB
Raw
1 import * as emrc from "@distilled.cloud/aws/emr-containers";
2 import { toWireSeconds } from "alchemy/Util/Duration";
3 import * as Effect from "effect/Effect";
4 import * as Layer from "effect/Layer";
5 import * as AWSBindings from "../AWSBindings.ts";
6 import { virtualClusterPolicyStatement } from "./BindingHttp.ts";
7 import {
8 GetManagedEndpointSessionCredentials,
9 type GetManagedEndpointSessionCredentialsRequest,
10 } from "./GetManagedEndpointSessionCredentials.ts";
11 import type { VirtualCluster } from "./VirtualCluster.ts";
12
13 export const GetManagedEndpointSessionCredentialsHttp = Layer.effect(
14 GetManagedEndpointSessionCredentials,
15 Effect.gen(function* () {
16 const bind = yield* AWSBindings.Bind;
17 const op = yield* AWSBindings.withCredentials(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 yield* bind`AWS.EMRContainers.GetManagedEndpointSessionCredentials(${virtualCluster})`({
26 policyStatements: [
27 virtualClusterPolicyStatement(virtualCluster, [
28 "emr-containers:GetManagedEndpointSessionCredentials",
29 "emr-containers:DescribeManagedEndpoint",
30 ]),
31 ],
32 });
33 }
34 return Effect.fn(
35 `AWS.EMRContainers.GetManagedEndpointSessionCredentials(${virtualCluster.LogicalId})`,
36 )(function* (request: GetManagedEndpointSessionCredentialsRequest) {
37 const { duration, ...rest } = request;
38 return yield* op({
39 ...rest,
40 durationInSeconds: toWireSeconds(duration),
41 virtualClusterIdentifier: yield* VirtualClusterId,
42 });
43 });
44 });
45 }),
46 );