improve readability
This commit is contained in:
parent
c324f5ec9b
commit
a839bc25cf
2 changed files with 13 additions and 12 deletions
|
@ -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<T> = Result<T, Box<dyn ConnectorError>>;
|
||||
|
||||
// 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<Vec<dns::Record>, Box<dyn ConnectorError>>;
|
||||
async fn add_records(&mut self, zone: dns::Name, class: dns::DNSClass, new_records: Vec<dns::Record>) -> Result<(), Box<dyn ConnectorError>>;
|
||||
async fn update_records(&mut self, zone: dns::Name, class: dns::DNSClass, old_records: Vec<dns::Record>, new_records: Vec<dns::Record>) -> Result<(), Box<dyn ConnectorError>>;
|
||||
async fn delete_records(&mut self, zone: dns::Name, class: dns::DNSClass, records: Vec<dns::Record>) -> Result<(), Box<dyn ConnectorError>>;
|
||||
async fn get_records(&mut self, zone: dns::Name, class: dns::DNSClass) -> ConnectorResult<Vec<dns::Record>>;
|
||||
async fn add_records(&mut self, zone: dns::Name, class: dns::DNSClass, new_records: Vec<dns::Record>) -> ConnectorResult<()>;
|
||||
async fn update_records(&mut self, zone: dns::Name, class: dns::DNSClass, old_records: Vec<dns::Record>, new_records: Vec<dns::Record>) -> ConnectorResult<()>;
|
||||
async fn delete_records(&mut self, zone: dns::Name, class: dns::DNSClass, records: Vec<dns::Record>) -> 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<dyn ConnectorError>>;
|
||||
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<dns::Name>;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Vec<Record>, Box<dyn ConnectorError>>
|
||||
async fn get_records(&mut self, zone: Name, class: DNSClass) -> ConnectorResult<Vec<Record>>
|
||||
{
|
||||
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<Record>) -> Result<(), Box<dyn ConnectorError>>
|
||||
async fn add_records(&mut self, zone: Name, class: DNSClass, new_records: Vec<Record>) -> 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<Record>, new_records: Vec<Record>) -> Result<(), Box<dyn ConnectorError>>
|
||||
async fn update_records(&mut self, zone: Name, class: DNSClass, old_records: Vec<Record>, new_records: Vec<Record>) -> 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<Record>) -> Result<(), Box<dyn ConnectorError>>
|
||||
async fn delete_records(&mut self, zone: Name, class: DNSClass, records: Vec<Record>) -> 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<dyn ConnectorError>>
|
||||
async fn zone_exists(&mut self, zone: Name, class: DNSClass) -> ConnectorResult<()>
|
||||
{
|
||||
let response = {
|
||||
let query = self.client.query(zone.clone(), class, RecordType::SOA);
|
||||
|
|
Loading…
Reference in a new issue