File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed
Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1212use crate :: { env, uploaders:: Uploader , Env , Replica } ;
1313
1414pub struct Base {
15- pub ( super ) env : Env ,
15+ pub env : Env ,
1616 uploader : Uploader ,
1717}
1818
Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ use std::sync::Mutex;
33
44use crate :: util:: errors:: { server_error, AppResult } ;
55
6+ use crate :: config;
67use crate :: middleware:: log_request:: add_custom_metadata;
8+ use crate :: Env ;
79use lettre:: transport:: file:: FileTransport ;
810use lettre:: transport:: smtp:: authentication:: { Credentials , Mechanism } ;
911use lettre:: transport:: smtp:: SmtpTransport ;
@@ -18,7 +20,7 @@ pub struct Emails {
1820impl 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
You can’t perform that action at this time.
0 commit comments