zone: comments

This commit is contained in:
Luna Yao
2026-04-06 17:02:58 +02:00
parent 50ecd3679b
commit 09b26fd4fe
+8 -4
View File
@@ -3,23 +3,25 @@ use crate::dns::utils::addr::NameServerAddrGroup;
use crate::dns::zone::Zone; use crate::dns::zone::Zone;
use crate::proto::dns::ZoneData; use crate::proto::dns::ZoneData;
use derivative::Derivative; use derivative::Derivative;
use derive_more::{Deref, DerefMut, Into}; use derive_more::{Deref, Into};
use hickory_proto::rr::LowerName; use hickory_proto::rr::LowerName;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::convert::{TryFrom, TryInto}; use std::convert::{TryFrom, TryInto};
use std::net::{Ipv4Addr, Ipv6Addr}; use std::net::{Ipv4Addr, Ipv6Addr};
use uuid::Uuid; use uuid::Uuid;
#[derive(Derivative, Debug, Clone, Deserialize, Serialize, Default, Deref, DerefMut, Into)] #[derive(Derivative, Debug, Clone, Deserialize, Serialize, Default, Deref, Into)]
#[derivative(PartialEq)] #[derivative(PartialEq)]
#[serde(try_from = "ZoneConfigInner", into = "ZoneConfigInner")] #[serde(try_from = "ZoneConfigInner", into = "ZoneConfigInner")]
pub struct ZoneConfig { pub struct ZoneConfig {
#[into] #[into]
#[derivative(PartialEq = "ignore")] #[derivative(PartialEq = "ignore")]
data: ZoneData, data: ZoneData,
// User-facing config source of truth used for serde round-trips.
// Keep this in sync with `data` by rebuilding a full ZoneConfig via TryFrom.
// Do not mutate subfields in place and expect `data` to follow.
#[into] #[into]
#[deref] #[deref]
#[deref_mut]
inner: ZoneConfigInner, inner: ZoneConfigInner,
} }
@@ -27,8 +29,10 @@ impl TryFrom<ZoneConfigInner> for ZoneConfig {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(value: ZoneConfigInner) -> Result<Self, Self::Error> { fn try_from(value: ZoneConfigInner) -> Result<Self, Self::Error> {
// Rebuild both representations together and validate zone semantics.
// Config updates should follow this replacement path.
let data = ZoneData::from(value.clone()); let data = ZoneData::from(value.clone());
let _ = Zone::try_from(&data)?; let _ = Zone::try_from(&data)?; // validation
Ok(Self { data, inner: value }) Ok(Self { data, inner: value })
} }
} }