diff --git a/src/dns/connector.rs b/src/dns/connector.rs index 670b93f..eb5216f 100644 --- a/src/dns/connector.rs +++ b/src/dns/connector.rs @@ -3,14 +3,16 @@ use crate::dns; // TODO: Use model types instead of dns types as input / output and only convert internaly? +pub type ConnectorResult = Result>; + // Zone content api // E.g.: DNS update + axfr, zone file read + write #[async_trait] pub trait RecordConnector: Send { - async fn get_records(&mut self, zone: dns::Name, class: dns::DNSClass) -> Result, Box>; - async fn add_records(&mut self, zone: dns::Name, class: dns::DNSClass, new_records: Vec) -> Result<(), Box>; - async fn update_records(&mut self, zone: dns::Name, class: dns::DNSClass, old_records: Vec, new_records: Vec) -> Result<(), Box>; - async fn delete_records(&mut self, zone: dns::Name, class: dns::DNSClass, records: Vec) -> Result<(), Box>; + async fn get_records(&mut self, zone: dns::Name, class: dns::DNSClass) -> ConnectorResult>; + async fn add_records(&mut self, zone: dns::Name, class: dns::DNSClass, new_records: Vec) -> ConnectorResult<()>; + async fn update_records(&mut self, zone: dns::Name, class: dns::DNSClass, old_records: Vec, new_records: Vec) -> ConnectorResult<()>; + async fn delete_records(&mut self, zone: dns::Name, class: dns::DNSClass, records: Vec) -> ConnectorResult<()>; // delete_records } @@ -21,11 +23,10 @@ pub trait ZoneConnector: Send { // get_zones // add_zone // delete_zone - async fn zone_exists(&mut self, zone: dns::Name, class: dns::DNSClass) -> Result<(), Box>; + async fn zone_exists(&mut self, zone: dns::Name, class: dns::DNSClass) -> ConnectorResult<()>; } pub trait ConnectorError: std::fmt::Debug + std::fmt::Display { fn is_proto_error(&self) -> bool; fn zone_name(&self) -> Option; } - diff --git a/src/dns/dns_connector.rs b/src/dns/dns_connector.rs index d6db87f..0a7596e 100644 --- a/src/dns/dns_connector.rs +++ b/src/dns/dns_connector.rs @@ -6,7 +6,7 @@ use trust_dns_client::error::ClientError; use super::{Name, Record, RData}; use super::client::{ClientResponse, DnsClient}; -use super::connector::{RecordConnector, ZoneConnector, ConnectorError}; +use super::connector::{RecordConnector, ZoneConnector, ConnectorError, ConnectorResult}; const MAX_PAYLOAD_LEN: u16 = 1232; @@ -67,7 +67,7 @@ impl std::fmt::Display for DnsConnectorError { impl RecordConnector for DnsConnectorClient { //type Error = DnsConnectorError; - async fn get_records(&mut self, zone: Name, class: DNSClass) -> Result, Box> + async fn get_records(&mut self, zone: Name, class: DNSClass) -> ConnectorResult> { let response = { let query = self.client.query(zone.clone(), class, RecordType::AXFR); @@ -94,7 +94,7 @@ impl RecordConnector for DnsConnectorClient { Ok(records) } - async fn add_records(&mut self, zone: Name, class: DNSClass, new_records: Vec) -> Result<(), Box> + async fn add_records(&mut self, zone: Name, class: DNSClass, new_records: Vec) -> ConnectorResult<()> { // Taken from trust_dns_client::op::update_message::append // The original function can not be used as is because it takes a RecordSet and not a Record list @@ -136,7 +136,7 @@ impl RecordConnector for DnsConnectorClient { Ok(()) } - async fn update_records(&mut self, zone: Name, class: DNSClass, old_records: Vec, new_records: Vec) -> Result<(), Box> + async fn update_records(&mut self, zone: Name, class: DNSClass, old_records: Vec, new_records: Vec) -> ConnectorResult<()> { // Taken from trust_dns_client::op::update_message::compare_and_swap // The original function can not be used as is because it takes a RecordSet and not a Record list @@ -200,7 +200,7 @@ impl RecordConnector for DnsConnectorClient { Ok(()) } - async fn delete_records(&mut self, zone: Name, class: DNSClass, records: Vec) -> Result<(), Box> + async fn delete_records(&mut self, zone: Name, class: DNSClass, records: Vec) -> ConnectorResult<()> { // for updates, the query section is used for the zone let mut zone_query = Query::new(); @@ -255,7 +255,7 @@ impl RecordConnector for DnsConnectorClient { #[async_trait] impl ZoneConnector for DnsConnectorClient { - async fn zone_exists(&mut self, zone: Name, class: DNSClass) -> Result<(), Box> + async fn zone_exists(&mut self, zone: Name, class: DNSClass) -> ConnectorResult<()> { let response = { let query = self.client.query(zone.clone(), class, RecordType::SOA);