@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 66 lines 2.56 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { PolicyStatement } from "../IAM/Policy.ts";
4
5 /**
6 * Shared HTTP scaffolding for the AWS Service Catalog runtime bindings.
7 *
8 * Service Catalog's end-user (self-service) plane is account-scoped:
9 * which products a caller can see and launch is governed by portfolio
10 * principal associations, not by IAM resource ARNs, and the target
11 * products / provisioned products are discovered per request at runtime
12 * (`searchProducts`, `searchProvisionedProducts`). Every binding is
13 * therefore account-level and grants its action(s) on `Resource: ["*"]`.
14 *
15 * The provisioning writes (`ProvisionProduct`, `UpdateProvisionedProduct`,
16 * `TerminateProvisionedProduct`) additionally grant the CloudFormation
17 * (and template-fetch `s3:GetObject`) actions Service Catalog performs
18 * with the caller's credentials when the product has no launch-role
19 * constraint.
20 *
21 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service
22 * is a `Layer.effect(Cap, makeServiceCatalogHttpBinding({ … }))` over the
23 * builder below. Everything except the operation and the IAM action list
24 * is boilerplate.
25 */
26 export const makeServiceCatalogHttpBinding = <I, A, E, R>(options: {
27 /**
28 * Short capability name used in the binding sid and runtime span, e.g.
29 * `"SearchProducts"`.
30 */
31 capability: string;
32 /**
33 * IAM actions granted on `Resource: ["*"]` (access is governed by
34 * portfolio principal associations; targets are chosen per request).
35 */
36 iamActions: readonly string[];
37 /**
38 * The distilled operation implementing the capability.
39 */
40 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
41 }) =>
42 Effect.gen(function* () {
43 const bind = yield* AWSBindings.Bind;
44 const op = yield* AWSBindings.withCredentials(options.operation);
45
46 return Effect.fn(function* () {
47 if (!globalThis.__ALCHEMY_RUNTIME__) {
48 const policyStatements: PolicyStatement[] = [
49 {
50 Effect: "Allow",
51 Action: [...options.iamActions],
52 // Access is governed by portfolio principal associations;
53 // the target products / provisioned products are chosen per
54 // request at runtime.
55 Resource: ["*"],
56 },
57 ];
58 yield* bind`AWS.ServiceCatalog.${options.capability}()`({
59 policyStatements,
60 });
61 }
62 return Effect.fn(`AWS.ServiceCatalog.${options.capability}`)(function* (request?: I) {
63 return yield* op((request ?? {}) as I);
64 });
65 });
66 });