1import * as cloudrun from "@distilled.cloud/gcp/run_v2";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import { bindGcpHost } from "../Host.ts";
5import { grantFor } from "../HttpBinding.ts";
6import { GetService, type GetServiceRequest } from "./GetService.ts";
7import type { Service } from "./Service.ts";
8
9/**
10 * HTTP implementation of {@link GetService}.
11 *
12 * @layer
13 * @provides GCP.Run.GetService
14 */
15export const GetServiceHttp = Layer.effect(
16 GetService,
17 Effect.gen(function* () {
18 const get = yield* cloudrun.getProjectsLocationsServices;
19 return Effect.fn(function* <T extends Service>(service: T) {
20 const name = yield* service.name;
21 yield* bindGcpHost({
22 tag: "GCP.Run.GetService",
23 resource: service,
24 iam: [
25 grantFor(
26 { role: "roles/run.viewer", on: "run.service" },
27 service.name,
28 ),
29 ],
30 });
31 return Effect.fn(`GCP.Run.GetService(${service.LogicalId})`)(function* (
32 request?: GetServiceRequest,
33 ) {
34 return yield* get({
35 ...request,
36 name: yield* name,
37 });
38 });
39 });
40 }),
41);