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