42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
use anyhow::Result;
|
|
use envconfig::Envconfig;
|
|
use lazy_static::lazy_static;
|
|
use url::Url;
|
|
|
|
#[derive(Envconfig, Debug)]
|
|
pub struct Config {
|
|
#[envconfig(from = "AUTH_UNTIS_URL")]
|
|
pub untis_url: String,
|
|
|
|
#[envconfig(from = "AUTH_UNTIS_CLIENT_NAME")]
|
|
pub untis_client_name: String,
|
|
|
|
#[envconfig(from = "AUTH_UNTIS_SCHOOL")]
|
|
pub untis_school: String,
|
|
|
|
#[envconfig(from = "AUTH_UNTIS_USERNAME")]
|
|
pub untis_username: String,
|
|
|
|
#[envconfig(from = "AUTH_UNTIS_PASSWORD")]
|
|
pub untis_password: String,
|
|
}
|
|
|
|
lazy_static! {
|
|
pub static ref CONFIG: Config = Config::init_from_env().unwrap();
|
|
}
|
|
|
|
pub fn untis_from_env() -> Result<untis::Client> {
|
|
let webuntis_url = Url::parse(&CONFIG.untis_url)?;
|
|
|
|
Ok(untis::Client {
|
|
rpc_url: untis::Client::gen_rpc_url(&webuntis_url, &CONFIG.untis_school)?,
|
|
webuntis_url,
|
|
client_name: CONFIG.untis_client_name.to_owned(),
|
|
user_agent: "".to_string(),
|
|
username: CONFIG.untis_username.to_owned(),
|
|
password: CONFIG.untis_password.to_owned(),
|
|
session: None,
|
|
authorization: None,
|
|
})
|
|
}
|