forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: [torrust#591] extract new types for SMTP server configuration
From: ```toml [mail] email_verification_enabled = false from = "[email protected]" password = "" port = 25 reply_to = "[email protected]" server = "" username = "" ``` To: ```toml [mail] email_verification_enabled = false from = "[email protected]" reply_to = "[email protected]" [mail.smtp] port = 25 server = "" [mail.smtp.credentials] password = "" username = "" ```
- Loading branch information
1 parent
cd8248a
commit 1bc00ce
Showing
15 changed files
with
188 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,18 +19,33 @@ use url::Url; | |
use crate::web::api::server::DynError; | ||
|
||
pub type Settings = v1::Settings; | ||
|
||
pub type Api = v1::api::Api; | ||
|
||
pub type Auth = v1::auth::Auth; | ||
pub type EmailOnSignup = v1::auth::EmailOnSignup; | ||
pub type SecretKey = v1::auth::SecretKey; | ||
pub type PasswordConstraints = v1::auth::PasswordConstraints; | ||
|
||
pub type Database = v1::database::Database; | ||
|
||
pub type ImageCache = v1::image_cache::ImageCache; | ||
|
||
pub type Mail = v1::mail::Mail; | ||
pub type Smtp = v1::mail::Smtp; | ||
pub type Credentials = v1::mail::Credentials; | ||
|
||
pub type Network = v1::net::Network; | ||
|
||
pub type TrackerStatisticsImporter = v1::tracker_statistics_importer::TrackerStatisticsImporter; | ||
|
||
pub type Tracker = v1::tracker::Tracker; | ||
pub type ApiToken = v1::tracker::ApiToken; | ||
|
||
pub type Logging = v1::logging::Logging; | ||
pub type LogLevel = v1::logging::LogLevel; | ||
|
||
pub type Website = v1::website::Website; | ||
pub type EmailOnSignup = v1::auth::EmailOnSignup; | ||
pub type PasswordConstraints = v1::auth::PasswordConstraints; | ||
|
||
/// Prefix for env vars that overwrite configuration options. | ||
const CONFIG_OVERRIDE_PREFIX: &str = "TORRUST_INDEX_CONFIG_OVERRIDE_"; | ||
|
@@ -321,9 +336,7 @@ mod tests { | |
|
||
use url::Url; | ||
|
||
use crate::config::v1::auth::SecretKey; | ||
use crate::config::v1::tracker::ApiToken; | ||
use crate::config::{Configuration, ConfigurationPublic, Info, Settings}; | ||
use crate::config::{ApiToken, Configuration, ConfigurationPublic, Info, SecretKey, Settings}; | ||
|
||
#[cfg(test)] | ||
fn default_config_toml() -> String { | ||
|
@@ -358,10 +371,14 @@ mod tests { | |
email_verification_enabled = false | ||
from = "[email protected]" | ||
reply_to = "[email protected]" | ||
username = "" | ||
password = "" | ||
server = "" | ||
[mail.smtp] | ||
port = 25 | ||
server = "" | ||
[mail.smtp.credentials] | ||
password = "" | ||
username = "" | ||
[image_cache] | ||
max_request_timeout_ms = 1000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,18 +13,9 @@ pub struct Mail { | |
/// The email address to reply to. | ||
#[serde(default = "Mail::default_reply_to")] | ||
pub reply_to: Mailbox, | ||
/// The username to use for SMTP authentication. | ||
#[serde(default = "Mail::default_username")] | ||
pub username: String, | ||
/// The password to use for SMTP authentication. | ||
#[serde(default = "Mail::default_password")] | ||
pub password: String, | ||
/// The SMTP server to use. | ||
#[serde(default = "Mail::default_server")] | ||
pub server: String, | ||
/// The SMTP port to use. | ||
#[serde(default = "Mail::default_port")] | ||
pub port: u16, | ||
/// The SMTP server configuration. | ||
#[serde(default = "Mail::default_smtp")] | ||
pub smtp: Smtp, | ||
} | ||
|
||
impl Default for Mail { | ||
|
@@ -33,10 +24,7 @@ impl Default for Mail { | |
email_verification_enabled: Self::default_email_verification_enabled(), | ||
from: Self::default_from(), | ||
reply_to: Self::default_reply_to(), | ||
username: Self::default_username(), | ||
password: Self::default_password(), | ||
server: Self::default_server(), | ||
port: Self::default_port(), | ||
smtp: Self::default_smtp(), | ||
} | ||
} | ||
} | ||
|
@@ -54,19 +42,75 @@ impl Mail { | |
"[email protected]".parse().expect("valid mailbox") | ||
} | ||
|
||
fn default_username() -> String { | ||
String::default() | ||
fn default_smtp() -> Smtp { | ||
Smtp::default() | ||
} | ||
} | ||
|
||
fn default_password() -> String { | ||
String::default() | ||
/// SMTP configuration. | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
pub struct Smtp { | ||
/// The SMTP port to use. | ||
#[serde(default = "Smtp::default_port")] | ||
pub port: u16, | ||
/// The SMTP server to use. | ||
#[serde(default = "Smtp::default_server")] | ||
pub server: String, | ||
/// The SMTP server credentials. | ||
#[serde(default = "Smtp::default_credentials")] | ||
pub credentials: Credentials, | ||
} | ||
|
||
impl Default for Smtp { | ||
fn default() -> Self { | ||
Self { | ||
server: Self::default_server(), | ||
port: Self::default_port(), | ||
credentials: Self::default_credentials(), | ||
} | ||
} | ||
} | ||
|
||
impl Smtp { | ||
fn default_server() -> String { | ||
String::default() | ||
} | ||
|
||
fn default_port() -> u16 { | ||
25 | ||
} | ||
|
||
fn default_credentials() -> Credentials { | ||
Credentials::default() | ||
} | ||
} | ||
|
||
/// SMTP configuration. | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
pub struct Credentials { | ||
/// The password to use for SMTP authentication. | ||
#[serde(default = "Credentials::default_password")] | ||
pub password: String, | ||
/// The username to use for SMTP authentication. | ||
#[serde(default = "Credentials::default_username")] | ||
pub username: String, | ||
} | ||
|
||
impl Default for Credentials { | ||
fn default() -> Self { | ||
Self { | ||
username: Self::default_username(), | ||
password: Self::default_password(), | ||
} | ||
} | ||
} | ||
|
||
impl Credentials { | ||
fn default_username() -> String { | ||
String::default() | ||
} | ||
|
||
fn default_password() -> String { | ||
String::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,10 +194,14 @@ | |
//! email_verification_enabled = false | ||
//! from = "[email protected]" | ||
//! reply_to = "[email protected]" | ||
//! username = "" | ||
//! password = "" | ||
//! server = "" | ||
//! | ||
//! [mail.smtp] | ||
//! port = 25 | ||
//! server = "" | ||
//! | ||
//! [mail.smtp.credentials] | ||
//! password = "" | ||
//! username = "" | ||
//! | ||
//! [image_cache] | ||
//! max_request_timeout_ms = 1000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.