| 1 | import type { |
| 2 | AppSecrets, |
| 3 | ListSecretsError, |
| 4 | } from "@distilled.cloud/fly-io/machines"; |
| 5 | import type * as Effect from "effect/Effect"; |
| 6 | import * as Binding from "../Binding.ts"; |
| 7 | import type { RuntimeContext } from "../RuntimeContext.ts"; |
| 8 | import type { App } from "./App.ts"; |
| 9 | |
| 10 | /** |
| 11 | * List Fly.io App secrets. Scoped to an {@link App}. Fly's list API |
| 12 | * is `GET /apps/{app}/secrets`, not a single Secret. |
| 13 | * |
| 14 | * |
| 15 | * ### List this App |
| 16 | * The App is fixed by `ListSecrets(app)`. Calls take no `app_name`. |
| 17 | * Provide {@link ListSecretsHttp}. |
| 18 | * |
| 19 | * Plaintext is only returned from inside a Machine in the same App. |
| 20 | * From a deploy-time Action you get metadata (name, digest, |
| 21 | * timestamps). |
| 22 | * |
| 23 | * **Example:** ListSecrets |
| 24 | * ```typescript |
| 25 | * const list = yield* Fly.ListSecrets(Site); |
| 26 | * const { secrets } = yield* list(); |
| 27 | * ``` |
| 28 | * |
| 29 | * ### List another App |
| 30 | * From an Action, the org `FLY_API_TOKEN` can list any App in the |
| 31 | * org. `ListSecrets(other)` is how you reach across Apps. |
| 32 | * |
| 33 | * From a Machine, deploy tokens are per-App. Mixing Apps on one host |
| 34 | * shares one `FLY_API_TOKEN` and is not supported. |
| 35 | * |
| 36 | * **Example:** Cross-app from an Action |
| 37 | * ```typescript |
| 38 | * const Seed = Alchemy.Action( |
| 39 | * "Seed", |
| 40 | * Effect.gen(function* () { |
| 41 | * const list = yield* Fly.ListSecrets(Other); |
| 42 | * |
| 43 | * return Effect.fn(function* () { |
| 44 | * const { secrets } = yield* list(); |
| 45 | * return secrets; |
| 46 | * }); |
| 47 | * }).pipe(Effect.provide(Fly.ListSecretsHttp)), |
| 48 | * ); |
| 49 | * ``` |
| 50 | * |
| 51 | * @binding |
| 52 | * @product Secret |
| 53 | */ |
| 54 | export interface ListSecrets extends Binding.Service< |
| 55 | ListSecrets, |
| 56 | "Fly.ListSecrets", |
| 57 | ( |
| 58 | app: App, |
| 59 | ) => Effect.Effect< |
| 60 | () => Effect.Effect<AppSecrets, ListSecretsError, RuntimeContext> |
| 61 | > |
| 62 | > {} |
| 63 | |
| 64 | export const ListSecrets = Binding.Service<ListSecrets>("Fly.ListSecrets"); |