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 codedeploy from "@distilled.cloud/aws/codedeploy"; |
| 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 { CreateDeployment, type CreateDeploymentRequest } from "./CreateDeployment.ts"; |
| 7 | import type { DeploymentGroup } from "./DeploymentGroup.ts"; |
| 8 | |
| 9 | /** |
| 10 | * Bespoke (multi-statement IAM): besides `codedeploy:CreateDeployment` on |
| 11 | * the group, creating a deployment reads the deployment configuration and |
| 12 | * the application revision on the caller's behalf, so the grant also covers |
| 13 | * `GetDeploymentConfig` on the account's configs and |
| 14 | * `GetApplicationRevision`/`RegisterApplicationRevision` on the group's |
| 15 | * application. |
| 16 | */ |
| 17 | export const CreateDeploymentHttp = Layer.effect( |
| 18 | CreateDeployment, |
| 19 | Effect.gen(function* () { |
| 20 | const bind = yield* AWSBindings.Bind; |
| 21 | const op = yield* AWSBindings.withCredentials(codedeploy.createDeployment); |
| 22 | |
| 23 | return Effect.fn(function* <G extends DeploymentGroup>(group: G) { |
| 24 | // Outputs yield a DEFERRED effect — resolve again per invocation below. |
| 25 | const ApplicationName = yield* group.applicationName; |
| 26 | const DeploymentGroupName = yield* group.deploymentGroupName; |
| 27 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 28 | yield* bind`AWS.CodeDeploy.CreateDeployment(${group})`({ |
| 29 | policyStatements: [ |
| 30 | { |
| 31 | Effect: "Allow", |
| 32 | Action: ["codedeploy:CreateDeployment"], |
| 33 | Resource: [Output.interpolate`${group.deploymentGroupArn}`], |
| 34 | }, |
| 35 | { |
| 36 | Effect: "Allow", |
| 37 | Action: ["codedeploy:GetDeploymentConfig"], |
| 38 | Resource: [ |
| 39 | Output.map(group.deploymentGroupArn, (arn) => |
| 40 | arn.replace(/:deploymentgroup:.*$/, ":deploymentconfig:*"), |
| 41 | ), |
| 42 | ], |
| 43 | }, |
| 44 | { |
| 45 | Effect: "Allow", |
| 46 | Action: [ |
| 47 | "codedeploy:GetApplicationRevision", |
| 48 | "codedeploy:RegisterApplicationRevision", |
| 49 | ], |
| 50 | Resource: [ |
| 51 | Output.map(group.deploymentGroupArn, (arn) => |
| 52 | arn.replace(/:deploymentgroup:([^/]+)\/.*$/, ":application:$1"), |
| 53 | ), |
| 54 | ], |
| 55 | }, |
| 56 | ], |
| 57 | }); |
| 58 | } |
| 59 | return Effect.fn(`AWS.CodeDeploy.CreateDeployment(${group.LogicalId})`)(function* ( |
| 60 | request?: CreateDeploymentRequest, |
| 61 | ) { |
| 62 | return yield* op({ |
| 63 | ...request, |
| 64 | applicationName: yield* ApplicationName, |
| 65 | deploymentGroupName: yield* DeploymentGroupName, |
| 66 | }); |
| 67 | }); |
| 68 | }); |
| 69 | }), |
| 70 | ); |