use serde_derive::Deserialize;
use std::{fs::File, io::Read};
#[derive(Debug, Clone, Deserialize)]
pub struct CasdoorConfig {
pub(crate) endpoint: String,
pub(crate) client_id: String,
pub(crate) client_secret: String,
pub(crate) jwt_pub_key: String,
pub(crate) org_name: String,
pub(crate) app_name: Option<String>,
}
impl CasdoorConfig {
#[allow(dead_code)]
pub fn new(
endpoint: String,
client_id: String,
client_secret: String,
jwt_pub_key: String,
org_name: String,
app_name: Option<String>,
) -> Self {
CasdoorConfig {
endpoint,
client_id,
client_secret,
jwt_pub_key,
org_name,
app_name,
}
}
#[allow(dead_code)]
pub fn from_toml(path: &str) -> Result<Self, Box<dyn std::error::Error>> {
let mut file = File::open(path)?;
let mut content = String::new();
file.read_to_string(&mut content)?;
Ok(toml::from_str(&content)?)
}
}