1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use serde::{Deserialize, Serialize};

use super::Merge;

#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct CapabilityNetworkDnsV1 {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enabled: Option<bool>,

    /// DNS servers to be used.
    // Note: not Option because we'd like to distinguis between "empty" and "not specified".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub servers: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allowed_hosts: Option<NetworkDnsAllowedHostsV1>,
}

impl Merge for CapabilityNetworkDnsV1 {
    fn merge_extend(self, other: &Self) -> Self {
        Self {
            enabled: self.enabled.merge_extend(&other.enabled),
            servers: self.servers.merge_extend(&other.servers),
            allowed_hosts: self.allowed_hosts.merge_extend(&other.allowed_hosts),
        }
    }
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct NetworkDnsAllowedHostsV1 {
    pub allow_all_hosts: Option<bool>,
    /// List of allowed hostnames.
    pub hosts: Vec<String>,
    /// List of regular expression patterns that match allowed hosts.
    pub regex_patterns: Vec<String>,
    /// List of wildcard patterns that can use '*' as a wildcard.
    pub wildcard_patterns: Vec<String>,
}

impl Merge for NetworkDnsAllowedHostsV1 {
    fn merge_extend(self, other: &Self) -> Self {
        Self {
            allow_all_hosts: self.allow_all_hosts.merge_extend(&other.allow_all_hosts),
            hosts: self.hosts.merge_extend(&other.hosts),
            regex_patterns: self.regex_patterns.merge_extend(&other.regex_patterns),
            wildcard_patterns: self
                .wildcard_patterns
                .merge_extend(&other.wildcard_patterns),
        }
    }
}