- Add nixos_config_api_key_file option to NixOS configuration - Support reading API token from file for private repositories - Automatically inject token into HTTPS URLs (https://token@host/repo.git) - Graceful fallback to original URL if key file missing/empty - Default key file location: /var/lib/cm-dashboard/git-api-key Usage: echo 'your-api-token' | sudo tee /var/lib/cm-dashboard/git-api-key
60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
use anyhow::Result;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::path::Path;
|
|
|
|
/// Main dashboard configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct DashboardConfig {
|
|
pub zmq: ZmqConfig,
|
|
pub hosts: HostsConfig,
|
|
pub system: SystemConfig,
|
|
}
|
|
|
|
/// ZMQ consumer configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ZmqConfig {
|
|
pub subscriber_ports: Vec<u16>,
|
|
}
|
|
|
|
/// Hosts configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct HostsConfig {
|
|
pub predefined_hosts: Vec<String>,
|
|
}
|
|
|
|
/// System configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct SystemConfig {
|
|
pub nixos_config_git_url: String,
|
|
pub nixos_config_branch: String,
|
|
pub nixos_config_working_dir: String,
|
|
pub nixos_config_api_key_file: Option<String>,
|
|
}
|
|
|
|
impl DashboardConfig {
|
|
pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
|
|
let path = path.as_ref();
|
|
let content = std::fs::read_to_string(path)?;
|
|
let config: DashboardConfig = toml::from_str(&content)?;
|
|
Ok(config)
|
|
}
|
|
}
|
|
|
|
impl Default for DashboardConfig {
|
|
fn default() -> Self {
|
|
panic!("Dashboard configuration must be loaded from file - no hardcoded defaults allowed")
|
|
}
|
|
}
|
|
|
|
impl Default for ZmqConfig {
|
|
fn default() -> Self {
|
|
panic!("Dashboard configuration must be loaded from file - no hardcoded defaults allowed")
|
|
}
|
|
}
|
|
|
|
impl Default for HostsConfig {
|
|
fn default() -> Self {
|
|
panic!("Dashboard configuration must be loaded from file - no hardcoded defaults allowed")
|
|
}
|
|
}
|