@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 56 lines 2.17 KB
Raw
1 import * as backup from "@distilled.cloud/aws/backup";
2 import * as Output from "alchemy/Output";
3 import * as Effect from "effect/Effect";
4 import * as Layer from "effect/Layer";
5 import * as AWSBindings from "../AWSBindings.ts";
6 import type { Role } from "../IAM/Role.ts";
7 import type { BackupVault } from "./BackupVault.ts";
8 import { StartCopyJob, type StartCopyJobRequest } from "./StartCopyJob.ts";
9
10 export const StartCopyJobHttp = Layer.effect(
11 StartCopyJob,
12 Effect.gen(function* () {
13 const bind = yield* AWSBindings.Bind;
14 const startCopyJob = yield* AWSBindings.withCredentials(backup.startCopyJob);
15
16 return Effect.fn(function* <R extends Role>(sourceVault: BackupVault, copyRole: R) {
17 const SourceBackupVaultName = yield* sourceVault.backupVaultName;
18 const RoleArn = yield* copyRole.roleArn;
19 if (!globalThis.__ALCHEMY_RUNTIME__) {
20 yield* bind`AWS.Backup.StartCopyJob(${sourceVault}, ${copyRole})`({
21 policyStatements: [
22 // StartCopyJob authorizes on the recovery point's underlying
23 // resource ARN and CopyIntoBackupVault on the destination
24 // vault — both runtime request fields, so the grant is `*`.
25 {
26 Effect: "Allow",
27 Action: ["backup:StartCopyJob", "backup:CopyIntoBackupVault"],
28 Resource: ["*"],
29 },
30 // CRITICAL: without iam:PassRole on the copy role,
31 // StartCopyJob fails only at runtime with an AccessDenied.
32 {
33 Effect: "Allow",
34 Action: ["iam:PassRole"],
35 Resource: [Output.interpolate`${copyRole.roleArn}`],
36 Condition: {
37 StringEquals: {
38 "iam:PassedToService": "backup.amazonaws.com",
39 },
40 },
41 },
42 ],
43 });
44 }
45 return Effect.fn(`AWS.Backup.StartCopyJob(${sourceVault.LogicalId})`)(function* (
46 request: StartCopyJobRequest,
47 ) {
48 return yield* startCopyJob({
49 ...request,
50 SourceBackupVaultName: yield* SourceBackupVaultName,
51 IamRoleArn: request.IamRoleArn ?? (yield* RoleArn),
52 });
53 });
54 });
55 }),
56 );