Email client, application startup logic and tests
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::domain::SubscriberEmail;
|
||||
use secrecy::{ExposeSecret, SecretString};
|
||||
use serde::Deserialize;
|
||||
use serde_aux::field_attributes::deserialize_number_from_string;
|
||||
@@ -58,6 +59,7 @@ impl TryFrom<String> for Environment {
|
||||
pub struct Settings {
|
||||
pub application: ApplicationSettings,
|
||||
pub database: DatabaseSettings,
|
||||
pub email_client: EmailClientSettings,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -67,6 +69,35 @@ pub struct ApplicationSettings {
|
||||
pub host: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct EmailClientSettings {
|
||||
pub base_url: String,
|
||||
sender_email: String,
|
||||
pub authorization_token: SecretString,
|
||||
pub timeout_milliseconds: u64,
|
||||
}
|
||||
|
||||
impl EmailClientSettings {
|
||||
pub fn sender(&self) -> Result<SubscriberEmail, String> {
|
||||
SubscriberEmail::parse(self.sender_email.clone())
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
base_url: String,
|
||||
sender_email: String,
|
||||
authorization_token: String,
|
||||
timeout_milliseconds: u64,
|
||||
) -> Self {
|
||||
let authorization_token = SecretString::from(authorization_token);
|
||||
Self {
|
||||
base_url,
|
||||
sender_email,
|
||||
authorization_token,
|
||||
timeout_milliseconds,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct DatabaseSettings {
|
||||
pub username: String,
|
||||
|
||||
Reference in New Issue
Block a user