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