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
| 1 | import * as dataexchange from "@distilled.cloud/aws/dataexchange"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as AWSBindings from "../AWSBindings.ts"; |
| 5 | import { StartJob } from "./StartJob.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Bespoke implementation (not the shared account builder): a started job |
| 9 | * runs with the caller's forwarded permissions, so on top of the |
| 10 | * `dataexchange:*` actions it needs S3 access to AWS Data Exchange's own |
| 11 | * service buckets (`arn:aws:s3:::*aws-data-exchange*`) — import jobs write |
| 12 | * staged assets there (`s3:PutObject`/`s3:PutObjectAcl`), export jobs read |
| 13 | * them (`s3:GetObject`). Mirrors the AWS-managed |
| 14 | * `AWSDataExchangeProviderFullAccess` policy, including the `aws:CalledVia` |
| 15 | * condition that limits the S3 grant to calls made through Data Exchange. |
| 16 | */ |
| 17 | export const StartJobHttp = Layer.effect( |
| 18 | StartJob, |
| 19 | Effect.gen(function* () { |
| 20 | const bind = yield* AWSBindings.Bind; |
| 21 | const op = yield* AWSBindings.withCredentials(dataexchange.startJob); |
| 22 | |
| 23 | return Effect.fn(function* () { |
| 24 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 25 | yield* bind`AWS.DataExchange.StartJob()`({ |
| 26 | policyStatements: [ |
| 27 | { |
| 28 | Effect: "Allow", |
| 29 | Action: [ |
| 30 | "dataexchange:StartJob", |
| 31 | "dataexchange:CreateAsset", |
| 32 | "dataexchange:GetAsset", |
| 33 | ], |
| 34 | Resource: ["*"], |
| 35 | }, |
| 36 | { |
| 37 | Effect: "Allow", |
| 38 | Action: ["s3:GetObject", "s3:PutObject", "s3:PutObjectAcl"], |
| 39 | Resource: ["arn:aws:s3:::*aws-data-exchange*"], |
| 40 | Condition: { |
| 41 | "ForAnyValue:StringEquals": { |
| 42 | "aws:CalledVia": ["dataexchange.amazonaws.com"], |
| 43 | }, |
| 44 | }, |
| 45 | }, |
| 46 | ], |
| 47 | }); |
| 48 | } |
| 49 | return Effect.fn("AWS.DataExchange.StartJob")(function* ( |
| 50 | request: dataexchange.StartJobRequest, |
| 51 | ) { |
| 52 | return yield* op(request); |
| 53 | }); |
| 54 | }); |
| 55 | }), |
| 56 | ); |