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

main
ts 36 lines 1.16 KB
Raw
1 import * as apikeys from "@distilled.cloud/gcp/apikeys_v2";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as GCPBindings from "../GCPBindings.ts";
5 import { GetKeyString } from "./GetKeyString.ts";
6 import type { Key } from "./Key.ts";
7
8 /**
9 * HTTP implementation of {@link GetKeyString}.
10 *
11 * @layer
12 * @provides GCP.ApiKeys.GetKeyString
13 */
14 export const GetKeyStringHttp = Layer.effect(
15 GetKeyString,
16 Effect.gen(function* () {
17 const bind = yield* GCPBindings.Bind;
18 const getKeyStringProjectsLocationsKeys = yield* GCPBindings.withCredentials(
19 apikeys.getKeyStringProjectsLocationsKeys,
20 );
21 return Effect.fn(function* <K extends Key>(key: K) {
22 if (!globalThis.__ALCHEMY_RUNTIME__) {
23 yield* bind`GCP.ApiKeys.GetKeyString(${key})`({
24 // API keys have no resource-level IAM.
25 iam: [{ role: "roles/serviceusage.apiKeysViewer" }],
26 });
27 }
28 const name = yield* key.name;
29 return Effect.fn(`GCP.ApiKeys.GetKeyString(${key.LogicalId})`)(function* () {
30 return yield* getKeyStringProjectsLocationsKeys({
31 name: yield* name,
32 });
33 });
34 });
35 }),
36 );