diff --git a/src/server/config.rs b/src/server/config.rs index 814d2d7..78c6272 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -78,10 +78,64 @@ impl DatabaseConnectionConfig { } } +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +enum KeyValStoreConnectionConfig { + FromUrl { + url: String, + }, + FromParts { + scheme: Option, + host: String, + port: Option, + database: Option, + username: Option, + password: Option, + }, +} + +impl KeyValStoreConnectionConfig { + /// Convert this configuration into the Redis connection URI + pub fn as_uri(&self) -> String { + match self { + Self::FromUrl { url } => url.clone(), + Self::FromParts { + scheme, + host, + port, + database, + username, + password, + } => format_uri( + scheme.as_deref().unwrap_or("redis"), + username, + password, + host, + port, + database, + ), + } + } +} + +#[derive(Debug, Clone, Deserialize)] +pub struct KeyValStoreConfig { + #[serde(flatten)] + connection: KeyValStoreConnectionConfig, +} + +impl KeyValStoreConfig { + /// Get the configured database connection URI + pub fn connection_uri(&self) -> String { + self.connection.as_uri() + } +} + #[derive(Debug, Clone, Deserialize)] /// Top-level application configuration pub struct Config { pub database: DatabaseConfig, + pub key_val_store: KeyValStoreConfig, } /// Parse configuration from the expected files and environment variables