Skip to content

Commit b7a75f5

Browse files
committed
panic if non-smtp backends are used in productions
1 parent e59cfcd commit b7a75f5

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ impl App {
164164
read_only_replica_database: replica_database,
165165
github,
166166
github_oauth,
167-
config,
168167
version_id_cacher,
169168
downloads_counter: DownloadsCounter::new(),
170-
emails: Emails::from_environment(),
169+
emails: Emails::from_environment(&config),
171170
service_metrics: ServiceMetrics::new().expect("could not initialize service metrics"),
172171
instance_metrics,
173172
http_client,
173+
config,
174174
}
175175
}
176176

src/config/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use crate::{env, uploaders::Uploader, Env, Replica};
1313

1414
pub struct Base {
15-
pub(super) env: Env,
15+
pub env: Env,
1616
uploader: Uploader,
1717
}
1818

src/email.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::sync::Mutex;
33

44
use crate::util::errors::{server_error, AppResult};
55

6+
use crate::config;
67
use crate::middleware::log_request::add_custom_metadata;
8+
use crate::Env;
79
use lettre::transport::file::FileTransport;
810
use lettre::transport::smtp::authentication::{Credentials, Mechanism};
911
use lettre::transport::smtp::SmtpTransport;
@@ -18,7 +20,7 @@ pub struct Emails {
1820
impl Emails {
1921
/// Create a new instance detecting the backend from the environment. This will either connect
2022
/// to a SMTP server or store the emails on the local filesystem.
21-
pub fn from_environment() -> Self {
23+
pub fn from_environment(config: &config::Server) -> Self {
2224
let backend = match (
2325
dotenv::var("MAILGUN_SMTP_LOGIN"),
2426
dotenv::var("MAILGUN_SMTP_PASSWORD"),
@@ -34,6 +36,10 @@ impl Emails {
3436
},
3537
};
3638

39+
if config.base.env == Env::Production && !matches!(backend, EmailBackend::Smtp { .. }) {
40+
panic!("only the smtp backend is allowed in production");
41+
}
42+
3743
Self { backend }
3844
}
3945

0 commit comments

Comments
 (0)