@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 165 lines 5.79 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { Firewall } from "./Firewall.ts";
4 import type { FirewallPolicy } from "./FirewallPolicy.ts";
5 import type { RuleGroup } from "./RuleGroup.ts";
6
7 /**
8 * Shared scaffolding for AWS Network Firewall HTTP bindings.
9 *
10 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
11 * thin `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the three
12 * builders below. Everything except the operation and the IAM action is
13 * boilerplate:
14 *
15 * - {@link makeNetworkFirewallFirewallHttpBinding} — operations scoped to one
16 * bound {@link Firewall} (`DescribeFirewall`, the flow-operation interface,
17 * the analysis-report interface). The runtime callable injects the
18 * firewall's ARN as the request's `FirewallArn`; the deploy-time half
19 * grants `actions` on the firewall ARN.
20 * - {@link makeNetworkFirewallFirewallPolicyHttpBinding} — operations scoped
21 * to one bound {@link FirewallPolicy}; injects `FirewallPolicyArn`.
22 * - {@link makeNetworkFirewallRuleGroupHttpBinding} — operations scoped to
23 * one bound {@link RuleGroup}; injects `RuleGroupArn`.
24 */
25
26 /**
27 * Build the impl Effect for an operation scoped to a single bound
28 * {@link Firewall}. The runtime callable injects the firewall's ARN as the
29 * request's `FirewallArn`; the deploy-time half grants `actions` on the
30 * firewall ARN.
31 */
32 export const makeNetworkFirewallFirewallHttpBinding = <
33 I extends { FirewallArn?: string },
34 A,
35 E,
36 R,
37 >(options: {
38 /** Fully-qualified binding tag, e.g. `AWS.NetworkFirewall.StartFlowCapture`. */
39 tag: string;
40 /** The distilled operation; `FirewallArn` is injected from the resource. */
41 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
42 /** IAM actions granted on the firewall ARN. */
43 actions: readonly string[];
44 }) =>
45 Effect.gen(function* () {
46 const bind = yield* AWSBindings.Bind;
47 const op = yield* AWSBindings.withCredentials(options.operation);
48
49 return Effect.fn(function* (firewall: Firewall) {
50 const FirewallArn = yield* firewall.firewallArn;
51 if (!globalThis.__ALCHEMY_RUNTIME__) {
52 yield* bind`${options.tag}(${firewall})`({
53 policyStatements: [
54 {
55 Effect: "Allow",
56 Action: [...options.actions],
57 Resource: [firewall.firewallArn],
58 },
59 ],
60 });
61 }
62 return Effect.fn(`${options.tag}(${firewall.LogicalId})`)(function* (
63 request?: Omit<I, "FirewallArn" | "FirewallName">,
64 ) {
65 return yield* op({
66 ...request,
67 FirewallArn: yield* FirewallArn,
68 } as I);
69 });
70 });
71 });
72
73 /**
74 * Build the impl Effect for an operation scoped to a single bound
75 * {@link FirewallPolicy}. The runtime callable injects the policy's ARN as
76 * the request's `FirewallPolicyArn`; the deploy-time half grants `actions`
77 * on the policy ARN.
78 */
79 export const makeNetworkFirewallFirewallPolicyHttpBinding = <
80 I extends { FirewallPolicyArn?: string },
81 A,
82 E,
83 R,
84 >(options: {
85 /** Fully-qualified binding tag, e.g. `AWS.NetworkFirewall.DescribeFirewallPolicy`. */
86 tag: string;
87 /** The distilled operation; `FirewallPolicyArn` is injected from the resource. */
88 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
89 /** IAM actions granted on the firewall policy ARN. */
90 actions: readonly string[];
91 }) =>
92 Effect.gen(function* () {
93 const bind = yield* AWSBindings.Bind;
94 const op = yield* AWSBindings.withCredentials(options.operation);
95
96 return Effect.fn(function* (policy: FirewallPolicy) {
97 const FirewallPolicyArn = yield* policy.firewallPolicyArn;
98 if (!globalThis.__ALCHEMY_RUNTIME__) {
99 yield* bind`${options.tag}(${policy})`({
100 policyStatements: [
101 {
102 Effect: "Allow",
103 Action: [...options.actions],
104 Resource: [policy.firewallPolicyArn],
105 },
106 ],
107 });
108 }
109 return Effect.fn(`${options.tag}(${policy.LogicalId})`)(function* (
110 request?: Omit<I, "FirewallPolicyArn" | "FirewallPolicyName">,
111 ) {
112 return yield* op({
113 ...request,
114 FirewallPolicyArn: yield* FirewallPolicyArn,
115 } as I);
116 });
117 });
118 });
119
120 /**
121 * Build the impl Effect for an operation scoped to a single bound
122 * {@link RuleGroup}. The runtime callable injects the rule group's ARN as
123 * the request's `RuleGroupArn`; the deploy-time half grants `actions` on the
124 * rule group ARN.
125 */
126 export const makeNetworkFirewallRuleGroupHttpBinding = <
127 I extends { RuleGroupArn?: string },
128 A,
129 E,
130 R,
131 >(options: {
132 /** Fully-qualified binding tag, e.g. `AWS.NetworkFirewall.DescribeRuleGroup`. */
133 tag: string;
134 /** The distilled operation; `RuleGroupArn` is injected from the resource. */
135 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
136 /** IAM actions granted on the rule group ARN. */
137 actions: readonly string[];
138 }) =>
139 Effect.gen(function* () {
140 const bind = yield* AWSBindings.Bind;
141 const op = yield* AWSBindings.withCredentials(options.operation);
142
143 return Effect.fn(function* (ruleGroup: RuleGroup) {
144 const RuleGroupArn = yield* ruleGroup.ruleGroupArn;
145 if (!globalThis.__ALCHEMY_RUNTIME__) {
146 yield* bind`${options.tag}(${ruleGroup})`({
147 policyStatements: [
148 {
149 Effect: "Allow",
150 Action: [...options.actions],
151 Resource: [ruleGroup.ruleGroupArn],
152 },
153 ],
154 });
155 }
156 return Effect.fn(`${options.tag}(${ruleGroup.LogicalId})`)(function* (
157 request?: Omit<I, "RuleGroupArn" | "RuleGroupName" | "Type">,
158 ) {
159 return yield* op({
160 ...request,
161 RuleGroupArn: yield* RuleGroupArn,
162 } as I);
163 });
164 });
165 });