use std::collections::HashMap;
use std::time::Duration;
pub const DEFAULT_POWER_PATH: &str = "/PowerControl/0/PowerConsumedWatts";
pub const MIN_SCRAPE_INTERVAL_SECS: u64 = 15;
pub const MAX_SCRAPE_INTERVAL_SECS: u64 = 3600;
#[derive(Clone)]
pub struct RedfishConfig {
pub endpoints: HashMap<String, String>,
pub scrape_interval: Duration,
pub service_mappings: HashMap<String, String>,
pub power_path: String,
pub ca_bundle_path: Option<String>,
pub auth_header: Option<String>,
}
impl std::fmt::Debug for RedfishConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RedfishConfig")
.field("endpoints", &self.endpoints)
.field("scrape_interval", &self.scrape_interval)
.field("service_mappings", &self.service_mappings)
.field("power_path", &self.power_path)
.field("ca_bundle_path", &self.ca_bundle_path)
.field(
"auth_header",
&self.auth_header.as_ref().map(|_| "[REDACTED]"),
)
.finish()
}
}
#[cfg(test)]
mod tests {
use super::*;
fn sample_config() -> RedfishConfig {
let mut endpoints = HashMap::new();
endpoints.insert(
"chassis-1".to_string(),
"https://bmc/redfish/v1/Chassis/1/Power".to_string(),
);
let mut mappings = HashMap::new();
mappings.insert("order-svc".to_string(), "chassis-1".to_string());
RedfishConfig {
endpoints,
scrape_interval: Duration::from_mins(1),
service_mappings: mappings,
power_path: DEFAULT_POWER_PATH.to_string(),
ca_bundle_path: None,
auth_header: Some("Authorization: Basic super-secret-do-not-log".to_string()),
}
}
#[test]
fn debug_impl_redacts_auth_header() {
let cfg = sample_config();
crate::test_helpers::assert_debug_redacts_secret!(&cfg, "super-secret-do-not-log");
}
#[test]
fn debug_impl_preserves_non_secret_fields() {
let cfg = sample_config();
let dbg = format!("{cfg:?}");
assert!(dbg.contains("chassis-1"));
assert!(dbg.contains("https://bmc/redfish/v1/Chassis/1/Power"));
assert!(dbg.contains("order-svc"));
assert!(dbg.contains("PowerConsumedWatts"));
}
}