1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::env;
#[derive(Debug, Default)]
pub struct EnvironmentConfig {
pub api_url: String,
pub app_name: String,
pub instance_id: String,
pub secret: Option<String>,
}
impl EnvironmentConfig {
pub fn from_env() -> Result<Self, Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut result = EnvironmentConfig::default();
let api_url = env::var("UNLEASH_API_URL");
if let Ok(api_url) = api_url {
result.api_url = api_url;
} else {
return Err(anyhow::anyhow!("UNLEASH_API_URL not set").into());
};
if let Ok(app_name) = env::var("UNLEASH_APP_NAME") {
result.app_name = app_name;
} else {
return Err(anyhow::anyhow!("UNLEASH_APP_NAME not set").into());
};
if let Ok(instance_id) = env::var("UNLEASH_INSTANCE_ID") {
result.instance_id = instance_id;
} else {
return Err(anyhow::anyhow!("UNLEASH_INSTANCE_ID not set").into());
};
result.secret = env::var("UNLEASH_CLIENT_SECRET").ok();
Ok(result)
}
}