use crate::ServerError;
use crate::config::types::{SelfStreamsConfig, ServerConfig, ServiceProfile};
impl SelfStreamsConfig {
pub fn validate(&self) -> Result<(), ServerError> {
let mut errors = Vec::new();
collect_self_stream_bound_errors(self, &mut errors);
if errors.is_empty() {
Ok(())
} else {
Err(ServerError::ConfigValidation {
message: errors.join("; "),
})
}
}
}
fn collect_self_stream_bound_errors(config: &SelfStreamsConfig, errors: &mut Vec<String>) {
errors.extend(
[
("cost_rows", config.cost_rows),
("events_rows", config.events_rows),
]
.into_iter()
.filter(|(_, rows)| *rows == 0)
.map(|(name, _)| format!("services.self_streams.{name}: must be non-zero")),
);
}
pub(super) fn validate_services(config: &ServerConfig, errors: &mut Vec<String>) {
collect_self_stream_bound_errors(&config.services.self_streams, errors);
let profile = match config.services.profile() {
Ok(profile) => profile,
Err(error) => {
match error {
crate::ServerError::ConfigValidation { message } => errors.push(message),
other => errors.push(other.to_string()),
}
return;
}
};
if profile == ServiceProfile::WorkerFrontDoor {
errors.extend(worker_front_door_field_errors(config));
}
}
pub fn worker_front_door_field_errors(config: &ServerConfig) -> Vec<String> {
let mut errors = Vec::new();
if !config.channels.is_empty() {
errors.push(
"services.profile: \"worker-front-door\" builds no channels; remove the \
[[channels]] entries or use profile = \"full\""
.to_owned(),
);
}
if !config.routing_rules.is_empty() {
errors.push(
"services.profile: \"worker-front-door\" builds no channels to route between; \
remove the [[routing_rules]] entries or use profile = \"full\""
.to_owned(),
);
}
if config.persistence_path.is_some() {
errors.push(
"services.profile: \"worker-front-door\" builds no durable store; remove \
persistence_path or use profile = \"full\""
.to_owned(),
);
}
if config.cluster.is_some() {
errors.push(
"services.profile: \"worker-front-door\" builds no channel cluster; remove the \
[cluster] section or use profile = \"full\""
.to_owned(),
);
}
if config.participant.is_some() {
errors.push(
"services.profile: \"worker-front-door\" installs no participant service; remove \
the [participant] section or use profile = \"full\""
.to_owned(),
);
}
errors
}