@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, 06:00 UTC

main
ts 49 lines 1.85 KB
Raw
1 import * as grafana from "@distilled.cloud/aws/grafana";
2 import * as Output from "alchemy/Output";
3 import { toWireSeconds } from "alchemy/Util/Duration";
4 import * as Effect from "effect/Effect";
5 import * as Layer from "effect/Layer";
6 import * as AWSBindings from "../AWSBindings.ts";
7 import {
8 CreateWorkspaceServiceAccountToken,
9 type CreateWorkspaceServiceAccountTokenRequest,
10 } from "./CreateWorkspaceServiceAccountToken.ts";
11 import type { Workspace } from "./Workspace.ts";
12
13 /**
14 * Bespoke (not scaffold-built): the runtime request carries a
15 * `timeToLive: Duration.Input` that is converted to the wire's
16 * `secondsToLive` via the central Duration util.
17 */
18 export const CreateWorkspaceServiceAccountTokenHttp = Layer.effect(
19 CreateWorkspaceServiceAccountToken,
20 Effect.gen(function* () {
21 const bind = yield* AWSBindings.Bind;
22 const op = yield* AWSBindings.withCredentials(grafana.createWorkspaceServiceAccountToken);
23
24 return Effect.fn(function* (workspace: Workspace) {
25 const workspaceId = yield* workspace.workspaceId;
26 if (!globalThis.__ALCHEMY_RUNTIME__) {
27 yield* bind`AWS.Grafana.CreateWorkspaceServiceAccountToken(${workspace})`({
28 policyStatements: [
29 {
30 Effect: "Allow",
31 Action: ["grafana:CreateWorkspaceServiceAccountToken"],
32 Resource: [Output.interpolate`${workspace.workspaceArn}`],
33 },
34 ],
35 });
36 }
37 return Effect.fn(`AWS.Grafana.CreateWorkspaceServiceAccountToken(${workspace.LogicalId})`)(
38 function* (request: CreateWorkspaceServiceAccountTokenRequest) {
39 return yield* op({
40 name: request.name,
41 serviceAccountId: request.serviceAccountId,
42 secondsToLive: toWireSeconds(request.timeToLive)!,
43 workspaceId: yield* workspaceId,
44 });
45 },
46 );
47 });
48 }),
49 );