]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Set attribute `deny_unknown_fields` for Lemmy config (#2852)
[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 }
43
44 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
45 #[serde(default, deny_unknown_fields)]
46 pub struct PictrsConfig {
47   /// Address where pictrs is available (for image hosting)
48   #[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
49   #[doku(example = "http://localhost:8080")]
50   pub url: Url,
51
52   /// Set a custom pictrs API key. ( Required for deleting images )
53   #[default(None)]
54   pub api_key: Option<String>,
55 }
56
57 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
58 #[serde(default, deny_unknown_fields)]
59 pub struct DatabaseConfig {
60   /// Username to connect to postgres
61   #[default("lemmy")]
62   pub(super) user: String,
63   /// Password to connect to postgres
64   #[default("password")]
65   pub password: String,
66   #[default("localhost")]
67   /// Host where postgres is running
68   pub host: String,
69   /// Port where postgres can be accessed
70   #[default(5432)]
71   pub(super) port: i32,
72   /// Name of the postgres database for lemmy
73   #[default("lemmy")]
74   pub(super) database: String,
75   /// Maximum number of active sql connections
76   #[default(5)]
77   pub pool_size: usize,
78 }
79
80 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
81 #[serde(deny_unknown_fields)]
82 pub struct EmailConfig {
83   /// Hostname and port of the smtp server
84   #[doku(example = "localhost:25")]
85   pub smtp_server: String,
86   /// Login name for smtp server
87   pub smtp_login: Option<String>,
88   /// Password to login to the smtp server
89   pub smtp_password: Option<String>,
90   #[doku(example = "noreply@example.com")]
91   /// Address to send emails from, eg "noreply@your-instance.com"
92   pub smtp_from_address: String,
93   /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
94   #[default("none")]
95   #[doku(example = "none")]
96   pub tls_type: String,
97 }
98
99 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
100 #[serde(deny_unknown_fields)]
101 pub struct SetupConfig {
102   /// Username for the admin user
103   #[doku(example = "admin")]
104   pub admin_username: String,
105   /// Password for the admin user. It must be at least 10 characters.
106   #[doku(example = "tf6HHDS4RolWfFhk4Rq9")]
107   pub admin_password: String,
108   /// Name of the site (can be changed later)
109   #[doku(example = "My Lemmy Instance")]
110   pub site_name: String,
111   /// Email for the admin user (optional, can be omitted and set later through the website)
112   #[doku(example = "user@example.com")]
113   #[default(None)]
114   pub admin_email: Option<String>,
115 }