remove id from zone

This commit is contained in:
Luna Yao
2026-04-19 02:14:07 +02:00
parent 362547eaab
commit 11626d8082
7 changed files with 8 additions and 50 deletions
+1 -2
View File
@@ -705,8 +705,7 @@ impl DnsGlobalCtxExt for GlobalCtx {
let ipv6 = self.get_ipv6().map(|ip| ip.address());
let ipv6 = ipv6.map(|a| vec![a]).unwrap_or_default();
crate::dns::config::zone::ZoneConfig::dedicated(Some(self.get_id()), fqdn, ipv4, ipv6)
.unwrap()
crate::dns::config::zone::ZoneConfig::dedicated(fqdn, ipv4, ipv6).unwrap()
}
fn dns_export_config(&self) -> DnsExportConfig {
-7
View File
@@ -8,7 +8,6 @@ use hickory_proto::rr::LowerName;
use serde::{Deserialize, Serialize};
use std::convert::{TryFrom, TryInto};
use std::net::{Ipv4Addr, Ipv6Addr};
use uuid::Uuid;
#[derive(Derivative, Debug, Clone, Deserialize, Serialize, Default, Deref, Into)]
#[derivative(PartialEq)]
@@ -39,7 +38,6 @@ impl TryFrom<ZoneConfigInner> for ZoneConfig {
impl ZoneConfig {
pub fn dedicated(
id: Option<Uuid>,
origin: LowerName,
ipv4: Option<Ipv4Addr>,
ipv6: Vec<Ipv6Addr>,
@@ -58,7 +56,6 @@ impl ZoneConfig {
};
let config = ZoneConfigInner {
id: id.unwrap_or_else(Uuid::new_v4),
origin,
records,
policy,
@@ -73,9 +70,6 @@ impl ZoneConfig {
#[derivative(Default)]
#[serde(default)]
pub struct ZoneConfigInner {
#[derivative(Default(value = "Uuid::new_v4()"))]
#[serde(skip_serializing)]
id: Uuid,
pub origin: LowerName,
pub ttl: u32,
pub records: Vec<String>,
@@ -89,7 +83,6 @@ pub struct ZoneConfigInner {
impl From<ZoneConfigInner> for ZoneData {
fn from(value: ZoneConfigInner) -> Self {
Self {
id: Some(value.id.into()),
origin: value.origin.to_string(),
ttl: value.ttl,
records: value.records,
+2 -5
View File
@@ -204,7 +204,6 @@ mod tests {
use std::collections::HashSet;
use std::net::Ipv4Addr;
use tokio::time::{Duration, sleep};
use uuid::Uuid;
async fn create_peer_manager_with_zone(
host: &str,
@@ -216,7 +215,6 @@ mod tests {
dns.name = host.parse().unwrap();
dns.zones.push(
ZoneConfig::dedicated(
Some(Uuid::new_v4()),
origin.parse().expect("invalid zone origin"),
Some(record_ip),
vec![],
@@ -246,10 +244,9 @@ mod tests {
fn dns_peer_info_try_from_invalid_zone_rejected() {
let cfg = DnsExportConfig {
zones: vec![ZoneData {
id: None,
origin: "invalid.peer.test".to_string(),
origin: "?".to_string(),
ttl: 60,
records: vec!["@ IN A 10.0.0.11".to_string()],
records: vec!["?".to_string()],
forwarders: vec![],
fallthrough: false,
}],
-1
View File
@@ -102,7 +102,6 @@ pub fn zone_data_a(origin: &str, record: &str) -> ZoneData {
pub fn zone_data_a_with_forwarders(origin: &str, record: &str, forwarders: Vec<&str>) -> ZoneData {
ZoneData {
id: Some(Uuid::new_v4().into()),
origin: origin.to_string(),
ttl: 60,
records: vec![format!("@ IN A {record}")],
-28
View File
@@ -13,11 +13,9 @@ use indexmap::IndexMap;
use itertools::chain;
use std::collections::BTreeMap;
use std::sync::Arc;
use uuid::Uuid;
#[derive(Debug, Clone)]
pub struct Zone {
id: Uuid,
origin: LowerName,
records: BTreeMap<RrKey, RecordSet>,
pub forward: Option<ForwardConfig>,
@@ -41,7 +39,6 @@ impl Zone {
impl Zone {
pub fn new(name: LowerName) -> Self {
Self {
id: Uuid::new_v4(),
origin: name,
records: BTreeMap::new(),
forward: None,
@@ -96,11 +93,6 @@ impl TryFrom<&proto::dns::ZoneData> for Zone {
type Error = anyhow::Error;
fn try_from(value: &proto::dns::ZoneData) -> Result<Self, Self::Error> {
let id = value
.id
.ok_or(anyhow::anyhow!("missing id in zone data"))?
.into();
let (origin, records) = Parser::new(value.to_string(), None, None)
.parse()
.map_err(|e| anyhow::anyhow!("failed to parse zone data: {e}"))?;
@@ -117,7 +109,6 @@ impl TryFrom<&proto::dns::ZoneData> for Zone {
});
Ok(Self {
id,
origin: origin.into(),
records,
forward,
@@ -145,7 +136,6 @@ impl From<Zone> for proto::dns::ZoneData {
.collect();
Self {
id: Some(value.id.into()),
origin: value.origin.to_string(),
ttl: 0,
records,
@@ -190,7 +180,6 @@ mod tests {
use std::str::FromStr;
use tokio::net::UdpSocket;
use tokio::task::JoinHandle;
use uuid::Uuid;
impl Zone {
// Test-only record iterator for precise assertions.
@@ -214,7 +203,6 @@ mod tests {
fallthrough: bool,
) -> ZoneData {
ZoneData {
id: Some(Uuid::new_v4().into()),
origin: origin.to_string(),
ttl: 60,
records: records.into_iter().map(ToString::to_string).collect(),
@@ -287,21 +275,6 @@ mod tests {
Ok((addr, handle))
}
#[test]
fn zone_try_from_rejects_missing_id() {
let data = ZoneData {
id: None,
origin: "missing-id.test".to_string(),
ttl: 60,
records: vec!["@ IN A 10.0.0.1".to_string()],
forwarders: vec![],
fallthrough: false,
};
let err = Zone::try_from(&data).expect_err("missing id should fail");
assert!(err.to_string().contains("missing id"));
}
#[test]
fn zone_try_from_rejects_invalid_record() {
let data = zone_data("invalid-record.test", vec!["this is not a record"], vec![]);
@@ -340,7 +313,6 @@ mod tests {
assert_eq!(zone.forward.as_ref().unwrap().name_servers.len(), 2);
let serialized = ZoneData::from(zone.clone());
assert!(serialized.id.is_some());
assert_eq!(serialized.origin, "roundtrip.test.");
assert_eq!(serialized.records.len(), 2);
assert_eq!(serialized.forwarders.len(), 2);
+5 -6
View File
@@ -5,12 +5,11 @@ import "common.proto";
package dns;
message ZoneData {
common.UUID id = 1;
string origin = 2;
uint32 ttl = 3;
repeated string records = 4;
repeated common.Url forwarders = 5;
bool fallthrough = 6;
string origin = 1;
uint32 ttl = 2;
repeated string records = 3;
repeated common.Url forwarders = 4;
bool fallthrough = 5;
}
message GetExportConfigRequest {}
-1
View File
@@ -14,7 +14,6 @@ impl Display for ZoneData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "; EasyTier Magic DNS zone data")?;
writeln!(f, "; https://github.com/easytier/easytier")?;
writeln!(f, "; {}", self.id.unwrap_or_default())?;
if !self.forwarders.is_empty() {
writeln!(f, "; Forwarders:")?;