Skip to content

Commit 35a125e

Browse files
committed
refactor: [#591] order keys in config TOML files alphabetically
We should produce always the same TOML file from the same configuration deterministically.
1 parent cb8935b commit 35a125e

File tree

9 files changed

+53
-27
lines changed

9 files changed

+53
-27
lines changed

src/config/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,11 @@ mod tests {
347347
name = "Torrust"
348348
349349
[tracker]
350-
url = "udp://localhost:6969"
351-
mode = "public"
352350
api_url = "http://localhost:1212/"
351+
mode = "public"
353352
token = "MyAccessToken"
354353
token_valid_seconds = 7257600
354+
url = "udp://localhost:6969"
355355
356356
[net]
357357
bind_address = "0.0.0.0:3001"
@@ -361,9 +361,9 @@ mod tests {
361361
secret_key = "MaxVerstappenWC2021"
362362
363363
[auth.password_constraints]
364-
min_password_length = 6
365364
max_password_length = 64
366-
365+
min_password_length = 6
366+
367367
[database]
368368
connect_url = "sqlite://data.db?mode=rwc"
369369
@@ -381,19 +381,19 @@ mod tests {
381381
username = ""
382382
383383
[image_cache]
384-
max_request_timeout_ms = 1000
385384
capacity = 128000000
386385
entry_size_limit = 4000000
387-
user_quota_period_seconds = 3600
386+
max_request_timeout_ms = 1000
388387
user_quota_bytes = 64000000
388+
user_quota_period_seconds = 3600
389389
390390
[api]
391391
default_torrent_page_size = 10
392392
max_torrent_page_size = 30
393393
394394
[tracker_statistics_importer]
395-
torrent_info_update_interval = 3600
396395
port = 3002
396+
torrent_info_update_interval = 3600
397397
"#
398398
.lines()
399399
.map(str::trim_start)

src/config/v1/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub struct Api {
66
/// The default page size for torrent lists.
77
#[serde(default = "Api::default_default_torrent_page_size")]
88
pub default_torrent_page_size: u8,
9+
910
/// The maximum page size for torrent lists.
1011
#[serde(default = "Api::default_max_torrent_page_size")]
1112
pub max_torrent_page_size: u8,

src/config/v1/auth.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ pub struct Auth {
99
/// Whether or not to require an email on signup.
1010
#[serde(default = "Auth::default_email_on_signup")]
1111
pub email_on_signup: EmailOnSignup,
12+
1213
/// The secret key used to sign JWT tokens.
1314
#[serde(default = "Auth::default_secret_key")]
1415
pub secret_key: SecretKey,
16+
1517
/// The password constraints
1618
#[serde(default = "Auth::default_password_constraints")]
1719
pub password_constraints: PasswordConstraints,
@@ -117,19 +119,19 @@ impl fmt::Display for SecretKey {
117119

118120
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
119121
pub struct PasswordConstraints {
120-
/// The minimum password length.
121-
#[serde(default = "PasswordConstraints::default_min_password_length")]
122-
pub min_password_length: usize,
123122
/// The maximum password length.
124123
#[serde(default = "PasswordConstraints::default_max_password_length")]
125124
pub max_password_length: usize,
125+
/// The minimum password length.
126+
#[serde(default = "PasswordConstraints::default_min_password_length")]
127+
pub min_password_length: usize,
126128
}
127129

128130
impl Default for PasswordConstraints {
129131
fn default() -> Self {
130132
Self {
131-
min_password_length: Self::default_min_password_length(),
132133
max_password_length: Self::default_max_password_length(),
134+
min_password_length: Self::default_min_password_length(),
133135
}
134136
}
135137
}

src/config/v1/image_cache.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@ use serde::{Deserialize, Serialize};
1010
#[allow(clippy::module_name_repetitions)]
1111
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1212
pub struct ImageCache {
13-
/// Maximum time in seconds to wait for downloading the image form the original source.
14-
#[serde(default = "ImageCache::default_max_request_timeout_ms")]
15-
pub max_request_timeout_ms: u64,
1613
/// Cache size in bytes.
1714
#[serde(default = "ImageCache::default_capacity")]
1815
pub capacity: usize,
16+
1917
/// Maximum size in bytes for a single image.
2018
#[serde(default = "ImageCache::default_entry_size_limit")]
2119
pub entry_size_limit: usize,
22-
/// Users have a cache quota per period. For example: 100MB per day.
23-
/// This is the period in seconds (1 day in seconds).
24-
#[serde(default = "ImageCache::default_user_quota_period_seconds")]
25-
pub user_quota_period_seconds: u64,
20+
21+
/// Maximum time in seconds to wait for downloading the image form the original source.
22+
#[serde(default = "ImageCache::default_max_request_timeout_ms")]
23+
pub max_request_timeout_ms: u64,
24+
2625
/// Users have a cache quota per period. For example: 100MB per day.
2726
/// This is the maximum size in bytes (100MB in bytes).
2827
#[serde(default = "ImageCache::default_user_quota_bytes")]
2928
pub user_quota_bytes: usize,
29+
30+
/// Users have a cache quota per period. For example: 100MB per day.
31+
/// This is the period in seconds (1 day in seconds).
32+
#[serde(default = "ImageCache::default_user_quota_period_seconds")]
33+
pub user_quota_period_seconds: u64,
3034
}
3135

3236
impl Default for ImageCache {

src/config/v1/mail.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ pub struct Mail {
77
/// Whether or not to enable email verification on signup.
88
#[serde(default = "Mail::default_email_verification_enabled")]
99
pub email_verification_enabled: bool,
10+
1011
/// The email address to send emails from.
1112
#[serde(default = "Mail::default_from")]
1213
pub from: Mailbox,
14+
1315
/// The email address to reply to.
1416
#[serde(default = "Mail::default_reply_to")]
1517
pub reply_to: Mailbox,
18+
1619
/// The SMTP server configuration.
1720
#[serde(default = "Mail::default_smtp")]
1821
pub smtp: Smtp,

src/config/v1/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,39 @@ pub struct Settings {
2929
/// The logging configuration.
3030
#[serde(default)]
3131
pub logging: Logging,
32+
3233
/// The website customizable values.
3334
#[serde(default)]
3435
pub website: Website,
36+
3537
/// The tracker configuration.
3638
#[serde(default)]
3739
pub tracker: Tracker,
40+
3841
/// The network configuration.
3942
#[serde(default)]
4043
pub net: Network,
44+
4145
/// The authentication configuration.
4246
#[serde(default)]
4347
pub auth: Auth,
48+
4449
/// The database configuration.
4550
#[serde(default)]
4651
pub database: Database,
52+
4753
/// The SMTP configuration.
4854
#[serde(default)]
4955
pub mail: Mail,
56+
5057
/// The image proxy cache configuration.
5158
#[serde(default)]
5259
pub image_cache: ImageCache,
60+
5361
/// The API configuration.
5462
#[serde(default)]
5563
pub api: Api,
64+
5665
/// The tracker statistics importer job configuration.
5766
#[serde(default)]
5867
pub tracker_statistics_importer: TrackerStatisticsImporter,

src/config/v1/net.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ pub struct Network {
1717
/// If not set, the base URL will be inferred from the request.
1818
#[serde(default = "Network::default_base_url")]
1919
pub base_url: Option<Url>,
20+
2021
/// The address the tracker will bind to.
2122
/// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to
2223
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
2324
/// system to choose a random port, use port `0`.
2425
#[serde(default = "Network::default_bind_address")]
2526
pub bind_address: SocketAddr,
27+
2628
/// TSL configuration.
2729
#[serde(default = "Network::default_tsl")]
2830
pub tsl: Option<Tsl>,

src/config/v1/tracker.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,27 @@ use crate::config::TrackerMode;
99
/// Configuration for the associated tracker.
1010
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1111
pub struct Tracker {
12-
/// Connection string for the tracker. For example: `udp://TRACKER_IP:6969`.
13-
#[serde(default = "Tracker::default_url")]
14-
pub url: Url,
12+
/// The url of the tracker API. For example: `http://localhost:1212/`.
13+
#[serde(default = "Tracker::default_api_url")]
14+
pub api_url: Url,
15+
1516
/// The mode of the tracker. For example: `Public`.
1617
/// See `TrackerMode` in [`torrust-tracker-primitives`](https://docs.rs/torrust-tracker-primitives)
1718
/// crate for more information.
1819
#[serde(default = "Tracker::default_mode")]
1920
pub mode: TrackerMode,
20-
/// The url of the tracker API. For example: `http://localhost:1212/`.
21-
#[serde(default = "Tracker::default_api_url")]
22-
pub api_url: Url,
21+
2322
/// The token used to authenticate with the tracker API.
2423
#[serde(default = "Tracker::default_token")]
2524
pub token: ApiToken,
25+
2626
/// The amount of seconds the tracker API token is valid.
2727
#[serde(default = "Tracker::default_token_valid_seconds")]
2828
pub token_valid_seconds: u64,
29+
30+
/// Connection string for the tracker. For example: `udp://TRACKER_IP:6969`.
31+
#[serde(default = "Tracker::default_url")]
32+
pub url: Url,
2933
}
3034

3135
impl Validator for Tracker {

src/config/v1/tracker_statistics_importer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use serde::{Deserialize, Serialize};
33
/// Configuration for the tracker statistics importer.
44
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
55
pub struct TrackerStatisticsImporter {
6-
/// The interval in seconds to get statistics from the tracker.
7-
#[serde(default = "TrackerStatisticsImporter::default_torrent_info_update_interval")]
8-
pub torrent_info_update_interval: u64,
96
/// The port the Importer API is listening on. Default to `3002`.
107
#[serde(default = "TrackerStatisticsImporter::default_port")]
118
pub port: u16,
9+
10+
/// The interval in seconds to get statistics from the tracker.
11+
#[serde(default = "TrackerStatisticsImporter::default_torrent_info_update_interval")]
12+
pub torrent_info_update_interval: u64,
1213
}
1314

1415
impl Default for TrackerStatisticsImporter {

0 commit comments

Comments
 (0)