The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as cloudrun from "@distilled.cloud/gcp/run_v2"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import * as GCPBindings from "../GCPBindings.ts"; |
| 5 | import { grantFor } from "../HttpBinding.ts"; |
| 6 | import { GetService, type GetServiceRequest } from "./GetService.ts"; |
| 7 | import type { Service } from "./Service.ts"; |
| 8 | |
| 9 | /** |
| 10 | * HTTP implementation of {@link GetService}. |
| 11 | * |
| 12 | * @layer |
| 13 | * @provides GCP.Run.GetService |
| 14 | */ |
| 15 | export const GetServiceHttp = Layer.effect( |
| 16 | GetService, |
| 17 | Effect.gen(function* () { |
| 18 | const bind = yield* GCPBindings.Bind; |
| 19 | const get = yield* GCPBindings.withCredentials(cloudrun.getProjectsLocationsServices); |
| 20 | return Effect.fn(function* <T extends Service>(service: T) { |
| 21 | const name = yield* service.name; |
| 22 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 23 | yield* bind`GCP.Run.GetService(${service})`({ |
| 24 | iam: [grantFor({ role: "roles/run.viewer", on: "run.service" }, service.name)], |
| 25 | }); |
| 26 | } |
| 27 | return Effect.fn(`GCP.Run.GetService(${service.LogicalId})`)(function* ( |
| 28 | request?: GetServiceRequest, |
| 29 | ) { |
| 30 | return yield* get({ |
| 31 | ...request, |
| 32 | name: yield* name, |
| 33 | }); |
| 34 | }); |
| 35 | }); |
| 36 | }), |
| 37 | ); |