Split settings into multiple files

This commit is contained in:
Felix Ableitner 2021-02-19 13:23:23 +01:00
parent 1a02ab3482
commit f83b5590c7
30 changed files with 189 additions and 172 deletions

View file

@ -19,7 +19,13 @@ use lemmy_db_views_actor::{
community_view::CommunityView, community_view::CommunityView,
}; };
use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*, websocket::*}; use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*, websocket::*};
use lemmy_utils::{claims::Claims, settings::Settings, APIError, ConnectionId, LemmyError}; use lemmy_utils::{
claims::Claims,
settings::structs::Settings,
APIError,
ConnectionId,
LemmyError,
};
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation}; use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
use serde::Deserialize; use serde::Deserialize;
use std::process::Command; use std::process::Command;

View file

@ -48,7 +48,7 @@ use lemmy_db_views_moderator::{
use lemmy_structs::{blocking, site::*, user::Register}; use lemmy_structs::{blocking, site::*, user::Register};
use lemmy_utils::{ use lemmy_utils::{
location_info, location_info,
settings::Settings, settings::structs::Settings,
utils::{check_slurs, check_slurs_opt}, utils::{check_slurs, check_slurs_opt},
version, version,
APIError, APIError,

View file

@ -71,7 +71,7 @@ use lemmy_utils::{
claims::Claims, claims::Claims,
email::send_email, email::send_email,
location_info, location_info,
settings::Settings, settings::structs::Settings,
utils::{ utils::{
check_slurs, check_slurs,
generate_random_string, generate_random_string,

View file

@ -31,7 +31,7 @@ use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post
use lemmy_structs::{blocking, WebFingerResponse}; use lemmy_structs::{blocking, WebFingerResponse};
use lemmy_utils::{ use lemmy_utils::{
request::{retry, RecvError}, request::{retry, RecvError},
settings::Settings, settings::structs::Settings,
utils::{scrape_text_for_mentions, MentionData}, utils::{scrape_text_for_mentions, MentionData},
LemmyError, LemmyError,
}; };

View file

@ -1,4 +1,4 @@
use lemmy_utils::settings::Settings; use lemmy_utils::settings::structs::Settings;
use url::{ParseError, Url}; use url::{ParseError, Url};
use uuid::Uuid; use uuid::Uuid;

View file

@ -22,7 +22,7 @@ use background_jobs::{
use itertools::Itertools; use itertools::Itertools;
use lemmy_db_queries::DbPool; use lemmy_db_queries::DbPool;
use lemmy_db_schema::source::{community::Community, user::User_}; use lemmy_db_schema::source::{community::Community, user::User_};
use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::{debug, warn}; use log::{debug, warn};
use reqwest::Client; use reqwest::Client;

View file

@ -35,7 +35,7 @@ use lemmy_db_schema::source::{
use lemmy_db_views::{comment_view::CommentView, post_view::PostView}; use lemmy_db_views::{comment_view::CommentView, post_view::PostView};
use lemmy_db_views_actor::{community_view::CommunityView, user_view::UserViewSafe}; use lemmy_db_views_actor::{community_view::CommunityView, user_view::UserViewSafe};
use lemmy_structs::{blocking, site::SearchResponse}; use lemmy_structs::{blocking, site::SearchResponse};
use lemmy_utils::{settings::Settings, LemmyError}; use lemmy_utils::{settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::debug; use log::debug;
use url::Url; use url::Url;

View file

@ -4,7 +4,7 @@ use http::StatusCode;
use lemmy_db_queries::source::activity::Activity_; use lemmy_db_queries::source::activity::Activity_;
use lemmy_db_schema::source::activity::Activity; use lemmy_db_schema::source::activity::Activity;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, LemmyError}; use lemmy_utils::{settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -19,7 +19,7 @@ use lemmy_db_queries::{
}; };
use lemmy_db_schema::source::{activity::Activity, community::Community, user::User_}; use lemmy_db_schema::source::{activity::Activity, community::Community, user::User_};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::Serialize; use serde::Serialize;
use std::fmt::Debug; use std::fmt::Debug;

View file

@ -34,7 +34,7 @@ use lemmy_db_schema::source::{
user::User_, user::User_,
}; };
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::Serialize; use serde::Serialize;
use std::net::IpAddr; use std::net::IpAddr;

View file

@ -15,7 +15,12 @@ use diesel::result::Error::NotFound;
use lemmy_db_queries::{ApubObject, Crud, DbPool}; use lemmy_db_queries::{ApubObject, Crud, DbPool};
use lemmy_db_schema::source::community::Community; use lemmy_db_schema::source::community::Community;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, utils::convert_datetime, LemmyError}; use lemmy_utils::{
location_info,
settings::structs::Settings,
utils::convert_datetime,
LemmyError,
};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;

View file

@ -26,7 +26,7 @@ use lemmy_db_schema::{
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{ use lemmy_utils::{
location_info, location_info,
settings::Settings, settings::structs::Settings,
utils::{check_slurs, check_slurs_opt, convert_datetime}, utils::{check_slurs, check_slurs_opt, convert_datetime},
LemmyError, LemmyError,
}; };

View file

@ -16,7 +16,7 @@ use crate::{
}; };
use actix_web::*; use actix_web::*;
use http_signature_normalization_actix::digest::middleware::VerifyDigest; use http_signature_normalization_actix::digest::middleware::VerifyDigest;
use lemmy_utils::settings::Settings; use lemmy_utils::settings::structs::Settings;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
static APUB_JSON_CONTENT_TYPE_LONG: &str = static APUB_JSON_CONTENT_TYPE_LONG: &str =

View file

@ -7,7 +7,7 @@ use lemmy_db_schema::{
source::user::{UserForm, UserSafeSettings, User_}, source::user::{UserForm, UserSafeSettings, User_},
Url, Url,
}; };
use lemmy_utils::settings::Settings; use lemmy_utils::settings::structs::Settings;
mod safe_type { mod safe_type {
use crate::ToSafe; use crate::ToSafe;

View file

@ -15,7 +15,12 @@ use lemmy_db_views::{
}; };
use lemmy_db_views_actor::user_mention_view::{UserMentionQueryBuilder, UserMentionView}; use lemmy_db_views_actor::user_mention_view::{UserMentionQueryBuilder, UserMentionView};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{claims::Claims, settings::Settings, utils::markdown_to_html, LemmyError}; use lemmy_utils::{
claims::Claims,
settings::structs::Settings,
utils::markdown_to_html,
LemmyError,
};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use rss::{ use rss::{
extension::dublincore::DublinCoreExtensionBuilder, extension::dublincore::DublinCoreExtensionBuilder,

View file

@ -1,7 +1,7 @@
use actix::clock::Duration; use actix::clock::Duration;
use actix_web::{body::BodyStream, http::StatusCode, *}; use actix_web::{body::BodyStream, http::StatusCode, *};
use awc::Client; use awc::Client;
use lemmy_utils::{claims::Claims, rate_limit::RateLimit, settings::Settings}; use lemmy_utils::{claims::Claims, rate_limit::RateLimit, settings::structs::Settings};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {

View file

@ -2,7 +2,7 @@ use actix_web::{body::Body, error::ErrorBadRequest, *};
use anyhow::anyhow; use anyhow::anyhow;
use lemmy_db_views::site_view::SiteView; use lemmy_db_views::site_view::SiteView;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, version, LemmyError}; use lemmy_utils::{settings::structs::Settings, version, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View file

@ -4,7 +4,7 @@ use lemmy_db_queries::source::{community::Community_, user::User};
use lemmy_db_schema::source::{community::Community, user::User_}; use lemmy_db_schema::source::{community::Community, user::User_};
use lemmy_structs::{blocking, WebFingerLink, WebFingerResponse}; use lemmy_structs::{blocking, WebFingerLink, WebFingerResponse};
use lemmy_utils::{ use lemmy_utils::{
settings::Settings, settings::structs::Settings,
LemmyError, LemmyError,
WEBFINGER_COMMUNITY_REGEX, WEBFINGER_COMMUNITY_REGEX,
WEBFINGER_USER_REGEX, WEBFINGER_USER_REGEX,

View file

@ -13,7 +13,7 @@ use lemmy_db_schema::source::{
user::User_, user::User_,
user_mention::{UserMention, UserMentionForm}, user_mention::{UserMention, UserMentionForm},
}; };
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError}; use lemmy_utils::{email::send_email, settings::structs::Settings, utils::MentionData, LemmyError};
use log::error; use log::error;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;

View file

@ -1,4 +1,4 @@
use crate::settings::Settings; use crate::settings::structs::Settings;
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,4 +1,4 @@
use crate::settings::Settings; use crate::settings::structs::Settings;
use lettre::{ use lettre::{
message::{header, Mailbox, MultiPart, SinglePart}, message::{header, Mailbox, MultiPart, SinglePart},
transport::smtp::{ transport::smtp::{

View file

@ -14,7 +14,7 @@ mod test;
pub mod utils; pub mod utils;
pub mod version; pub mod version;
use crate::settings::Settings; use crate::settings::structs::Settings;
use http::StatusCode; use http::StatusCode;
use regex::Regex; use regex::Regex;
use thiserror::Error; use thiserror::Error;

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
settings::{RateLimitConfig, Settings}, settings::structs::{RateLimitConfig, Settings},
utils::get_ip, utils::get_ip,
LemmyError, LemmyError,
}; };

View file

@ -1,4 +1,4 @@
use crate::{settings::Settings, LemmyError}; use crate::{settings::structs::Settings, LemmyError};
use anyhow::anyhow; use anyhow::anyhow;
use log::error; use log::error;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};

View file

@ -0,0 +1,69 @@
use crate::settings::structs::*;
use std::net::{IpAddr, Ipv4Addr};
impl Default for Settings {
fn default() -> Self {
Self {
database: Some(DatabaseConfig::default()),
rate_limit: Some(RateLimitConfig::default()),
federation: Some(FederationConfig::default()),
captcha: Some(CaptchaConfig::default()),
email: None,
setup: None,
hostname: None,
bind: Some(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))),
port: Some(8536),
tls_enabled: Some(true),
jwt_secret: Some("changeme".into()),
pictrs_url: Some("http://pictrs:8080".into()),
iframely_url: Some("http://iframely".into()),
}
}
}
impl Default for RateLimitConfig {
fn default() -> Self {
Self {
message: 180,
message_per_second: 60,
post: 6,
post_per_second: 600,
register: 3,
register_per_second: 3600,
image: 6,
image_per_second: 3600,
}
}
}
impl Default for CaptchaConfig {
fn default() -> Self {
Self {
enabled: true,
difficulty: "medium".into(),
}
}
}
impl Default for DatabaseConfig {
fn default() -> Self {
Self {
user: "lemmy".into(),
password: "password".into(),
host: "localhost".into(),
port: 5432,
database: "lemmy".into(),
pool_size: 5,
}
}
}
impl Default for FederationConfig {
fn default() -> Self {
Self {
enabled: false,
allowed_instances: Some("".into()),
blocked_instances: Some("".into()),
}
}
}

View file

@ -1,154 +1,14 @@
use crate::{location_info, LemmyError}; use crate::{location_info, settings::structs::Settings, LemmyError};
use anyhow::Context; use anyhow::Context;
use deser_hjson::from_str; use deser_hjson::from_str;
use merge::Merge; use merge::Merge;
use serde::Deserialize; use std::{env, fs, io::Error, sync::RwLock};
use std::{
env, pub mod defaults;
fs, pub mod structs;
io::Error,
net::{IpAddr, Ipv4Addr},
sync::RwLock,
};
static CONFIG_FILE: &str = "config/config.hjson"; static CONFIG_FILE: &str = "config/config.hjson";
#[derive(Debug, Deserialize, Clone, Merge)]
pub struct Settings {
pub setup: Option<Setup>,
pub database: Option<DatabaseConfig>,
pub hostname: Option<String>,
pub bind: Option<IpAddr>,
pub port: Option<u16>,
pub tls_enabled: Option<bool>,
pub jwt_secret: Option<String>,
pub pictrs_url: Option<String>,
pub iframely_url: Option<String>,
pub rate_limit: Option<RateLimitConfig>,
pub email: Option<EmailConfig>,
pub federation: Option<FederationConfig>,
pub captcha: Option<CaptchaConfig>,
}
impl Default for Settings {
fn default() -> Self {
Self {
database: Some(DatabaseConfig::default()),
rate_limit: Some(RateLimitConfig::default()),
federation: Some(FederationConfig::default()),
captcha: Some(CaptchaConfig::default()),
email: None,
setup: None,
hostname: None,
bind: Some(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))),
port: Some(8536),
tls_enabled: Some(true),
jwt_secret: Some("changeme".into()),
pictrs_url: Some("http://pictrs:8080".into()),
iframely_url: Some("http://iframely".into()),
}
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct Setup {
pub admin_username: String,
pub admin_password: String,
pub admin_email: Option<String>,
pub site_name: String,
}
#[derive(Debug, Deserialize, Clone)]
pub struct RateLimitConfig {
pub message: i32,
pub message_per_second: i32,
pub post: i32,
pub post_per_second: i32,
pub register: i32,
pub register_per_second: i32,
pub image: i32,
pub image_per_second: i32,
}
impl Default for RateLimitConfig {
fn default() -> Self {
Self {
message: 180,
message_per_second: 60,
post: 6,
post_per_second: 600,
register: 3,
register_per_second: 3600,
image: 6,
image_per_second: 3600,
}
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct EmailConfig {
pub smtp_server: String,
pub smtp_login: Option<String>,
pub smtp_password: Option<String>,
pub smtp_from_address: String,
pub use_tls: bool,
}
#[derive(Debug, Deserialize, Clone)]
pub struct CaptchaConfig {
pub enabled: bool,
pub difficulty: String,
}
impl Default for CaptchaConfig {
fn default() -> Self {
Self {
enabled: true,
difficulty: "medium".into(),
}
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct DatabaseConfig {
pub user: String,
pub password: String,
pub host: String,
pub port: i32,
pub database: String,
pub pool_size: u32,
}
impl Default for DatabaseConfig {
fn default() -> Self {
Self {
user: "lemmy".into(),
password: "password".into(),
host: "localhost".into(),
port: 5432,
database: "lemmy".into(),
pool_size: 5,
}
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct FederationConfig {
pub enabled: bool,
pub allowed_instances: Option<String>,
pub blocked_instances: Option<String>,
}
impl Default for FederationConfig {
fn default() -> Self {
Self {
enabled: false,
allowed_instances: Some("".into()),
blocked_instances: Some("".into()),
}
}
}
lazy_static! { lazy_static! {
static ref SETTINGS: RwLock<Settings> = RwLock::new(match Settings::init() { static ref SETTINGS: RwLock<Settings> = RwLock::new(match Settings::init() {
Ok(c) => c, Ok(c) => c,

View file

@ -0,0 +1,72 @@
use merge::Merge;
use serde::Deserialize;
use std::net::IpAddr;
#[derive(Debug, Deserialize, Clone, Merge)]
pub struct Settings {
pub setup: Option<Setup>,
pub database: Option<DatabaseConfig>,
pub hostname: Option<String>,
pub bind: Option<IpAddr>,
pub port: Option<u16>,
pub tls_enabled: Option<bool>,
pub jwt_secret: Option<String>,
pub pictrs_url: Option<String>,
pub iframely_url: Option<String>,
pub rate_limit: Option<RateLimitConfig>,
pub email: Option<EmailConfig>,
pub federation: Option<FederationConfig>,
pub captcha: Option<CaptchaConfig>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct Setup {
pub admin_username: String,
pub admin_password: String,
pub admin_email: Option<String>,
pub site_name: String,
}
#[derive(Debug, Deserialize, Clone)]
pub struct RateLimitConfig {
pub message: i32,
pub message_per_second: i32,
pub post: i32,
pub post_per_second: i32,
pub register: i32,
pub register_per_second: i32,
pub image: i32,
pub image_per_second: i32,
}
#[derive(Debug, Deserialize, Clone)]
pub struct EmailConfig {
pub smtp_server: String,
pub smtp_login: Option<String>,
pub smtp_password: Option<String>,
pub smtp_from_address: String,
pub use_tls: bool,
}
#[derive(Debug, Deserialize, Clone)]
pub struct CaptchaConfig {
pub enabled: bool,
pub difficulty: String,
}
#[derive(Debug, Deserialize, Clone)]
pub struct DatabaseConfig {
pub user: String,
pub password: String,
pub host: String,
pub port: i32,
pub database: String,
pub pool_size: u32,
}
#[derive(Debug, Deserialize, Clone)]
pub struct FederationConfig {
pub enabled: bool,
pub allowed_instances: Option<String>,
pub blocked_instances: Option<String>,
}

View file

@ -1,4 +1,4 @@
use crate::{settings::Settings, APIError}; use crate::{settings::structs::Settings, APIError};
use actix_web::dev::ConnectionInfo; use actix_web::dev::ConnectionInfo;
use chrono::{DateTime, FixedOffset, NaiveDateTime}; use chrono::{DateTime, FixedOffset, NaiveDateTime};
use itertools::Itertools; use itertools::Itertools;

View file

@ -24,7 +24,7 @@ use lemmy_db_schema::{
user::{UserForm, User_}, user::{UserForm, User_},
}, },
}; };
use lemmy_utils::{apub::generate_actor_keypair, settings::Settings, LemmyError}; use lemmy_utils::{apub::generate_actor_keypair, settings::structs::Settings, LemmyError};
use log::info; use log::info;
pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> { pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> {

View file

@ -15,7 +15,7 @@ use lemmy_server::{code_migrations::run_advanced_migrations, scheduled_tasks};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{ use lemmy_utils::{
rate_limit::{rate_limiter::RateLimiter, RateLimit}, rate_limit::{rate_limiter::RateLimiter, RateLimit},
settings::Settings, settings::structs::Settings,
LemmyError, LemmyError,
}; };
use lemmy_websocket::{chat_server::ChatServer, LemmyContext}; use lemmy_websocket::{chat_server::ChatServer, LemmyContext};