parse redis ssl_context

This commit is contained in:
Robin Appelman 2025-04-29 18:13:10 +02:00
commit e4bb72fd00
6 changed files with 220 additions and 14 deletions

View file

@ -31,14 +31,41 @@ pub enum RedisConnectionAddr {
TcpTls {
host: String,
port: u16,
insecure: bool,
tls_params: Option<String>,
tls_params: Option<RedisTlsParams>,
},
Unix {
path: PathBuf,
},
}
impl RedisConnectionAddr {
pub fn with_tls(self, tls_params: RedisTlsParams) -> Self {
match self {
RedisConnectionAddr::Tcp { host, port }
| RedisConnectionAddr::TcpTls { host, port, .. } => RedisConnectionAddr::TcpTls {
host,
port,
tls_params: Some(tls_params),
},
unix => unix,
}
}
pub fn with_tls_opt(self, tls_params: Option<RedisTlsParams>) -> Self {
if let Some(params) = tls_params {
self.with_tls(params)
} else {
match self {
RedisConnectionAddr::Tcp { host, port }
| RedisConnectionAddr::TcpTls { host, port, .. } => {
RedisConnectionAddr::Tcp { host, port }
}
unix => unix,
}
}
}
}
#[derive(Clone, Debug)]
pub struct RedisConnectionInfo {
pub addr: RedisConnectionAddr,
@ -47,6 +74,15 @@ pub struct RedisConnectionInfo {
pub password: Option<String>,
}
#[derive(Clone, Debug)]
pub struct RedisTlsParams {
pub local_cert: Option<PathBuf>,
pub local_pk: Option<PathBuf>,
pub ca_file: Option<PathBuf>,
pub accept_invalid_hostname: bool,
pub insecure: bool,
}
impl RedisConfig {
pub fn addr(&self) -> impl Iterator<Item = &RedisConnectionAddr> {
let boxed: Box<dyn Iterator<Item = &RedisConnectionAddr>> = match self {