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
| 1 | import * as SSM from "@distilled.cloud/aws/ssm"; |
| 2 | import * as Output 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 { |
| 7 | GetParameters, |
| 8 | type GetParametersParameters, |
| 9 | type GetParametersRequest, |
| 10 | } from "./GetParameters.ts"; |
| 11 | |
| 12 | export const GetParametersHttp = Layer.effect( |
| 13 | GetParameters, |
| 14 | Effect.gen(function* () { |
| 15 | const bind = yield* AWSBindings.Bind; |
| 16 | const getParameters = yield* AWSBindings.withCredentials(SSM.getParameters); |
| 17 | |
| 18 | return Effect.fn(function* (...parameters: GetParametersParameters) { |
| 19 | // Resolve name accessors in caller order so the runtime request |
| 20 | // preserves the order the user bound the parameters in. |
| 21 | const NameAccessors: Effect.Effect<string>[] = []; |
| 22 | for (const parameter of parameters) { |
| 23 | NameAccessors.push(yield* parameter.parameterName); |
| 24 | } |
| 25 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 26 | // Sort by LogicalId so the binding identity (SID + ARN list) is |
| 27 | // deterministic regardless of argument order. |
| 28 | const sorted = [...parameters].sort((a, b) => a.LogicalId.localeCompare(b.LogicalId)); |
| 29 | yield* bind`AWS.SSM.GetParameters(${sorted})`({ |
| 30 | policyStatements: [ |
| 31 | { |
| 32 | Effect: "Allow", |
| 33 | Action: ["ssm:GetParameters"], |
| 34 | Resource: sorted.map((parameter) => parameter.parameterArn), |
| 35 | }, |
| 36 | { |
| 37 | // kms:Decrypt so `WithDecryption: true` works on SecureString |
| 38 | // parameters. Parameters without a key (String/StringList) |
| 39 | // fall back to their own ARN, which matches no KMS key. |
| 40 | Effect: "Allow", |
| 41 | Action: ["kms:Decrypt"], |
| 42 | Resource: sorted.map((parameter) => |
| 43 | Output.all(parameter.parameterArn, parameter.keyArn).pipe( |
| 44 | Output.map(([parameterArn, keyArn]) => keyArn ?? parameterArn), |
| 45 | ), |
| 46 | ), |
| 47 | }, |
| 48 | ], |
| 49 | }); |
| 50 | } |
| 51 | return Effect.fn( |
| 52 | `AWS.SSM.GetParameters(${parameters.map((parameter) => parameter.LogicalId).join(", ")})`, |
| 53 | )(function* (request: GetParametersRequest = {}) { |
| 54 | const names = yield* Effect.forEach(NameAccessors, (accessor) => accessor); |
| 55 | return yield* getParameters({ |
| 56 | ...request, |
| 57 | Names: names, |
| 58 | }); |
| 59 | }); |
| 60 | }); |
| 61 | }), |
| 62 | ); |