Skip to main content

liminal_server/config/types/
templates.rs

1//! Where an exchange's service templates are read from (ACCESS-012 R1).
2
3use crate::services::lifecycle::templates::TemplateSources;
4
5impl super::ServerConfig {
6    /// The templates services are created from: the top-level `[[templates]]`
7    /// when any are written there, else `[[auth.lys.templates]]`, else none
8    /// (ACCESS-012 R1). Validation refuses both places at once, so there is
9    /// one answer.
10    #[must_use]
11    pub fn template_sources(&self) -> &TemplateSources {
12        if !self.templates.is_empty() {
13            return &self.templates;
14        }
15        self.auth
16            .as_ref()
17            .and_then(|auth| auth.lys.as_ref())
18            .map_or(&self.templates, |lys| &lys.templates)
19    }
20
21    /// The configuration place [`Self::template_sources`] answers from, for a
22    /// refusal to name: `templates` or `auth.lys.templates`.
23    #[must_use]
24    pub fn templates_place(&self) -> &'static str {
25        if self.templates.is_empty() && self.auth.as_ref().is_some_and(|auth| auth.lys.is_some()) {
26            "auth.lys.templates"
27        } else {
28            "templates"
29        }
30    }
31}