]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
add enable_federated_downvotes site option
[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   // Prometheus configuration.
49   #[default(None)]
50   #[doku(example = "Some(Default::default())")]
51   pub prometheus: Option<PrometheusConfig>,
52 }
53
54 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
55 #[serde(default, deny_unknown_fields)]
56 pub struct PictrsConfig {
57   /// Address where pictrs is available (for image hosting)
58   #[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
59   #[doku(example = "http://localhost:8080")]
60   pub url: Url,
61
62   /// Set a custom pictrs API key. ( Required for deleting images )
63   #[default(None)]
64   pub api_key: Option<String>,
65 }
66
67 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
68 #[serde(default)]
69 pub struct DatabaseConfig {
70   #[serde(flatten, default)]
71   pub connection: DatabaseConnection,
72
73   /// Maximum number of active sql connections
74   #[default(5)]
75   pub pool_size: usize,
76 }
77
78 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
79 #[serde(untagged)]
80 pub enum DatabaseConnection {
81   /// Configure the database by specifying a URI
82   ///
83   /// This is the preferred method to specify database connection details since
84   /// it is the most flexible.
85   Uri {
86     /// Connection URI pointing to a postgres instance
87     ///
88     /// This example uses peer authentication to obviate the need for creating,
89     /// configuring, and managing passwords.
90     ///
91     /// For an explanation of how to use connection URIs, see [here][0] in
92     /// PostgreSQL's documentation.
93     ///
94     /// [0]: https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6
95     #[doku(example = "postgresql:///lemmy?user=lemmy&host=/var/run/postgresql")]
96     uri: String,
97   },
98
99   /// Configure the database by specifying parts of a URI
100   ///
101   /// Note that specifying the `uri` field should be preferred since it provides
102   /// greater control over how the connection is made. This merely exists for
103   /// backwards-compatibility.
104   #[default]
105   Parts(DatabaseConnectionParts),
106 }
107
108 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
109 #[serde(default)]
110 pub struct DatabaseConnectionParts {
111   /// Username to connect to postgres
112   #[default("lemmy")]
113   pub(super) user: String,
114   /// Password to connect to postgres
115   #[default("password")]
116   pub password: String,
117   #[default("localhost")]
118   /// Host where postgres is running
119   pub host: String,
120   /// Port where postgres can be accessed
121   #[default(5432)]
122   pub(super) port: i32,
123   /// Name of the postgres database for lemmy
124   #[default("lemmy")]
125   pub(super) database: String,
126 }
127
128 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
129 #[serde(deny_unknown_fields)]
130 pub struct EmailConfig {
131   /// Hostname and port of the smtp server
132   #[doku(example = "localhost:25")]
133   pub smtp_server: String,
134   /// Login name for smtp server
135   pub smtp_login: Option<String>,
136   /// Password to login to the smtp server
137   pub smtp_password: Option<String>,
138   #[doku(example = "noreply@example.com")]
139   /// Address to send emails from, eg "noreply@your-instance.com"
140   pub smtp_from_address: String,
141   /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
142   #[default("none")]
143   #[doku(example = "none")]
144   pub tls_type: String,
145 }
146
147 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
148 #[serde(deny_unknown_fields)]
149 pub struct SetupConfig {
150   /// Username for the admin user
151   #[doku(example = "admin")]
152   pub admin_username: String,
153   /// Password for the admin user. It must be at least 10 characters.
154   #[doku(example = "tf6HHDS4RolWfFhk4Rq9")]
155   pub admin_password: String,
156   /// Name of the site (can be changed later)
157   #[doku(example = "My Lemmy Instance")]
158   pub site_name: String,
159   /// Email for the admin user (optional, can be omitted and set later through the website)
160   #[doku(example = "user@example.com")]
161   #[default(None)]
162   pub admin_email: Option<String>,
163 }
164
165 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
166 #[serde(deny_unknown_fields)]
167 pub struct PrometheusConfig {
168   // Address that the Prometheus metrics will be served on.
169   #[default(Some(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))))]
170   #[doku(example = "127.0.0.1")]
171   pub bind: Option<IpAddr>,
172   // Port that the Prometheus metrics will be served on.
173   #[default(Some(10002))]
174   #[doku(example = "10002")]
175   pub port: Option<i32>,
176 }