wasmer_deploy_schema/schema/
network_dns.rs

1use serde::{Deserialize, Serialize};
2
3use super::Merge;
4
5#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
6pub struct CapabilityNetworkDnsV1 {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub enabled: Option<bool>,
9
10    /// DNS servers to be used.
11    // Note: not Option because we'd like to distinguis between "empty" and "not specified".
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub servers: Option<Vec<String>>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub allowed_hosts: Option<NetworkDnsAllowedHostsV1>,
16}
17
18impl Merge for CapabilityNetworkDnsV1 {
19    fn merge_extend(self, other: &Self) -> Self {
20        Self {
21            enabled: self.enabled.merge_extend(&other.enabled),
22            servers: self.servers.merge_extend(&other.servers),
23            allowed_hosts: self.allowed_hosts.merge_extend(&other.allowed_hosts),
24        }
25    }
26}
27
28#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
29pub struct NetworkDnsAllowedHostsV1 {
30    pub allow_all_hosts: Option<bool>,
31    /// List of allowed hostnames.
32    pub hosts: Vec<String>,
33    /// List of regular expression patterns that match allowed hosts.
34    pub regex_patterns: Vec<String>,
35    /// List of wildcard patterns that can use '*' as a wildcard.
36    pub wildcard_patterns: Vec<String>,
37}
38
39impl Merge for NetworkDnsAllowedHostsV1 {
40    fn merge_extend(self, other: &Self) -> Self {
41        Self {
42            allow_all_hosts: self.allow_all_hosts.merge_extend(&other.allow_all_hosts),
43            hosts: self.hosts.merge_extend(&other.hosts),
44            regex_patterns: self.regex_patterns.merge_extend(&other.regex_patterns),
45            wildcard_patterns: self
46                .wildcard_patterns
47                .merge_extend(&other.wildcard_patterns),
48        }
49    }
50}