From 2c6db8f62e8143fe565bad79af785d5e7ad043a0 Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 22 Oct 2022 16:46:35 +0200 Subject: Revert "reduce nameserver.info response to correct members" This reverts commit a8ea04b12acfb4a91ec44201fff1ffc282de539e. --- Cargo.toml | 1 + src/response/nameserver.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 93f7413..d456e79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +iso8601 = "0.4.0" reqwest = { version = "0.11", features = ["blocking", "cookies"] } url = "2.2.2" xmlrpc = "0.15.1" diff --git a/src/response/nameserver.rs b/src/response/nameserver.rs index 974df7b..c5fb9fc 100644 --- a/src/response/nameserver.rs +++ b/src/response/nameserver.rs @@ -5,6 +5,8 @@ use crate::{Error, Result}; use std::collections::BTreeMap; use std::fmt; +use iso8601::DateTime; + fn get_str(map: &BTreeMap, key: &'static str) -> Result { let value = map .get(key) @@ -35,6 +37,16 @@ fn get_bool(map: &BTreeMap, key: &'static str) -> Result< Ok(value) } +fn get_datetime(map: &BTreeMap, key: &'static str) -> Result { + let value = map + .get(key) + .ok_or(Error::Inexistent(key))? + .as_datetime() + .ok_or_else(|| Error::Type(key, "DateTime", map.get(key).unwrap().clone()))?; + + Ok(value) +} + fn get_array( map: &BTreeMap, key: &'static str, @@ -48,6 +60,19 @@ fn get_array( Ok(value.to_vec()) } +fn get_map( + map: &BTreeMap, + key: &'static str, +) -> Result> { + let value = map + .get(key) + .ok_or(Error::Inexistent(key))? + .as_struct() + .ok_or_else(|| Error::Type(key, "Struct", map.get(key).unwrap().clone()))?; + + Ok(value.to_owned()) +} + /// The domain type. Can be master or slave. #[derive(Clone, Debug)] pub enum DomainType { @@ -172,6 +197,13 @@ impl TryFrom for Record { /// The records that match a search. #[derive(Clone, Debug)] pub struct RecordInfo { + pub domain_id: i32, + pub domain_name: String, + pub domain_type: DomainType, + pub master_address: String, + pub last_zone_check: DateTime, + pub slave_dns: SlaveDns, + pub soa_serial: String, pub records: Vec, } @@ -179,6 +211,13 @@ impl TryFrom for RecordInfo { type Error = Error; fn try_from(resp: Response) -> Result { let info = Self { + domain_id: get_i32(&resp.data, "roId")?, + domain_name: get_str(&resp.data, "domain")?, + domain_type: get_str(&resp.data, "type")?.try_into()?, + master_address: get_str(&resp.data, "masterIp")?, + last_zone_check: get_datetime(&resp.data, "lastZoneCheck")?, + slave_dns: get_map(&resp.data, "slaveDns")?.try_into()?, + soa_serial: get_str(&resp.data, "SOAserial")?, records: get_array(&resp.data, "record")? .iter() .map(|v| v.to_owned().try_into()) -- cgit v1.2.3