use std::fmt;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
#[serde(rename_all = "kebab-case")]
pub enum BackendKind {
SystemdResolved,
NetworkManager,
Resolvconf,
ResolvConfFile,
WindowsIpHelper,
MacosSystemConfiguration,
Fake,
}
impl BackendKind {
pub fn is_real(&self) -> bool {
*self != BackendKind::Fake
}
}
impl fmt::Display for BackendKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match self {
BackendKind::SystemdResolved => "systemd-resolved",
BackendKind::NetworkManager => "network-manager",
BackendKind::Resolvconf => "resolvconf",
BackendKind::ResolvConfFile => "resolv-conf-file",
BackendKind::WindowsIpHelper => "windows-ip-helper",
BackendKind::MacosSystemConfiguration => "macos-system-configuration",
BackendKind::Fake => "fake",
};
f.write_str(name)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct Capabilities {
pub backend: BackendKind,
pub read: bool,
pub global_dns: bool,
pub per_interface_dns: bool,
pub search_domains: bool,
pub split_dns: bool,
pub default_route: bool,
pub watch: bool,
pub cache_flush: bool,
pub mutation_guard: MutationGuard,
pub ownership_identity: OwnershipIdentity,
pub resource_binding: ResourceBinding,
}
impl Capabilities {
pub fn new(backend: BackendKind) -> Self {
Self {
backend,
read: false,
global_dns: false,
per_interface_dns: false,
search_domains: false,
split_dns: false,
default_route: false,
watch: false,
cache_flush: false,
mutation_guard: MutationGuard::Unconditional,
ownership_identity: OwnershipIdentity::BestEffort,
resource_binding: ResourceBinding::StableTarget,
}
}
pub fn with_read(mut self, enabled: bool) -> Self {
self.read = enabled;
self
}
pub fn with_global_dns(mut self, enabled: bool) -> Self {
self.global_dns = enabled;
self
}
pub fn with_per_interface_dns(mut self, enabled: bool) -> Self {
self.per_interface_dns = enabled;
self
}
pub fn with_search_domains(mut self, enabled: bool) -> Self {
self.search_domains = enabled;
self
}
pub fn with_split_dns(mut self, enabled: bool) -> Self {
self.split_dns = enabled;
self
}
pub fn with_default_route(mut self, enabled: bool) -> Self {
self.default_route = enabled;
self
}
pub fn with_watch(mut self, enabled: bool) -> Self {
self.watch = enabled;
self
}
pub fn with_cache_flush(mut self, enabled: bool) -> Self {
self.cache_flush = enabled;
self
}
pub fn with_mutation_guard(mut self, guard: MutationGuard) -> Self {
self.mutation_guard = guard;
self
}
pub fn with_ownership_identity(mut self, identity: OwnershipIdentity) -> Self {
self.ownership_identity = identity;
self
}
pub fn with_resource_binding(mut self, binding: ResourceBinding) -> Self {
self.resource_binding = binding;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub enum ResourceBinding {
StableTarget,
NativeGuarded,
PreflightOnly,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub enum MutationGuard {
CompareAndMutate,
Unconditional,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub enum OwnershipIdentity {
Durable,
BestEffort,
}