1import * as machines from "@distilled.cloud/fly-io/machines";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as FetchHttpClient from "effect/http/FetchHttpClient";
5import { CredentialsFromAmbientOrEnv } from "./Credentials.ts";
6import { ListSecrets } from "./ListSecrets.ts";
7import { makeHttpAppBinding } from "./SecretHttp.ts";
8
9/**
10 * HTTP implementation of {@link ListSecrets}. Provide it on the
11 * {@link Service} or Action Effect.
12 *
13 *
14 * ### Provide the layer
15 * **Example:** On an Action
16 * ```typescript
17 * Effect.gen(function* () {
18 * const list = yield* Fly.ListSecrets(Site);
19 * // ...
20 * }).pipe(Effect.provide(Fly.ListSecretsHttp))
21 * ```
22 *
23 * @layer
24 * @product Secret
25 * @provides Fly.ListSecrets
26 */
27export const ListSecretsHttp = Layer.effect(
28 ListSecrets,
29 Effect.suspend(() =>
30 makeHttpAppBinding({
31 makeClient: (auth, appName) =>
32 Effect.fn("Fly.ListSecrets")(function* () {
33 return yield* auth.authorize(
34 machines.listSecrets({
35 app_name: yield* appName,
36 // Names are enough for the binding; plaintext is env-injected.
37 show_secrets: false,
38 }),
39 );
40 }),
41 }),
42 ),
43).pipe(
44 Layer.provide(FetchHttpClient.layer),
45 Layer.provide(CredentialsFromAmbientOrEnv),
46);