dragonfly_client_rs/
app_config.rs1use std::sync::LazyLock;
2
3use figment::{
4 providers::{Env, Format, Serialized, Toml},
5 Figment,
6};
7use serde::{Deserialize, Serialize};
8
9#[derive(Serialize, Deserialize)]
10pub struct AppConfig {
11 pub base_url: String,
12 pub threads: usize,
13 pub load_duration: u64,
14 pub bulk_size: usize,
15 pub auth0_domain: String,
16 pub client_id: String,
17 pub client_secret: String,
18 pub audience: String,
19 pub grant_type: String,
20 pub username: String,
21 pub password: String,
22 pub max_scan_size: u64,
23}
24
25impl Default for AppConfig {
26 fn default() -> Self {
27 let available_parallelism = std::thread::available_parallelism()
28 .map(usize::from)
29 .unwrap_or(1);
30
31 #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
32 AppConfig {
33 base_url: String::from("https://dragonfly.vipyrsec.com"),
34 auth0_domain: String::from("vipyrsec.us.auth0.com"),
35 audience: String::from("https://dragonfly.vipyrsec.com"),
36 grant_type: String::from("password"),
37 client_id: String::new(),
38 client_secret: String::new(),
39 username: String::new(),
40 password: String::new(),
41 threads: available_parallelism,
42 bulk_size: 20,
43 load_duration: 60,
44 max_scan_size: 1.28e+8 as u64, }
46 }
47}
48
49impl AppConfig {
50 #[allow(clippy::result_large_err)]
51 pub fn build() -> Result<AppConfig, figment::Error> {
52 Figment::from(Serialized::defaults(AppConfig::default()))
53 .merge(Toml::file("Config.toml"))
54 .merge(Toml::file("Config-dev.toml"))
55 .merge(Env::prefixed("DRAGONFLY_"))
56 .extract()
57 }
58}
59
60pub static APP_CONFIG: LazyLock<AppConfig> = LazyLock::new(|| AppConfig::build().unwrap());