casdoor_sdk_rust/
config.rsuse std::{fs::File, io::Read};
use serde::{Deserialize, Serialize};
use openssl::{error::ErrorStack, pkey::{PKey, Public}, x509::X509};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub endpoint: String,
pub client_id: String,
pub client_secret: String,
pub certificate: String,
pub org_name: String,
pub app_name: Option<String>,
}
impl Config {
pub fn new(
endpoint: String,
client_id: String,
client_secret: String,
certificate: String,
org_name: String,
app_name: Option<String>,
) -> Self {
Config {
endpoint,
client_id,
client_secret,
certificate,
org_name,
app_name
}
}
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)?;
let conf: Config = toml::from_str(&content)?;
Ok(conf)
}
pub fn replace_cert_to_pub_key(&self) -> Result<PKey<Public>, ErrorStack> {
let cert_x509 = &X509::from_pem(self.certificate.as_bytes())?;
cert_x509.public_key()
}
}