| 1 | import * as ECS from "@distilled.cloud/aws/ecs"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import { toWireMinutes } from "../../Util/Duration.ts"; |
| 5 | import { makeEcsClusterHttpBinding } from "./BindingHttp.ts"; |
| 6 | import { |
| 7 | UpdateTaskProtection, |
| 8 | type UpdateTaskProtectionRequest, |
| 9 | } from "./UpdateTaskProtection.ts"; |
| 10 | |
| 11 | export const UpdateTaskProtectionHttp = Layer.effect( |
| 12 | UpdateTaskProtection, |
| 13 | makeEcsClusterHttpBinding({ |
| 14 | tag: "AWS.ECS.UpdateTaskProtection", |
| 15 | // Wrap the distilled operation so the binding accepts a Duration.Input |
| 16 | // `expiresIn` and converts it to the wire's whole minutes. |
| 17 | // |
| 18 | // The operation must be *yielded* (its `Symbol.iterator`/`asEffect` |
| 19 | // protocol), never passed to `Effect.map`: an `API.OperationMethod` is a |
| 20 | // plain callable that is not `Effect.isEffect`, so `Effect.map` wraps it |
| 21 | // into an invalid effect that crashes the fiber at run time with |
| 22 | // "Not a valid effect: function ...". |
| 23 | operation: Effect.gen(function* () { |
| 24 | const op = yield* ECS.updateTaskProtection; |
| 25 | return ({ |
| 26 | expiresIn, |
| 27 | ...request |
| 28 | }: UpdateTaskProtectionRequest & { cluster: string }) => |
| 29 | op({ ...request, expiresInMinutes: toWireMinutes(expiresIn) }); |
| 30 | }), |
| 31 | actions: ["ecs:UpdateTaskProtection"], |
| 32 | // Authorizes against the task resource: |
| 33 | // arn:aws:ecs:{region}:{account}:task/{clusterName}/* |
| 34 | resources: ["task"], |
| 35 | }), |
| 36 | ); |