From 35a125ef09fccaac68d7d5a9d3d3abf7174c7f9d Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 13 Jun 2024 16:32:18 +0100 Subject: [PATCH] refactor: [#591] order keys in config TOML files alphabetically We should produce always the same TOML file from the same configuration deterministically. --- src/config/mod.rs | 14 +++++++------- src/config/v1/api.rs | 1 + src/config/v1/auth.rs | 10 ++++++---- src/config/v1/image_cache.rs | 18 +++++++++++------- src/config/v1/mail.rs | 3 +++ src/config/v1/mod.rs | 9 +++++++++ src/config/v1/net.rs | 2 ++ src/config/v1/tracker.rs | 16 ++++++++++------ src/config/v1/tracker_statistics_importer.rs | 7 ++++--- 9 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 84c7681f..d0fbe7b2 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -347,11 +347,11 @@ mod tests { name = "Torrust" [tracker] - url = "udp://localhost:6969" - mode = "public" api_url = "http://localhost:1212/" + mode = "public" token = "MyAccessToken" token_valid_seconds = 7257600 + url = "udp://localhost:6969" [net] bind_address = "0.0.0.0:3001" @@ -361,9 +361,9 @@ mod tests { secret_key = "MaxVerstappenWC2021" [auth.password_constraints] - min_password_length = 6 max_password_length = 64 - + min_password_length = 6 + [database] connect_url = "sqlite://data.db?mode=rwc" @@ -381,19 +381,19 @@ mod tests { username = "" [image_cache] - max_request_timeout_ms = 1000 capacity = 128000000 entry_size_limit = 4000000 - user_quota_period_seconds = 3600 + max_request_timeout_ms = 1000 user_quota_bytes = 64000000 + user_quota_period_seconds = 3600 [api] default_torrent_page_size = 10 max_torrent_page_size = 30 [tracker_statistics_importer] - torrent_info_update_interval = 3600 port = 3002 + torrent_info_update_interval = 3600 "# .lines() .map(str::trim_start) diff --git a/src/config/v1/api.rs b/src/config/v1/api.rs index 4b4db9fd..678c52d7 100644 --- a/src/config/v1/api.rs +++ b/src/config/v1/api.rs @@ -6,6 +6,7 @@ pub struct Api { /// The default page size for torrent lists. #[serde(default = "Api::default_default_torrent_page_size")] pub default_torrent_page_size: u8, + /// The maximum page size for torrent lists. #[serde(default = "Api::default_max_torrent_page_size")] pub max_torrent_page_size: u8, diff --git a/src/config/v1/auth.rs b/src/config/v1/auth.rs index 007d3084..71147e4c 100644 --- a/src/config/v1/auth.rs +++ b/src/config/v1/auth.rs @@ -9,9 +9,11 @@ pub struct Auth { /// Whether or not to require an email on signup. #[serde(default = "Auth::default_email_on_signup")] pub email_on_signup: EmailOnSignup, + /// The secret key used to sign JWT tokens. #[serde(default = "Auth::default_secret_key")] pub secret_key: SecretKey, + /// The password constraints #[serde(default = "Auth::default_password_constraints")] pub password_constraints: PasswordConstraints, @@ -117,19 +119,19 @@ impl fmt::Display for SecretKey { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct PasswordConstraints { - /// The minimum password length. - #[serde(default = "PasswordConstraints::default_min_password_length")] - pub min_password_length: usize, /// The maximum password length. #[serde(default = "PasswordConstraints::default_max_password_length")] pub max_password_length: usize, + /// The minimum password length. + #[serde(default = "PasswordConstraints::default_min_password_length")] + pub min_password_length: usize, } impl Default for PasswordConstraints { fn default() -> Self { Self { - min_password_length: Self::default_min_password_length(), max_password_length: Self::default_max_password_length(), + min_password_length: Self::default_min_password_length(), } } } diff --git a/src/config/v1/image_cache.rs b/src/config/v1/image_cache.rs index 88c5ebec..6f9accf1 100644 --- a/src/config/v1/image_cache.rs +++ b/src/config/v1/image_cache.rs @@ -10,23 +10,27 @@ use serde::{Deserialize, Serialize}; #[allow(clippy::module_name_repetitions)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ImageCache { - /// Maximum time in seconds to wait for downloading the image form the original source. - #[serde(default = "ImageCache::default_max_request_timeout_ms")] - pub max_request_timeout_ms: u64, /// Cache size in bytes. #[serde(default = "ImageCache::default_capacity")] pub capacity: usize, + /// Maximum size in bytes for a single image. #[serde(default = "ImageCache::default_entry_size_limit")] pub entry_size_limit: usize, - /// Users have a cache quota per period. For example: 100MB per day. - /// This is the period in seconds (1 day in seconds). - #[serde(default = "ImageCache::default_user_quota_period_seconds")] - pub user_quota_period_seconds: u64, + + /// Maximum time in seconds to wait for downloading the image form the original source. + #[serde(default = "ImageCache::default_max_request_timeout_ms")] + pub max_request_timeout_ms: u64, + /// Users have a cache quota per period. For example: 100MB per day. /// This is the maximum size in bytes (100MB in bytes). #[serde(default = "ImageCache::default_user_quota_bytes")] pub user_quota_bytes: usize, + + /// Users have a cache quota per period. For example: 100MB per day. + /// This is the period in seconds (1 day in seconds). + #[serde(default = "ImageCache::default_user_quota_period_seconds")] + pub user_quota_period_seconds: u64, } impl Default for ImageCache { diff --git a/src/config/v1/mail.rs b/src/config/v1/mail.rs index 7675ceac..e171d41b 100644 --- a/src/config/v1/mail.rs +++ b/src/config/v1/mail.rs @@ -7,12 +7,15 @@ pub struct Mail { /// Whether or not to enable email verification on signup. #[serde(default = "Mail::default_email_verification_enabled")] pub email_verification_enabled: bool, + /// The email address to send emails from. #[serde(default = "Mail::default_from")] pub from: Mailbox, + /// The email address to reply to. #[serde(default = "Mail::default_reply_to")] pub reply_to: Mailbox, + /// The SMTP server configuration. #[serde(default = "Mail::default_smtp")] pub smtp: Smtp, diff --git a/src/config/v1/mod.rs b/src/config/v1/mod.rs index 1820c923..9e73d93e 100644 --- a/src/config/v1/mod.rs +++ b/src/config/v1/mod.rs @@ -29,30 +29,39 @@ pub struct Settings { /// The logging configuration. #[serde(default)] pub logging: Logging, + /// The website customizable values. #[serde(default)] pub website: Website, + /// The tracker configuration. #[serde(default)] pub tracker: Tracker, + /// The network configuration. #[serde(default)] pub net: Network, + /// The authentication configuration. #[serde(default)] pub auth: Auth, + /// The database configuration. #[serde(default)] pub database: Database, + /// The SMTP configuration. #[serde(default)] pub mail: Mail, + /// The image proxy cache configuration. #[serde(default)] pub image_cache: ImageCache, + /// The API configuration. #[serde(default)] pub api: Api, + /// The tracker statistics importer job configuration. #[serde(default)] pub tracker_statistics_importer: TrackerStatisticsImporter, diff --git a/src/config/v1/net.rs b/src/config/v1/net.rs index 3df9fc23..cb41c046 100644 --- a/src/config/v1/net.rs +++ b/src/config/v1/net.rs @@ -17,12 +17,14 @@ pub struct Network { /// If not set, the base URL will be inferred from the request. #[serde(default = "Network::default_base_url")] pub base_url: Option, + /// The address the tracker will bind to. /// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to /// listen to all interfaces, use `0.0.0.0`. If you want the operating /// system to choose a random port, use port `0`. #[serde(default = "Network::default_bind_address")] pub bind_address: SocketAddr, + /// TSL configuration. #[serde(default = "Network::default_tsl")] pub tsl: Option, diff --git a/src/config/v1/tracker.rs b/src/config/v1/tracker.rs index 67c31bfe..889e77ad 100644 --- a/src/config/v1/tracker.rs +++ b/src/config/v1/tracker.rs @@ -9,23 +9,27 @@ use crate::config::TrackerMode; /// Configuration for the associated tracker. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct Tracker { - /// Connection string for the tracker. For example: `udp://TRACKER_IP:6969`. - #[serde(default = "Tracker::default_url")] - pub url: Url, + /// The url of the tracker API. For example: `http://localhost:1212/`. + #[serde(default = "Tracker::default_api_url")] + pub api_url: Url, + /// The mode of the tracker. For example: `Public`. /// See `TrackerMode` in [`torrust-tracker-primitives`](https://docs.rs/torrust-tracker-primitives) /// crate for more information. #[serde(default = "Tracker::default_mode")] pub mode: TrackerMode, - /// The url of the tracker API. For example: `http://localhost:1212/`. - #[serde(default = "Tracker::default_api_url")] - pub api_url: Url, + /// The token used to authenticate with the tracker API. #[serde(default = "Tracker::default_token")] pub token: ApiToken, + /// The amount of seconds the tracker API token is valid. #[serde(default = "Tracker::default_token_valid_seconds")] pub token_valid_seconds: u64, + + /// Connection string for the tracker. For example: `udp://TRACKER_IP:6969`. + #[serde(default = "Tracker::default_url")] + pub url: Url, } impl Validator for Tracker { diff --git a/src/config/v1/tracker_statistics_importer.rs b/src/config/v1/tracker_statistics_importer.rs index 531629b1..c9d5c306 100644 --- a/src/config/v1/tracker_statistics_importer.rs +++ b/src/config/v1/tracker_statistics_importer.rs @@ -3,12 +3,13 @@ use serde::{Deserialize, Serialize}; /// Configuration for the tracker statistics importer. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct TrackerStatisticsImporter { - /// The interval in seconds to get statistics from the tracker. - #[serde(default = "TrackerStatisticsImporter::default_torrent_info_update_interval")] - pub torrent_info_update_interval: u64, /// The port the Importer API is listening on. Default to `3002`. #[serde(default = "TrackerStatisticsImporter::default_port")] pub port: u16, + + /// The interval in seconds to get statistics from the tracker. + #[serde(default = "TrackerStatisticsImporter::default_torrent_info_update_interval")] + pub torrent_info_update_interval: u64, } impl Default for TrackerStatisticsImporter {