liminal-server 0.27.3

Standalone server for the liminal messaging bus
Documentation
//! ACCESS-012 R1: where templates may be written, and what each place needs.
//!
//! `[[templates]]` at the top level is the one place an open exchange (no
//! `[auth]`) can write the services it runs for its seats; a gated exchange
//! may write them there or under `[auth.lys]`, never both, so there is one
//! source of truth. The templates themselves are checked whole by
//! [`crate::config::templates`] from whichever place answers.

use crate::config::types::ServerConfig;

pub(super) fn validate_template_places(config: &ServerConfig, errors: &mut Vec<String>) {
    let lys = config.auth.as_ref().and_then(|auth| auth.lys.as_ref());
    if !config.templates.is_empty() && lys.is_some_and(|lys| !lys.templates.is_empty()) {
        errors.push(
            "templates are written once: at the top level or under [auth.lys], not both".to_owned(),
        );
    }
    if config.templates.is_empty() {
        return;
    }
    if config.auth.is_some() && lys.is_none() {
        errors.push(
            "templates: a gated exchange places services in Lys, write [auth.lys] or remove [auth]"
                .to_owned(),
        );
    }
    if config.auth.is_none() && config.templates.policy.is_some() {
        errors.push(
            "templates: roots and the record-template policy need [auth.lys.construction]; an \
             open exchange takes the template array only"
                .to_owned(),
        );
    }
}