]> Untitled Git - lemmy.git/blobdiff - crates/utils/src/settings/structs.rs
Remove `actix_rt` & use standard tokio spawn (#3158)
[lemmy.git] / crates / utils / src / settings / structs.rs
index 7ee8cf18bca57a313b8d72dfda7379c679885c98..5d0e642f6a2a55787ebfe7c34e2b5a20c67f8207 100644 (file)
@@ -9,17 +9,10 @@ pub struct Settings {
   /// settings related to the postgresql database
   #[default(Default::default())]
   pub database: DatabaseConfig,
-  /// rate limits for various user actions, by user ip
-  #[default(Some(Default::default()))]
-  pub rate_limit: Option<RateLimitConfig>,
   /// Settings related to activitypub federation
-  #[default(Default::default())]
-  pub federation: FederationConfig,
   /// Pictrs image server configuration.
   #[default(Some(Default::default()))]
-  pub(crate) pictrs_config: Option<PictrsConfig>,
-  #[default(Default::default())]
-  pub captcha: CaptchaConfig,
+  pub(crate) pictrs: Option<PictrsConfig>,
   /// Email sending configuration. All options except login/password are mandatory
   #[default(None)]
   #[doku(example = "Some(Default::default())")]
@@ -42,26 +35,24 @@ pub struct Settings {
   /// Whether the site is available over TLS. Needs to be true for federation to work.
   #[default(true)]
   pub tls_enabled: bool,
-  #[default(None)]
-  #[doku(example = "(\\bThis\\b)|(\\bis\\b)|(\\bsample\\b)")]
-  /// A regex list of slurs to block / hide
-  pub slur_filter: Option<String>,
-  /// Maximum length of local community and user names
-  #[default(20)]
-  pub actor_name_max_length: usize,
-
   /// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not set this option
   #[default(None)]
   #[doku(skip)]
   pub opentelemetry_url: Option<Url>,
+  /// The number of activitypub federation workers that can be in-flight concurrently
+  #[default(0)]
+  pub worker_count: usize,
+  /// The number of activitypub federation retry workers that can be in-flight concurrently
+  #[default(0)]
+  pub retry_count: usize,
 }
 
 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
-#[serde(default)]
+#[serde(default, deny_unknown_fields)]
 pub struct PictrsConfig {
   /// Address where pictrs is available (for image hosting)
-  #[default(Url::parse("http://pictrs:8080").expect("parse pictrs url"))]
-  #[doku(example = "Url::parse(\"http://pictrs:8080\").unwrap()")]
+  #[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
+  #[doku(example = "http://localhost:8080")]
   pub url: Url,
 
   /// Set a custom pictrs API key. ( Required for deleting images )
@@ -71,18 +62,48 @@ pub struct PictrsConfig {
 
 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
 #[serde(default)]
-pub struct CaptchaConfig {
-  /// Whether captcha is required for signup
-  #[default(false)]
-  pub enabled: bool,
-  /// Can be easy, medium, or hard
-  #[default("medium")]
-  pub difficulty: String,
+pub struct DatabaseConfig {
+  #[serde(flatten, default)]
+  pub connection: DatabaseConnection,
+
+  /// Maximum number of active sql connections
+  #[default(5)]
+  pub pool_size: usize,
+}
+
+#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
+#[serde(untagged)]
+pub enum DatabaseConnection {
+  /// Configure the database by specifying a URI
+  ///
+  /// This is the preferred method to specify database connection details since
+  /// it is the most flexible.
+  Uri {
+    /// Connection URI pointing to a postgres instance
+    ///
+    /// This example uses peer authentication to obviate the need for creating,
+    /// configuring, and managing passwords.
+    ///
+    /// For an explanation of how to use connection URIs, see [here][0] in
+    /// PostgreSQL's documentation.
+    ///
+    /// [0]: https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6
+    #[doku(example = "postgresql:///lemmy?user=lemmy&host=/var/run/postgresql")]
+    uri: String,
+  },
+
+  /// Configure the database by specifying parts of a URI
+  ///
+  /// Note that specifying the `uri` field should be preferred since it provides
+  /// greater control over how the connection is made. This merely exists for
+  /// backwards-compatibility.
+  #[default]
+  Parts(DatabaseConnectionParts),
 }
 
 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
 #[serde(default)]
-pub struct DatabaseConfig {
+pub struct DatabaseConnectionParts {
   /// Username to connect to postgres
   #[default("lemmy")]
   pub(super) user: String,
@@ -98,12 +119,10 @@ pub struct DatabaseConfig {
   /// Name of the postgres database for lemmy
   #[default("lemmy")]
   pub(super) database: String,
-  /// Maximum number of active sql connections
-  #[default(5)]
-  pub pool_size: u32,
 }
 
 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
+#[serde(deny_unknown_fields)]
 pub struct EmailConfig {
   /// Hostname and port of the smtp server
   #[doku(example = "localhost:25")]
@@ -122,82 +141,7 @@ pub struct EmailConfig {
 }
 
 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
-#[serde(default)]
-pub struct FederationConfig {
-  /// Whether to enable activitypub federation.
-  #[default(false)]
-  pub enabled: bool,
-  /// Allows and blocks are described here:
-  /// https://join-lemmy.org/docs/en/administration/federation_getting_started.html
-  ///
-  /// list of instances with which federation is allowed
-  #[default(None)]
-  #[doku(example = "instance1.tld")]
-  #[doku(example = "instance2.tld")]
-  pub allowed_instances: Option<Vec<String>>,
-  /// Instances which we never federate anything with (but previously federated objects are unaffected)
-  #[default(None)]
-  pub blocked_instances: Option<Vec<String>>,
-  /// If true, only federate with instances on the allowlist and block everything else. If false,
-  /// use allowlist only for remote communities, and posts/comments in local communities
-  /// (meaning remote communities will show content from arbitrary instances).
-  #[default(true)]
-  pub strict_allowlist: bool,
-  /// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search).
-  #[default(25)]
-  pub http_fetch_retry_limit: i32,
-  /// Number of workers for sending outgoing activities. Search logs for "Activity queue stats" to
-  /// see information. If "running" number is consistently close to the worker_count, you should
-  /// increase it.
-  #[default(64)]
-  pub worker_count: u64,
-  /// Use federation debug mode. Allows connecting to http and localhost urls. Also sends outgoing
-  /// activities synchronously for easier testing. Do not use in production.
-  #[default(false)]
-  pub debug: bool,
-}
-
-#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
-#[serde(default)]
-pub struct RateLimitConfig {
-  /// Maximum number of messages created in interval
-  #[default(180)]
-  pub message: i32,
-  /// Interval length for message limit, in seconds
-  #[default(60)]
-  pub message_per_second: i32,
-  /// Maximum number of posts created in interval
-  #[default(6)]
-  pub post: i32,
-  /// Interval length for post limit, in seconds
-  #[default(600)]
-  pub post_per_second: i32,
-  /// Maximum number of registrations in interval
-  #[default(3)]
-  pub register: i32,
-  /// Interval length for registration limit, in seconds
-  #[default(3600)]
-  pub register_per_second: i32,
-  /// Maximum number of image uploads in interval
-  #[default(6)]
-  pub image: i32,
-  /// Interval length for image uploads, in seconds
-  #[default(3600)]
-  pub image_per_second: i32,
-  /// Maximum number of comments created in interval
-  #[default(6)]
-  pub comment: i32,
-  /// Interval length for comment limit, in seconds
-  #[default(600)]
-  pub comment_per_second: i32,
-  #[default(6)]
-  pub search: i32,
-  /// Interval length for search limit, in seconds
-  #[default(600)]
-  pub search_per_second: i32,
-}
-
-#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
+#[serde(deny_unknown_fields)]
 pub struct SetupConfig {
   /// Username for the admin user
   #[doku(example = "admin")]