]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Merge branch 'main' into asonix/document-opentelemetry-url
[lemmy.git] / crates / utils / src / settings / structs.rs
1 use doku::Document;
2 use serde::{Deserialize, Serialize};
3 use std::net::{IpAddr, Ipv4Addr};
4
5 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
6 #[serde(default)]
7 pub struct Settings {
8   /// settings related to the postgresql database
9   #[serde(default)]
10   pub database: DatabaseConfig,
11   #[default(Some(RateLimitConfig::default()))]
12   /// rate limits for various user actions, by user ip
13   pub rate_limit: Option<RateLimitConfig>,
14   /// Settings related to activitypub federation
15   #[default(FederationConfig::default())]
16   pub federation: FederationConfig,
17   #[default(CaptchaConfig::default())]
18   pub captcha: CaptchaConfig,
19   /// Email sending configuration. All options except login/password are mandatory
20   #[default(None)]
21   pub email: Option<EmailConfig>,
22   /// Parameters for automatic configuration of new instance (only used at first start)
23   #[default(None)]
24   pub setup: Option<SetupConfig>,
25   /// the domain name of your instance (mandatory)
26   #[default("unset")]
27   #[doku(example = "example.com")]
28   pub hostname: String,
29   /// Address where lemmy should listen for incoming requests
30   #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
31   #[doku(as = "String")]
32   pub bind: IpAddr,
33   /// Port where lemmy should listen for incoming requests
34   #[default(8536)]
35   pub port: u16,
36   /// Whether the site is available over TLS. Needs to be true for federation to work.
37   #[default(true)]
38   pub tls_enabled: bool,
39   /// Address where pictrs is available (for image hosting)
40   #[default(None)]
41   #[doku(example = "http://localhost:8080")]
42   pub pictrs_url: Option<String>,
43   #[default(None)]
44   #[doku(example = "(\\bThis\\b)|(\\bis\\b)|(\\bsample\\b)")]
45   pub slur_filter: Option<String>,
46   /// Maximum length of local community and user names
47   #[default(20)]
48   pub actor_name_max_length: usize,
49   /// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search).
50   #[default(25)]
51   pub http_fetch_retry_limit: i32,
52
53   /// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not set this option
54   #[default(None)]
55   #[doku(example = "http://localhost:4317")]
56   pub opentelemetry_url: Option<String>,
57 }
58
59 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
60 #[serde(default)]
61 pub struct CaptchaConfig {
62   /// Whether captcha is required for signup
63   #[default(false)]
64   pub enabled: bool,
65   /// Can be easy, medium, or hard
66   #[default("medium")]
67   pub difficulty: String,
68 }
69
70 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
71 #[serde(default)]
72 pub struct DatabaseConfig {
73   /// Username to connect to postgres
74   #[default("lemmy")]
75   pub(super) user: String,
76   /// Password to connect to postgres
77   #[default("password")]
78   pub password: String,
79   #[default("localhost")]
80   /// Host where postgres is running
81   pub host: String,
82   /// Port where postgres can be accessed
83   #[default(5432)]
84   pub(super) port: i32,
85   /// Name of the postgres database for lemmy
86   #[default("lemmy")]
87   pub(super) database: String,
88   /// Maximum number of active sql connections
89   #[default(5)]
90   pub pool_size: u32,
91 }
92
93 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
94 pub struct EmailConfig {
95   /// Hostname and port of the smtp server
96   #[doku(example = "localhost:25")]
97   pub smtp_server: String,
98   /// Login name for smtp server
99   pub smtp_login: Option<String>,
100   /// Password to login to the smtp server
101   pub smtp_password: Option<String>,
102   #[doku(example = "noreply@example.com")]
103   /// Address to send emails from, eg "noreply@your-instance.com"
104   pub smtp_from_address: String,
105   /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
106   #[default("none")]
107   #[doku(example = "none")]
108   pub tls_type: String,
109 }
110
111 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
112 #[serde(default)]
113 pub struct FederationConfig {
114   /// Whether to enable activitypub federation.
115   #[default(false)]
116   pub enabled: bool,
117   /// Allows and blocks are described here:
118   /// https://join-lemmy.org/docs/en/federation/administration.html///instance-allowlist-and-blocklist
119   ///
120   /// list of instances with which federation is allowed
121   #[default(None)]
122   #[doku(example = "instance1.tld")]
123   #[doku(example = "instance2.tld")]
124   pub allowed_instances: Option<Vec<String>>,
125   /// Instances which we never federate anything with (but previously federated objects are unaffected)
126   #[default(None)]
127   pub blocked_instances: Option<Vec<String>>,
128   /// If true, only federate with instances on the allowlist and block everything else. If false,
129   /// use allowlist only for remote communities, and posts/comments in local communities
130   /// (meaning remote communities will show content from arbitrary instances).
131   #[default(true)]
132   pub strict_allowlist: bool,
133 }
134
135 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
136 #[serde(default)]
137 pub struct RateLimitConfig {
138   /// Maximum number of messages created in interval
139   #[default(180)]
140   pub message: i32,
141   /// Interval length for message limit, in seconds
142   #[default(60)]
143   pub message_per_second: i32,
144   /// Maximum number of posts created in interval
145   #[default(6)]
146   pub post: i32,
147   /// Interval length for post limit, in seconds
148   #[default(600)]
149   pub post_per_second: i32,
150   /// Maximum number of registrations in interval
151   #[default(3)]
152   pub register: i32,
153   /// Interval length for registration limit, in seconds
154   #[default(3600)]
155   pub register_per_second: i32,
156   /// Maximum number of image uploads in interval
157   #[default(6)]
158   pub image: i32,
159   /// Interval length for image uploads, in seconds
160   #[default(3600)]
161   pub image_per_second: i32,
162   /// Maximum number of comments created in interval
163   #[default(6)]
164   pub comment: i32,
165   /// Interval length for comment limit, in seconds
166   #[default(600)]
167   pub comment_per_second: i32,
168 }
169
170 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
171 pub struct SetupConfig {
172   /// Username for the admin user
173   #[doku(example = "admin")]
174   pub admin_username: String,
175   /// Password for the admin user. It must be at least 10 characters.
176   #[doku(example = "my_passwd_longer_than_ten_characters")]
177   pub admin_password: String,
178   /// Name of the site (can be changed later)
179   #[doku(example = "My Lemmy Instance")]
180   pub site_name: String,
181   /// Email for the admin user (optional, can be omitted and set later through the website)
182   #[default(None)]
183   pub admin_email: Option<String>,
184   #[default(None)]
185   pub sidebar: Option<String>,
186   #[default(None)]
187   pub description: Option<String>,
188   #[default(None)]
189   pub icon: Option<String>,
190   #[default(None)]
191   pub banner: Option<String>,
192   #[default(None)]
193   pub enable_downvotes: Option<bool>,
194   #[default(None)]
195   pub open_registration: Option<bool>,
196   #[default(None)]
197   pub enable_nsfw: Option<bool>,
198   #[default(None)]
199   pub community_creation_admin_only: Option<bool>,
200   #[default(None)]
201   pub require_email_verification: Option<bool>,
202   #[default(None)]
203   pub require_application: Option<bool>,
204   #[default(None)]
205   pub application_question: Option<String>,
206   #[default(None)]
207   pub private_instance: Option<bool>,
208 }