]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Add option to disable strict allowlist (fixes #1486) (#1581)
[lemmy.git] / crates / utils / src / settings / structs.rs
1 use merge::Merge;
2 use serde::Deserialize;
3 use std::net::IpAddr;
4
5 #[derive(Debug, Deserialize, Clone, Merge)]
6 pub struct Settings {
7   pub(crate) database: Option<DatabaseConfig>,
8   pub(crate) rate_limit: Option<RateLimitConfig>,
9   pub(crate) federation: Option<FederationConfig>,
10   pub(crate) hostname: Option<String>,
11   pub(crate) bind: Option<IpAddr>,
12   pub(crate) port: Option<u16>,
13   pub(crate) tls_enabled: Option<bool>,
14   pub(crate) jwt_secret: Option<String>,
15   pub(crate) pictrs_url: Option<String>,
16   pub(crate) iframely_url: Option<String>,
17   pub(crate) captcha: Option<CaptchaConfig>,
18   pub(crate) email: Option<EmailConfig>,
19   pub(crate) setup: Option<SetupConfig>,
20 }
21
22 #[derive(Debug, Deserialize, Clone)]
23 pub struct CaptchaConfig {
24   pub enabled: bool,
25   pub difficulty: String,
26 }
27
28 #[derive(Debug, Deserialize, Clone)]
29 pub struct DatabaseConfig {
30   pub(super) user: Option<String>,
31   pub password: String,
32   pub host: String,
33   pub(super) port: Option<i32>,
34   pub(super) database: Option<String>,
35   pub(super) pool_size: Option<u32>,
36 }
37
38 impl DatabaseConfig {
39   pub fn user(&self) -> String {
40     self
41       .user
42       .to_owned()
43       .unwrap_or_else(|| DatabaseConfig::default().user.expect("missing user"))
44   }
45   pub fn port(&self) -> i32 {
46     self
47       .port
48       .unwrap_or_else(|| DatabaseConfig::default().port.expect("missing port"))
49   }
50   pub fn database(&self) -> String {
51     self.database.to_owned().unwrap_or_else(|| {
52       DatabaseConfig::default()
53         .database
54         .expect("missing database")
55     })
56   }
57   pub fn pool_size(&self) -> u32 {
58     self.pool_size.unwrap_or_else(|| {
59       DatabaseConfig::default()
60         .pool_size
61         .expect("missing pool_size")
62     })
63   }
64 }
65
66 #[derive(Debug, Deserialize, Clone)]
67 pub struct EmailConfig {
68   pub smtp_server: String,
69   pub smtp_login: Option<String>,
70   pub smtp_password: Option<String>,
71   pub smtp_from_address: String,
72   pub use_tls: bool,
73 }
74
75 #[derive(Debug, Deserialize, Clone)]
76 pub struct FederationConfig {
77   pub enabled: bool,
78   pub allowed_instances: Option<Vec<String>>,
79   pub blocked_instances: Option<Vec<String>>,
80   pub strict_allowlist: Option<bool>,
81 }
82
83 #[derive(Debug, Deserialize, Clone)]
84 pub struct RateLimitConfig {
85   pub message: i32,
86   pub message_per_second: i32,
87   pub post: i32,
88   pub post_per_second: i32,
89   pub register: i32,
90   pub register_per_second: i32,
91   pub image: i32,
92   pub image_per_second: i32,
93 }
94
95 #[derive(Debug, Deserialize, Clone)]
96 pub struct SetupConfig {
97   pub admin_username: String,
98   pub admin_password: String,
99   pub admin_email: Option<String>,
100   pub site_name: String,
101 }