1import * as codedeploy from "@distilled.cloud/aws/codedeploy";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Binding from "../../Binding.ts";
5import { BatchGetDeployments } from "./BatchGetDeployments.ts";
6import type { DeploymentGroup } from "./DeploymentGroup.ts";
7import { isBindingHost } from "../Lambda/Function.ts";
8
9/**
10 * Bespoke IAM: `codedeploy:BatchGetDeployments` does not support
11 * resource-level permissions (a batch of deployment ids cannot be mapped to
12 * a deployment-group resource before authorization), so the grant must be
13 * on `*` — a group-scoped grant is denied with AccessDeniedException.
14 */
15export const BatchGetDeploymentsHttp = Layer.effect(
16 BatchGetDeployments,
17 Effect.gen(function* () {
18 const op = yield* codedeploy.batchGetDeployments;
19
20 return Effect.fn(function* <G extends DeploymentGroup>(group: G) {
21 if (!globalThis.__ALCHEMY_RUNTIME__) {
22 const host = yield* Binding.Host;
23 if (isBindingHost(host)) {
24 yield* host.bind`Allow(${host}, AWS.CodeDeploy.BatchGetDeployments(${group}))`(
25 {
26 policyStatements: [
27 {
28 Effect: "Allow",
29 Action: ["codedeploy:BatchGetDeployments"],
30 Resource: ["*"],
31 },
32 ],
33 },
34 );
35 }
36 }
37 return Effect.fn(
38 `AWS.CodeDeploy.BatchGetDeployments(${group.LogicalId})`,
39 )(function* (request: codedeploy.BatchGetDeploymentsInput) {
40 return yield* op(request);
41 });
42 });
43 }),
44);