25 lines
708 B
Rust
25 lines
708 B
Rust
use std::env;
|
|
|
|
#[derive(Clone)]
|
|
pub struct Config {
|
|
pub username: String,
|
|
pub password: String,
|
|
pub api_url: String,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from_env() -> Result<Self, String> {
|
|
let username = env::var("HETZNER_USERNAME")
|
|
.map_err(|_| "HETZNER_USERNAME environment variable not set".to_string())?;
|
|
let password = env::var("HETZNER_PASSWORD")
|
|
.map_err(|_| "HETZNER_PASSWORD environment variable not set".to_string())?;
|
|
let api_url = env::var("HETZNER_API_URL")
|
|
.unwrap_or_else(|_| "https://robot-ws.your-server.de".to_string());
|
|
|
|
Ok(Config {
|
|
username,
|
|
password,
|
|
api_url,
|
|
})
|
|
}
|
|
} |