@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 82 lines 3.09 KB
Raw
1 import * as autoscaling from "@distilled.cloud/aws/auto-scaling";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import type { AutoScalingGroup } from "./AutoScalingGroup.ts";
6 import {
7 InstanceRefresh,
8 type CancelInstanceRefreshRequest,
9 type DescribeInstanceRefreshesRequest,
10 type StartInstanceRefreshRequest,
11 } from "./InstanceRefresh.ts";
12
13 // Bespoke (not the shared scaffold): a multi-operation client over the four
14 // instance refresh operations behind one two-statement IAM grant (the write
15 // actions are group-scoped, Describe* only supports `*`).
16 export const InstanceRefreshHttp = Layer.effect(
17 InstanceRefresh,
18 Effect.gen(function* () {
19 const bind = yield* AWSBindings.Bind;
20 const start = yield* AWSBindings.withCredentials(autoscaling.startInstanceRefresh);
21 const cancel = yield* AWSBindings.withCredentials(autoscaling.cancelInstanceRefresh);
22 const rollback = yield* AWSBindings.withCredentials(autoscaling.rollbackInstanceRefresh);
23 const describe = yield* AWSBindings.withCredentials(autoscaling.describeInstanceRefreshes);
24
25 return Effect.fn(function* (group: AutoScalingGroup) {
26 const AutoScalingGroupName = yield* group.autoScalingGroupName;
27 if (!globalThis.__ALCHEMY_RUNTIME__) {
28 yield* bind`AWS.AutoScaling.InstanceRefresh(${group})`({
29 policyStatements: [
30 {
31 Effect: "Allow",
32 Action: [
33 "autoscaling:StartInstanceRefresh",
34 "autoscaling:CancelInstanceRefresh",
35 "autoscaling:RollbackInstanceRefresh",
36 ],
37 Resource: [group.autoScalingGroupArn],
38 },
39 {
40 Effect: "Allow",
41 Action: ["autoscaling:DescribeInstanceRefreshes"],
42 Resource: ["*"],
43 },
44 ],
45 });
46 }
47 return {
48 start: Effect.fn(`AWS.AutoScaling.StartInstanceRefresh(${group.LogicalId})`)(function* (
49 request?: StartInstanceRefreshRequest,
50 ) {
51 return yield* start({
52 ...request,
53 AutoScalingGroupName: yield* AutoScalingGroupName,
54 });
55 }),
56 cancel: Effect.fn(`AWS.AutoScaling.CancelInstanceRefresh(${group.LogicalId})`)(function* (
57 request?: CancelInstanceRefreshRequest,
58 ) {
59 return yield* cancel({
60 ...request,
61 AutoScalingGroupName: yield* AutoScalingGroupName,
62 });
63 }),
64 rollback: Effect.fn(`AWS.AutoScaling.RollbackInstanceRefresh(${group.LogicalId})`)(
65 function* () {
66 return yield* rollback({
67 AutoScalingGroupName: yield* AutoScalingGroupName,
68 });
69 },
70 ),
71 describe: Effect.fn(`AWS.AutoScaling.DescribeInstanceRefreshes(${group.LogicalId})`)(
72 function* (request?: DescribeInstanceRefreshesRequest) {
73 return yield* describe({
74 ...request,
75 AutoScalingGroupName: yield* AutoScalingGroupName,
76 });
77 },
78 ),
79 };
80 });
81 }),
82 );