The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import * as Alchemy from "alchemy"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Redacted from "effect/Redacted"; |
| 5 | import { database } from "./database.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Writes the app user's password as the secret's latest version at deploy |
| 9 | * time, so the service can read it at runtime. |
| 10 | */ |
| 11 | export const storePassword = Effect.gen(function* () { |
| 12 | const { password, passwordSecret } = yield* database; |
| 13 | |
| 14 | const StorePassword = Alchemy.Action( |
| 15 | "StorePassword", |
| 16 | Effect.gen(function* () { |
| 17 | const secret = yield* GCP.SecretManager.ReadWriteSecret(passwordSecret); |
| 18 | return Effect.fn(function* (input: { password: Redacted.Redacted<string> }) { |
| 19 | const value = Redacted.value(input.password); |
| 20 | if ((yield* secret.access()) !== value) { |
| 21 | yield* secret.addVersion(value); |
| 22 | } |
| 23 | }); |
| 24 | }).pipe(Effect.provide(GCP.SecretManager.ReadWriteSecretHttp)), |
| 25 | ); |
| 26 | |
| 27 | return yield* StorePassword({ password: password.text }); |
| 28 | }); |