liminal-server 0.27.1

Standalone server for the liminal messaging bus
Documentation
//! Where an exchange's service templates are read from (ACCESS-012 R1).

use crate::services::lifecycle::templates::TemplateSources;

impl super::ServerConfig {
    /// The templates services are created from: the top-level `[[templates]]`
    /// when any are written there, else `[[auth.lys.templates]]`, else none
    /// (ACCESS-012 R1). Validation refuses both places at once, so there is
    /// one answer.
    #[must_use]
    pub fn template_sources(&self) -> &TemplateSources {
        if !self.templates.is_empty() {
            return &self.templates;
        }
        self.auth
            .as_ref()
            .and_then(|auth| auth.lys.as_ref())
            .map_or(&self.templates, |lys| &lys.templates)
    }

    /// The configuration place [`Self::template_sources`] answers from, for a
    /// refusal to name: `templates` or `auth.lys.templates`.
    #[must_use]
    pub fn templates_place(&self) -> &'static str {
        if self.templates.is_empty() && self.auth.as_ref().is_some_and(|auth| auth.lys.is_some()) {
            "auth.lys.templates"
        } else {
            "templates"
        }
    }
}