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