mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 13:20:42 +00:00
- Added initial implementation of the `pkg6depotd` server with modular components for CLI parsing, configuration management, HTTP handling, repository access, and daemonization. - Implemented basic server startup logic with a default router and placeholder handlers. - Integrated telemetry initialization and configuration fallback mechanism for ease of development. - Updated `Cargo.toml` and `Cargo.lock` to include dependencies necessary for server functionality.
87 lines
2.6 KiB
Rust
87 lines
2.6 KiB
Rust
use std::path::PathBuf;
|
|
use crate::errors::DepotError;
|
|
use std::fs;
|
|
|
|
#[derive(Debug, knuffel::Decode, Clone)]
|
|
pub struct Config {
|
|
#[knuffel(child)]
|
|
pub server: ServerConfig,
|
|
#[knuffel(child)]
|
|
pub repository: RepositoryConfig,
|
|
#[knuffel(child)]
|
|
pub telemetry: Option<TelemetryConfig>,
|
|
#[knuffel(child)]
|
|
pub publishers: Option<PublishersConfig>,
|
|
#[knuffel(child)]
|
|
pub admin: Option<AdminConfig>,
|
|
#[knuffel(child)]
|
|
pub oauth2: Option<Oauth2Config>,
|
|
}
|
|
|
|
#[derive(Debug, knuffel::Decode, Clone)]
|
|
pub struct ServerConfig {
|
|
#[knuffel(child, unwrap(arguments))]
|
|
pub bind: Vec<String>,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub workers: Option<usize>,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub max_connections: Option<usize>,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub reuseport: Option<bool>,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub tls_cert: Option<PathBuf>,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub tls_key: Option<PathBuf>,
|
|
}
|
|
|
|
#[derive(Debug, knuffel::Decode, Clone)]
|
|
pub struct RepositoryConfig {
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub root: PathBuf,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub mode: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, knuffel::Decode, Clone)]
|
|
pub struct TelemetryConfig {
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub otlp_endpoint: Option<String>,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub service_name: Option<String>,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub log_format: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, knuffel::Decode, Clone)]
|
|
pub struct PublishersConfig {
|
|
#[knuffel(child, unwrap(arguments))]
|
|
pub list: Vec<String>,
|
|
}
|
|
|
|
#[derive(Debug, knuffel::Decode, Clone)]
|
|
pub struct AdminConfig {
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub unix_socket: Option<PathBuf>,
|
|
}
|
|
|
|
#[derive(Debug, knuffel::Decode, Clone)]
|
|
pub struct Oauth2Config {
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub issuer: Option<String>,
|
|
#[knuffel(child, unwrap(argument))]
|
|
pub jwks_uri: Option<String>,
|
|
#[knuffel(child, unwrap(arguments))]
|
|
pub required_scopes: Option<Vec<String>>,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn load(path: Option<PathBuf>) -> crate::errors::Result<Self> {
|
|
let path = path.unwrap_or_else(|| PathBuf::from("pkg6depotd.kdl"));
|
|
|
|
let content = fs::read_to_string(&path)
|
|
.map_err(|e| DepotError::Config(format!("Failed to read config file {:?}: {}", path, e)))?;
|
|
|
|
knuffel::parse(path.to_str().unwrap_or("pkg6depotd.kdl"), &content)
|
|
.map_err(|e| DepotError::Config(format!("Failed to parse config: {:?}", e)))
|
|
}
|
|
}
|