Add IP location service
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -27,9 +27,35 @@ pub struct AppConfig {
|
||||
/// Proxy IP, might end with a star "*"
|
||||
#[clap(short, long, env)]
|
||||
pub proxy_ip: Option<String>,
|
||||
|
||||
/// IP location service API
|
||||
///
|
||||
/// Up instance of IP location service : https://gitlab.com/pierre42100/iplocationserver
|
||||
///
|
||||
/// Example: "https://api.geoip.rs"
|
||||
#[arg(long, short, env)]
|
||||
pub ip_location_service: Option<String>,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref ARGS: AppConfig = {
|
||||
let mut config = AppConfig::parse();
|
||||
|
||||
// In debug mode only, use dummy token
|
||||
if cfg!(debug_assertions) && config.token_key.is_empty() {
|
||||
config.token_key = String::from_utf8_lossy(&[32; 64]).to_string();
|
||||
}
|
||||
|
||||
config
|
||||
};
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
/// Get parsed command line arguments
|
||||
pub fn get() -> &'static AppConfig {
|
||||
&ARGS
|
||||
}
|
||||
|
||||
pub fn secure_cookie(&self) -> bool {
|
||||
self.website_origin.starts_with("https:")
|
||||
}
|
||||
@ -58,3 +84,14 @@ impl AppConfig {
|
||||
self.website_origin.split('/').nth(2).unwrap_or(APP_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::data::app_config::AppConfig;
|
||||
|
||||
#[test]
|
||||
fn verify_cli() {
|
||||
use clap::CommandFactory;
|
||||
AppConfig::command().debug_assert()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user