mail based rss feed aggregator
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

make sure the `default admin` (the email stuff gets sent from) is present in the db

ollie c1b5b9de 30e2fa60

+43 -6
+28 -3
src/eater.gleam
··· 17 17 // See the Licence for the specific language governing permissions and limitations. [cite: 6] 18 18 19 19 import eater/configuration 20 + import eater/database 20 21 import eater/fetcher 21 22 import eater/sender 22 23 import eater/smtp 24 + import eater/user 23 25 import eater/webserver 24 26 import envoy 25 27 import gleam/erlang/process 26 28 import gleam/otp/static_supervisor as supervisor 27 29 import gleam/result 28 30 import group_registry 29 - import logging 30 31 import sqlight 31 32 import woof 32 33 ··· 37 38 38 39 woof.log(logger, woof.Info, "Starting", []) 39 40 40 - let configuration = configuration.from_environment(logger) 41 + let assert Ok(configuration) = configuration.from_environment(logger) 41 42 42 43 let assert Ok(smtp_environment) = smtp.environment() 43 44 as "Failed to get smtp environment" ··· 45 46 let assert Ok(database) = database_config(logger) 46 47 as "Failed to get database config" 47 48 use database <- sqlight.with_connection(database) 49 + 50 + let assert Ok(_) = 51 + ensure_default_admin_exists(database, smtp_environment, configuration) 48 52 49 53 let registry = process.new_name("registry") 50 54 let fetcher_factory = process.new_name("fetcher_factory") ··· 89 93 process.sleep_forever() 90 94 } 91 95 92 - fn configure_logging() { 96 + fn ensure_default_admin_exists( 97 + database: sqlight.Connection, 98 + smtp_environment: smtp.SmtpEnvironment, 99 + configuration: configuration.AppConfig, 100 + ) -> Result(user.User, sqlight.Error) { 101 + let sender_email = smtp.sender_email(smtp_environment) 102 + 103 + use maybe_user <- result.try(database.user_by_email(database, sender_email)) 104 + 105 + case maybe_user { 106 + Ok(user) -> Ok(user) 107 + Error(_) -> { 108 + let user = 109 + user.new(sender_email, configuration.default_admin_password_hash) 110 + |> user.promote 111 + 112 + database.add_user(user:, into: database) 113 + } 114 + } 115 + } 116 + 117 + fn configure_logging() -> Nil { 93 118 woof.configure(woof.Config( 94 119 level: woof.Debug, 95 120 format: woof.Json,
+15 -3
src/eater/configuration.gleam
··· 1 + import eater/user 1 2 import envoy 3 + import gleam/result 2 4 import woof 3 5 4 6 pub type AppConfig { 5 - AppConfig(allow_signups: Bool) 7 + AppConfig(allow_signups: Bool, default_admin_password_hash: BitArray) 6 8 } 7 9 8 - pub fn from_environment(logger: woof.Logger) -> AppConfig { 10 + pub fn from_environment(logger: woof.Logger) -> Result(AppConfig, String) { 9 11 woof.log(logger, woof.Info, "Getting ALLOW_SIGNUPS", []) 10 12 13 + use password <- result.try( 14 + envoy.get("ADMIN_PASSWORD") 15 + |> result.replace_error("ADMIN_PASSWORD is missing"), 16 + ) 17 + 11 18 let allow_signups = case envoy.get("ALLOW_SIGNUPS") { 12 19 Ok("false") | Ok("False") | Ok("FALSE") -> False 13 20 Ok(_) -> True 14 21 _ -> False 15 22 } 16 - AppConfig(allow_signups:) 23 + 24 + AppConfig( 25 + allow_signups:, 26 + default_admin_password_hash: user.hash_password(password), 27 + ) 28 + |> Ok 17 29 }