@ -27,6 +27,9 @@ pub struct AppConfig {
// Captcha (Cloudflare Turnstile)
pub turnstile_secret_key : String ,
pub turnstile_site_key : String ,
// Generation
pub generation_timeout_secs : u64 ,
}
impl AppConfig {
@ -51,6 +54,12 @@ impl AppConfig {
let static_dir = env ::var ( "STATIC_DIR" )
. unwrap_or_else ( | _ | "../frontend/dist" . to_string ( ) ) ;
let generation_timeout_secs = env ::var ( "GENERATION_TIMEOUT_MINUTES" )
. unwrap_or_else ( | _ | "30" . to_string ( ) )
. parse ::< u64 > ( )
. map_err ( | _ | "GENERATION_TIMEOUT_MINUTES must be a valid positive integer" . to_string ( ) ) ?
* 60 ;
Ok ( Self {
database_url ,
master_encryption_key : Arc ::new ( master_encryption_key ) ,
@ -61,6 +70,7 @@ impl AppConfig {
email_from ,
turnstile_secret_key ,
turnstile_site_key ,
generation_timeout_secs ,
} )
}
@ -115,6 +125,7 @@ mod tests {
email_from : "test@example.com" . into ( ) ,
turnstile_secret_key : "0x4AAA" . into ( ) ,
turnstile_site_key : "0x4BBB" . into ( ) ,
generation_timeout_secs : 1800 ,
} ;
assert! ( config . validate ( ) . is_ok ( ) ) ;
}
@ -131,6 +142,7 @@ mod tests {
email_from : "test@example.com" . into ( ) ,
turnstile_secret_key : "0x4AAA" . into ( ) ,
turnstile_site_key : "0x4BBB" . into ( ) ,
generation_timeout_secs : 1800 ,
} ;
let err = config . validate ( ) . unwrap_err ( ) ;
assert! ( err . contains ( "MASTER_ENCRYPTION_KEY" ) ) ;
@ -148,6 +160,7 @@ mod tests {
email_from : "test@example.com" . into ( ) ,
turnstile_secret_key : "0x4AAA" . into ( ) ,
turnstile_site_key : "0x4BBB" . into ( ) ,
generation_timeout_secs : 1800 ,
} ;
let err = config . validate ( ) . unwrap_err ( ) ;
assert! ( err . contains ( "MASTER_ENCRYPTION_KEY" ) ) ;
@ -165,6 +178,7 @@ mod tests {
email_from : "test@example.com" . into ( ) ,
turnstile_secret_key : "0x4AAA" . into ( ) ,
turnstile_site_key : "0x4BBB" . into ( ) ,
generation_timeout_secs : 1800 ,
} ;
let err = config . validate ( ) . unwrap_err ( ) ;
assert! ( err . contains ( "APP_URL" ) ) ;
@ -182,6 +196,7 @@ mod tests {
email_from : "test@example.com" . into ( ) ,
turnstile_secret_key : "0x4AAA" . into ( ) ,
turnstile_site_key : "0x4BBB" . into ( ) ,
generation_timeout_secs : 1800 ,
} ;
let err = config . validate ( ) . unwrap_err ( ) ;
assert! ( err . contains ( "trailing slash" ) ) ;
@ -199,6 +214,7 @@ mod tests {
email_from : "test@example.com" . into ( ) ,
turnstile_secret_key : "0x4AAA" . into ( ) ,
turnstile_site_key : "0x4BBB" . into ( ) ,
generation_timeout_secs : 1800 ,
} ;
assert! ( config . is_secure ( ) ) ;