@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 66 lines 2.32 KB
Raw
1 import * as secretsmanager from "@distilled.cloud/aws/secrets-manager";
2 import type { Accessor } from "alchemy/Output";
3 import * as Effect from "effect/Effect";
4 import * as Layer from "effect/Layer";
5 import * as AWSBindings from "../AWSBindings.ts";
6 import { BatchGetSecretValue, type BatchGetSecretValueRequest } from "./BatchGetSecretValue.ts";
7 import type { Secret } from "./Secret.ts";
8
9 /**
10 * Bespoke (multi-secret) HTTP binding: `BatchGetSecretValue` targets a list
11 * of secrets, so it can't reuse the single-secret scaffolding — the account
12 * -level `secretsmanager:BatchGetSecretValue` action is granted on `*` and
13 * per-secret `GetSecretValue`/`DescribeSecret` on each bound secret's ARN.
14 */
15 export const BatchGetSecretValueHttp = Layer.effect(
16 BatchGetSecretValue,
17 Effect.gen(function* () {
18 const bind = yield* AWSBindings.Bind;
19 const batchGetSecretValue = yield* AWSBindings.withCredentials(
20 secretsmanager.batchGetSecretValue,
21 );
22
23 return Effect.fn(function* (secrets: readonly Secret[]) {
24 const SecretIds: Accessor<string>[] = [];
25 for (const secret of secrets) {
26 SecretIds.push(yield* secret.secretArn);
27 }
28 if (!globalThis.__ALCHEMY_RUNTIME__) {
29 yield* bind`AWS.SecretsManager.BatchGetSecretValue()`({
30 policyStatements: [
31 {
32 Effect: "Allow",
33 Action: ["secretsmanager:BatchGetSecretValue"],
34 Resource: ["*"],
35 },
36 ],
37 });
38 for (const secret of secrets) {
39 yield* bind`AWS.SecretsManager.BatchGetSecretValue(${secret})`({
40 policyStatements: [
41 {
42 Effect: "Allow",
43 Action: ["secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret"],
44 Resource: [secret.secretArn],
45 },
46 ],
47 });
48 }
49 }
50 return Effect.fn(
51 `AWS.SecretsManager.BatchGetSecretValue(${secrets
52 .map((secret) => secret.LogicalId)
53 .join(",")})`,
54 )(function* (request?: BatchGetSecretValueRequest) {
55 const secretIdList = [];
56 for (const secretId of SecretIds) {
57 secretIdList.push(yield* secretId);
58 }
59 return yield* batchGetSecretValue({
60 ...request,
61 SecretIdList: secretIdList,
62 });
63 });
64 });
65 }),
66 );