]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Remove `actix_rt` & use standard tokio spawn (#3158)
[lemmy.git] / crates / utils / src / settings / structs.rs
1 use doku::Document;
2 use serde::{Deserialize, Serialize};
3 use std::net::{IpAddr, Ipv4Addr};
4 use url::Url;
5
6 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
7 #[serde(default)]
8 pub struct Settings {
9   /// settings related to the postgresql database
10   #[default(Default::default())]
11   pub database: DatabaseConfig,
12   /// Settings related to activitypub federation
13   /// Pictrs image server configuration.
14   #[default(Some(Default::default()))]
15   pub(crate) pictrs: Option<PictrsConfig>,
16   /// Email sending configuration. All options except login/password are mandatory
17   #[default(None)]
18   #[doku(example = "Some(Default::default())")]
19   pub email: Option<EmailConfig>,
20   /// Parameters for automatic configuration of new instance (only used at first start)
21   #[default(None)]
22   #[doku(example = "Some(Default::default())")]
23   pub setup: Option<SetupConfig>,
24   /// the domain name of your instance (mandatory)
25   #[default("unset")]
26   #[doku(example = "example.com")]
27   pub hostname: String,
28   /// Address where lemmy should listen for incoming requests
29   #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
30   #[doku(as = "String")]
31   pub bind: IpAddr,
32   /// Port where lemmy should listen for incoming requests
33   #[default(8536)]
34   pub port: u16,
35   /// Whether the site is available over TLS. Needs to be true for federation to work.
36   #[default(true)]
37   pub tls_enabled: bool,
38   /// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not set this option
39   #[default(None)]
40   #[doku(skip)]
41   pub opentelemetry_url: Option<Url>,
42   /// The number of activitypub federation workers that can be in-flight concurrently
43   #[default(0)]
44   pub worker_count: usize,
45   /// The number of activitypub federation retry workers that can be in-flight concurrently
46   #[default(0)]
47   pub retry_count: usize,
48 }
49
50 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
51 #[serde(default, deny_unknown_fields)]
52 pub struct PictrsConfig {
53   /// Address where pictrs is available (for image hosting)
54   #[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
55   #[doku(example = "http://localhost:8080")]
56   pub url: Url,
57
58   /// Set a custom pictrs API key. ( Required for deleting images )
59   #[default(None)]
60   pub api_key: Option<String>,
61 }
62
63 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
64 #[serde(default)]
65 pub struct DatabaseConfig {
66   #[serde(flatten, default)]
67   pub connection: DatabaseConnection,
68
69   /// Maximum number of active sql connections
70   #[default(5)]
71   pub pool_size: usize,
72 }
73
74 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
75 #[serde(untagged)]
76 pub enum DatabaseConnection {
77   /// Configure the database by specifying a URI
78   ///
79   /// This is the preferred method to specify database connection details since
80   /// it is the most flexible.
81   Uri {
82     /// Connection URI pointing to a postgres instance
83     ///
84     /// This example uses peer authentication to obviate the need for creating,
85     /// configuring, and managing passwords.
86     ///
87     /// For an explanation of how to use connection URIs, see [here][0] in
88     /// PostgreSQL's documentation.
89     ///
90     /// [0]: https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6
91     #[doku(example = "postgresql:///lemmy?user=lemmy&host=/var/run/postgresql")]
92     uri: String,
93   },
94
95   /// Configure the database by specifying parts of a URI
96   ///
97   /// Note that specifying the `uri` field should be preferred since it provides
98   /// greater control over how the connection is made. This merely exists for
99   /// backwards-compatibility.
100   #[default]
101   Parts(DatabaseConnectionParts),
102 }
103
104 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
105 #[serde(default)]
106 pub struct DatabaseConnectionParts {
107   /// Username to connect to postgres
108   #[default("lemmy")]
109   pub(super) user: String,
110   /// Password to connect to postgres
111   #[default("password")]
112   pub password: String,
113   #[default("localhost")]
114   /// Host where postgres is running
115   pub host: String,
116   /// Port where postgres can be accessed
117   #[default(5432)]
118   pub(super) port: i32,
119   /// Name of the postgres database for lemmy
120   #[default("lemmy")]
121   pub(super) database: String,
122 }
123
124 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
125 #[serde(deny_unknown_fields)]
126 pub struct EmailConfig {
127   /// Hostname and port of the smtp server
128   #[doku(example = "localhost:25")]
129   pub smtp_server: String,
130   /// Login name for smtp server
131   pub smtp_login: Option<String>,
132   /// Password to login to the smtp server
133   pub smtp_password: Option<String>,
134   #[doku(example = "noreply@example.com")]
135   /// Address to send emails from, eg "noreply@your-instance.com"
136   pub smtp_from_address: String,
137   /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
138   #[default("none")]
139   #[doku(example = "none")]
140   pub tls_type: String,
141 }
142
143 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
144 #[serde(deny_unknown_fields)]
145 pub struct SetupConfig {
146   /// Username for the admin user
147   #[doku(example = "admin")]
148   pub admin_username: String,
149   /// Password for the admin user. It must be at least 10 characters.
150   #[doku(example = "tf6HHDS4RolWfFhk4Rq9")]
151   pub admin_password: String,
152   /// Name of the site (can be changed later)
153   #[doku(example = "My Lemmy Instance")]
154   pub site_name: String,
155   /// Email for the admin user (optional, can be omitted and set later through the website)
156   #[doku(example = "user@example.com")]
157   #[default(None)]
158   pub admin_email: Option<String>,
159 }