@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 62 lines 2.22 KB
Raw
1 import * as codeartifact from "@distilled.cloud/aws/codeartifact";
2 import { toWireSeconds } from "alchemy/Util/Duration";
3 import * as Effect from "effect/Effect";
4 import * as Layer from "effect/Layer";
5 import * as AWSBindings from "../AWSBindings.ts";
6 import type { Domain } from "./Domain.ts";
7 import {
8 GetAuthorizationToken,
9 type GetAuthorizationTokenRequest,
10 } from "./GetAuthorizationToken.ts";
11
12 /**
13 * HTTP implementation of {@link GetAuthorizationToken} over the CodeArtifact
14 * API. Domain-scoped (not repository-scoped): tokens authorize against every
15 * repository in the domain, and CodeArtifact exchanges the caller's
16 * credentials via `sts:GetServiceBearerToken`.
17 */
18 export const GetAuthorizationTokenHttp = Layer.effect(
19 GetAuthorizationToken,
20 Effect.gen(function* () {
21 const bind = yield* AWSBindings.Bind;
22 const op = yield* AWSBindings.withCredentials(codeartifact.getAuthorizationToken);
23
24 return Effect.fn(function* (domain: Domain) {
25 const DomainName = yield* domain.domainName;
26 const Owner = yield* domain.owner;
27 if (!globalThis.__ALCHEMY_RUNTIME__) {
28 yield* bind`AWS.CodeArtifact.GetAuthorizationToken(${domain})`({
29 policyStatements: [
30 {
31 Effect: "Allow",
32 Action: ["codeartifact:GetAuthorizationToken"],
33 Resource: [domain.domainArn],
34 },
35 {
36 // CodeArtifact exchanges the caller's credentials for the
37 // bearer token through STS on the caller's behalf.
38 Effect: "Allow",
39 Action: ["sts:GetServiceBearerToken"],
40 Resource: ["*"],
41 Condition: {
42 StringEquals: {
43 "sts:AWSServiceName": "codeartifact.amazonaws.com",
44 },
45 },
46 },
47 ],
48 });
49 }
50 return Effect.fn(`AWS.CodeArtifact.GetAuthorizationToken(${domain.LogicalId})`)(function* (
51 request?: GetAuthorizationTokenRequest,
52 ) {
53 const owner = yield* Owner;
54 return yield* op({
55 domain: yield* DomainName,
56 ...(owner === "" ? {} : { domainOwner: owner }),
57 durationSeconds: toWireSeconds(request?.duration),
58 });
59 });
60 });
61 }),
62 );