Skip to main content

burn_central_client/
credentials.rs

1use serde::Serialize;
2use std::str::FromStr;
3
4/// Credentials to connect to the Burn Central server
5#[derive(Serialize, Debug, Clone)]
6pub struct BurnCentralCredentials {
7    api_key: String,
8}
9
10impl BurnCentralCredentials {
11    pub fn new(api_key: impl Into<String>) -> Self {
12        Self {
13            api_key: api_key.into(),
14        }
15    }
16
17    /// Creates a new instance of `BurnCentralCredentials` from environment variables.
18    pub fn from_env() -> Result<Self, std::env::VarError> {
19        let api_key = std::env::var("BURN_CENTRAL_API_KEY")?;
20        Ok(Self::new(api_key))
21    }
22}
23
24impl FromStr for BurnCentralCredentials {
25    type Err = String;
26
27    fn from_str(s: &str) -> Result<Self, Self::Err> {
28        if s.is_empty() {
29            Err("API key cannot be empty".to_string())
30        } else {
31            Ok(Self::new(s))
32        }
33    }
34}