fix make seeding an explicit opt-in

The production server refused to start unless HITO_SEED_PASSWORD was set, because it always seeded a single hardcoded account. A deployment that has moved past the seed carried a dead requirement, and a personal export path was a startup dependency. Seeding now runs only when HITO_SEED=1. Then HITO_SEED_PASSWORD is required as before. Otherwise the server starts with whatever accounts the database holds and never asks for a seed password.

Commit
2f92eb3fc562d67fce7dd9c17c5c93f5aab2d062
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
bin/main.ml
index 25914b03..61f9c906 100644..100644
@@ -12,20 +12,22 @@
12 12 - HITO_PORT TCP port. Default: 8080
13 13 - HITO_VERSION Deployment commit identifier shown in the page footer. Defaults
14 14 to "development" outside a deployment.
15 Removed: - HITO_SEED_PASSWORD Password for the seeded [blendux] account. Required.
16 Removed: The server refuses to start when unset. Temporary, until
17 Removed: public registration returns.
15 Added: - HITO_SEED Set to 1 to seed the single [blendux] account on startup.
16 Added: Default: 0, no seeding. Temporary, until public registration
17 Added: returns.
18 Added: - HITO_SEED_PASSWORD Password for the seeded account. Required when
19 Added: HITO_SEED=1; ignored otherwise.
18 20 - HITO_SEED_CSV Path to the Hevy export imported as the seeded account's
19 Removed: history. Default: workout_data.csv. Imported once, when the
20 Removed: account has no promoted records. Temporary, with the seed.
21 Added: history. Default: workout_data.csv. Read only when HITO_SEED=1,
22 Added: and imported once, when the account has no promoted records.
21 23
22 24 The socket binds loopback only. Authentication is local username and
23 25 password. Sessions and CSRF tokens are signed with the secret.
24 26
25 27 Public sign-up is closed: [Handlers.make] leaves [registration_open] at its
26 Removed: [false] default, and a single account ([blendux]) is seeded on startup with
27 Removed: the password from [HITO_SEED_PASSWORD]. Both are temporary until public
28 Removed: registration returns. *)
28 Added: [false] default. When HITO_SEED=1, a single account ([blendux]) is seeded
29 Added: on startup with the password from [HITO_SEED_PASSWORD]. Both are temporary
30 Added: until public registration returns. *)
29 31
30 32 module Handlers =
31 33 Hito_web.Handlers.Make
@@ -71,19 +73,25 @@
71 73 (Caqti_error.show error);
72 74 exit 1
73 75 | Ok repo ->
74 Removed: let seed_password =
75 Removed: match Sys.getenv_opt "HITO_SEED_PASSWORD" with
76 Removed: | Some p when p <> "" -> p
77 Removed: | _ ->
78 Removed: prerr_endline
79 Removed: "hito: HITO_SEED_PASSWORD is not set; refusing to seed the \
80 Removed: account with a default. Set it and restart.";
81 Removed:
82 Removed: exit 1
83 Removed: in
84 Removed: let seed_csv = getenv "HITO_SEED_CSV" "workout_data.csv" in
85 Removed: Lwt_main.run
86 Removed: (Seed.single_user repo ~password:seed_password ~csv_path:seed_csv);
76 Added: (* Seeding a single account is an explicit opt-in. Without HITO_SEED=1
77 Added: the server starts with whatever accounts the database holds and never
78 Added: demands a seed password, so a deployment that has moved past the seed
79 Added: carries no dead requirement. *)
80 Added: (match getenv "HITO_SEED" "0" with
81 Added: | "1" ->
82 Added: let seed_password =
83 Added: match Sys.getenv_opt "HITO_SEED_PASSWORD" with
84 Added: | Some p when p <> "" -> p
85 Added: | _ ->
86 Added: fail_config
87 Added: "HITO_SEED=1 requires HITO_SEED_PASSWORD; refusing to seed \
88 Added: the account with a default"
89 Added: in
90 Added: let seed_csv = getenv "HITO_SEED_CSV" "workout_data.csv" in
91 Added: Lwt_main.run
92 Added: (Seed.single_user repo ~password:seed_password ~csv_path:seed_csv)
93 Added: | "0" -> ()
94 Added: | other -> fail_config "HITO_SEED must be 0 or 1, got %S" other);
87 95 let handlers = Handlers.make ~repo () in
88 96 (* Sessions live in a signed, encrypted cookie, not in SQLite. The
89 97 repository already holds the one connection pool for this file; a