1import * as binaryauthorization from "@distilled.cloud/gcp/binaryauthorization_v1";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import type { Attestor } from "./Attestor.ts";
5import { GetAttestor, type GetAttestorRequest } from "./GetAttestor.ts";
6import { bindGcpHost } from "../Host.ts";
7import { grantFor } from "../HttpBinding.ts";
8
9/**
10 * HTTP implementation of {@link GetAttestor}.
11 *
12 * @layer
13 * @provides GCP.BinaryAuthorization.GetAttestor
14 */
15export const GetAttestorHttp = Layer.effect(
16 GetAttestor,
17 Effect.gen(function* () {
18 const getAttestor = yield* binaryauthorization.getProjectsAttestors;
19 return Effect.fn(function* (attestor: Attestor) {
20 yield* bindGcpHost({
21 tag: "GCP.BinaryAuthorization.GetAttestor",
22 resource: attestor,
23 iam: [
24 grantFor(
25 {
26 role: "roles/binaryauthorization.attestorsViewer",
27 on: "binaryauthorization.attestor",
28 },
29 attestor.name,
30 ),
31 ],
32 });
33 const name = yield* attestor.name;
34 return Effect.fn(
35 `GCP.BinaryAuthorization.GetAttestor(${attestor.LogicalId})`,
36 )(function* (request?: GetAttestorRequest) {
37 const attestorName = yield* name;
38 return yield* getAttestor({
39 ...request,
40 name: attestorName,
41 });
42 });
43 });
44 }),
45);