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