Skip to main content

isoloom_spec/model/
private_dns.rs

1//! The environment's own DNS zone (`dns:` at the top level): the machines' names and `aliases`
2//! served under a private domain by the platform's DNS, where it has one.
3
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7/// The environment's names in a private DNS zone (see [`super::Spec::dns`]).
8#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
9#[serde(deny_unknown_fields)]
10pub struct EnvironmentDns {
11    /// Serve every machine's name and `aliases` under `domain` (`web.<domain>`) from the
12    /// platform's own private DNS: a Route 53 private hosted zone on AWS, an Azure private DNS
13    /// zone, a Cloud DNS private zone on Google Cloud, a private view on Oracle Cloud, Docker's
14    /// DNS on the Docker targets. Where the platform has none (Vagrant, Proxmox, DigitalOcean,
15    /// Linode), the hosts file every VM gets carries the same names. Off by default: a cloud
16    /// zone is billed, and the short names already resolve through the hosts file everywhere.
17    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
18    pub private: bool,
19    /// The private zone's domain (`lab.internal`). By default `<name>.internal`, after the
20    /// environment's name. Needs `private: true`.
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub domain: Option<String>,
23}
24
25impl EnvironmentDns {
26    /// The private zone's domain for environment `name`, when private DNS is on.
27    #[must_use]
28    pub fn private_domain(&self, name: &str) -> Option<String> {
29        self.private.then(|| self.domain.clone().unwrap_or_else(|| format!("{name}.internal")))
30    }
31}