The best way to control Claude Code, Codex and more from any computer or phone

main
ts 66 lines 2.62 KB
Raw
1 import * as Lambda from "@alchemy.run/aws/Lambda";
2 import * as SecretsManager from "@alchemy.run/aws/SecretsManager";
3 import * as secretsmanager from "@distilled.cloud/aws/secrets-manager";
4 import * as Effect from "effect/Effect";
5 import { HttpServerRequest } from "effect/http/HttpServerRequest";
6 import * as HttpServerResponse from "effect/http/HttpServerResponse";
7 import * as Redacted from "effect/Redacted";
8
9 export class GetSecretOnlyTestFunction extends Lambda.Function<GetSecretOnlyTestFunction>()(
10 "GetSecretOnlyTestFunction",
11 ) {}
12
13 export default GetSecretOnlyTestFunction.make(
14 { main: import.meta.url, functionUrl: true },
15 Effect.gen(function* () {
16 const secret = yield* SecretsManager.Secret("GetSecretOnlySecret", {
17 secretString: Redacted.make("alchemy-sm-get-only-value"),
18 });
19 const getSecretValue = yield* SecretsManager.GetSecretValue(secret);
20 const describeSecret = yield* secretsmanager.describeSecret;
21 const secretArn = yield* secret.secretArn;
22 const secretName = yield* secret.secretName;
23
24 return {
25 fetch: Effect.gen(function* () {
26 const request = yield* HttpServerRequest;
27 const url = yield* Effect.sync(() => new URL(request.originalUrl));
28
29 if (request.method === "GET" && url.pathname === "/info") {
30 return yield* HttpServerResponse.json({
31 secretArn: yield* secretArn,
32 secretName: yield* secretName,
33 });
34 }
35
36 if (request.method === "GET" && url.pathname === "/get-value") {
37 const result = yield* getSecretValue({
38 VersionId: url.searchParams.get("versionId") ?? undefined,
39 VersionStage: url.searchParams.get("versionStage") ?? undefined,
40 });
41 return yield* HttpServerResponse.json({
42 arn: result.ARN,
43 name: result.Name,
44 versionId: result.VersionId,
45 secretString:
46 typeof result.SecretString === "string" || result.SecretString === undefined
47 ? result.SecretString
48 : Redacted.value(result.SecretString),
49 });
50 }
51
52 if (request.method === "GET" && url.pathname === "/describe-denied") {
53 const tag = yield* describeSecret({
54 SecretId: yield* secretArn,
55 }).pipe(
56 Effect.as("Allowed"),
57 Effect.catchTag("AccessDeniedException", (error) => Effect.succeed(error._tag)),
58 );
59 return yield* HttpServerResponse.json({ tag });
60 }
61
62 return HttpServerResponse.text("Not found", { status: 404 });
63 }).pipe(Effect.orDie),
64 };
65 }).pipe(Effect.provide(SecretsManager.GetSecretValueHttp)),
66 );