kanidmd_core/repl/
config.rsuse kanidm_lib_crypto::prelude::X509;
use kanidm_lib_crypto::serialise::x509b64;
use kanidm_proto::constants::{
AUTH_TOKEN_GRACE_WINDOW, DEFAULT_REPLICATION_ADDRESS, DEFAULT_REPLICATION_ORIGIN,
DEFAULT_REPL_TASK_POLL_INTERVAL,
};
use serde::Deserialize;
use std::collections::BTreeMap;
use std::net::SocketAddr;
use std::str::FromStr;
use url::Url;
#[derive(Deserialize, Debug, Clone)]
#[serde(tag = "type")]
pub enum RepNodeConfig {
#[serde(rename = "allow-pull")]
AllowPull {
#[serde(with = "x509b64")]
consumer_cert: X509,
},
#[serde(rename = "pull")]
Pull {
#[serde(with = "x509b64")]
supplier_cert: X509,
#[serde(default)]
automatic_refresh: bool,
},
#[serde(rename = "mutual-pull")]
MutualPull {
#[serde(with = "x509b64")]
partner_cert: X509,
#[serde(default)]
automatic_refresh: bool,
},
}
#[derive(Deserialize, Debug, Clone)]
pub struct ReplicationConfiguration {
pub origin: Url,
pub bindaddress: SocketAddr,
pub task_poll_interval: Option<u64>,
#[serde(flatten)]
pub manual: BTreeMap<Url, RepNodeConfig>,
}
impl Default for ReplicationConfiguration {
fn default() -> Self {
#[allow(clippy::expect_used)]
let origin: Url = Url::from_str(DEFAULT_REPLICATION_ORIGIN)
.expect("Failed to parse default replication origin URL");
#[allow(clippy::expect_used)]
let bindaddress: SocketAddr = DEFAULT_REPLICATION_ADDRESS
.parse()
.expect("Failed to parse default replication bind address");
Self {
origin,
bindaddress,
task_poll_interval: None,
manual: BTreeMap::new(),
}
}
}
impl ReplicationConfiguration {
pub(crate) fn get_task_poll_interval(&self) -> core::time::Duration {
let config_poll = core::time::Duration::from_secs(
self.task_poll_interval
.unwrap_or(DEFAULT_REPL_TASK_POLL_INTERVAL),
);
if config_poll > AUTH_TOKEN_GRACE_WINDOW {
AUTH_TOKEN_GRACE_WINDOW
} else {
config_poll
}
}
}