use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum CacheType {
#[default]
Memory,
Sqlite,
Postgres,
}
impl std::str::FromStr for CacheType {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"memory" => Ok(Self::Memory),
"sqlite" => Ok(Self::Sqlite),
"postgres" => Ok(Self::Postgres),
_ => Err(()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum LogLevel {
Trace,
Debug,
#[default]
Info,
Warn,
Error,
}
impl std::str::FromStr for LogLevel {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"trace" => Ok(Self::Trace),
"debug" => Ok(Self::Debug),
"info" => Ok(Self::Info),
"warn" => Ok(Self::Warn),
"error" => Ok(Self::Error),
_ => Err(()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum LogFormat {
#[default]
Json,
Text,
}
impl std::str::FromStr for LogFormat {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"json" => Ok(Self::Json),
"text" => Ok(Self::Text),
_ => Err(()),
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct RdapConfig {
pub timeout_seconds: u64,
pub max_response_size_mb: u64,
pub user_agent: String,
pub bootstrap_refresh_hours: u64,
}
impl Default for RdapConfig {
fn default() -> Self {
Self {
timeout_seconds: 15,
max_response_size_mb: 5,
user_agent: "RDAPify/0.x".to_string(),
bootstrap_refresh_hours: 24,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct CacheConfig {
#[serde(rename = "type")]
pub backend: CacheType,
pub ttl_seconds: u64,
pub max_entries: u64,
}
impl Default for CacheConfig {
fn default() -> Self {
Self {
backend: CacheType::Memory,
ttl_seconds: 3600,
max_entries: 100_000,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct SqliteConfig {
pub path: String,
}
impl Default for SqliteConfig {
fn default() -> Self {
Self {
path: "~/.rdapify/cache.db".to_string(),
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct MonitoringConfig {
pub workers: u32,
pub interval_seconds: u64,
pub batch_size: u32,
}
impl Default for MonitoringConfig {
fn default() -> Self {
Self {
workers: 4,
interval_seconds: 300,
batch_size: 50,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct WebhookConfig {
pub workers: u32,
pub timeout_seconds: u64,
pub max_retries: u32,
}
impl Default for WebhookConfig {
fn default() -> Self {
Self {
workers: 2,
timeout_seconds: 10,
max_retries: 7,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct LicenseConfig {
pub path: String,
pub grace_days: u32,
pub revocation_check_hours: u64,
}
impl Default for LicenseConfig {
fn default() -> Self {
Self {
path: "~/.rdapify/activation.rdap".to_string(),
grace_days: 7,
revocation_check_hours: 24,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct LoggingConfig {
pub level: LogLevel,
pub format: LogFormat,
}
impl Default for LoggingConfig {
fn default() -> Self {
Self {
level: LogLevel::Info,
format: LogFormat::Json,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct MetricsConfig {
pub enabled: bool,
pub port: u16,
}
impl Default for MetricsConfig {
fn default() -> Self {
Self {
enabled: true,
port: 9090,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct ServerConfig {
pub host: String,
pub port: u16,
}
impl Default for ServerConfig {
fn default() -> Self {
Self {
host: "0.0.0.0".to_string(),
port: 8080,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(default)]
pub struct RdapifyConfig {
pub rdap: RdapConfig,
pub cache: CacheConfig,
pub sqlite: SqliteConfig,
pub monitoring: MonitoringConfig,
pub webhooks: WebhookConfig,
pub license: LicenseConfig,
pub logging: LoggingConfig,
pub metrics: MetricsConfig,
pub server: ServerConfig,
}