66 lines
1.8 KiB
Rust
66 lines
1.8 KiB
Rust
use anyhow::Result;
|
|
use envconfig::Envconfig;
|
|
use lazy_static::lazy_static;
|
|
use url::Url;
|
|
|
|
#[derive(Envconfig, Debug)]
|
|
pub struct Config {
|
|
#[envconfig(from = "BACKEND_DB_URL")]
|
|
pub db_url: String,
|
|
|
|
#[envconfig(from = "BACKEND_AMQP_URL")]
|
|
pub amqp_url: String,
|
|
|
|
#[envconfig(from = "BACKEND_REDIS_URL")]
|
|
pub redis_url: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_API_URL")]
|
|
pub untis_api_url: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_RPC_URL")]
|
|
pub untis_rpc_url: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_CLIENT_NAME")]
|
|
pub untis_client_name: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_SCHOOL")]
|
|
pub untis_school: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_USERNAME")]
|
|
pub untis_username: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_PASSWORD")]
|
|
pub untis_password: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_VPLAN_URL")]
|
|
pub untis_vplan_url: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_VPLAN_USERNAME")]
|
|
pub untis_vplan_username: String,
|
|
|
|
#[envconfig(from = "BACKEND_UNTIS_VPLAN_PASSWORD")]
|
|
pub untis_vplan_password: String,
|
|
}
|
|
|
|
lazy_static! {
|
|
pub static ref CONFIG: Config = Config::init_from_env().unwrap();
|
|
}
|
|
|
|
pub fn untis_from_env() -> Result<untis::Client> {
|
|
Ok(untis::Client {
|
|
// api_url: Url::parse(&CONFIG.untis_api_url)?,
|
|
webuntis_url: Url::parse(&CONFIG.untis_api_url)?,
|
|
rpc_url: untis::Client::gen_rpc_url(
|
|
&Url::parse(&CONFIG.untis_rpc_url)?,
|
|
&CONFIG.untis_school,
|
|
)?,
|
|
client_name: CONFIG.untis_client_name.to_owned(),
|
|
user_agent: "Mozilla/5.0 (Windows NT 10.0; rv:108.0) Gecko/20100101 Firefox/108.0"
|
|
.to_string(),
|
|
username: CONFIG.untis_username.to_owned(),
|
|
password: CONFIG.untis_password.to_owned(),
|
|
session: None,
|
|
authorization: None,
|
|
})
|
|
}
|