diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-22 16:46:35 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-22 16:46:35 +0200 |
commit | 2c6db8f62e8143fe565bad79af785d5e7ad043a0 (patch) | |
tree | 4e7726c01c933c9262c375acc6d7fb5e4c338f83 | |
parent | f5e86549298612e57325daccb21b028f60b795ca (diff) |
Revert "reduce nameserver.info response to correct members"
This reverts commit a8ea04b12acfb4a91ec44201fff1ffc282de539e.
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/response/nameserver.rs | 39 |
2 files changed, 40 insertions, 0 deletions
@@ -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<String, xmlrpc::Value>, key: &'static str) -> Result<String> { let value = map .get(key) @@ -35,6 +37,16 @@ fn get_bool(map: &BTreeMap<String, xmlrpc::Value>, key: &'static str) -> Result< Ok(value) } +fn get_datetime(map: &BTreeMap<String, xmlrpc::Value>, key: &'static str) -> Result<DateTime> { + 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<String, xmlrpc::Value>, key: &'static str, @@ -48,6 +60,19 @@ fn get_array( Ok(value.to_vec()) } +fn get_map( + map: &BTreeMap<String, xmlrpc::Value>, + key: &'static str, +) -> Result<BTreeMap<String, xmlrpc::Value>> { + 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<xmlrpc::Value> 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<Record>, } @@ -179,6 +211,13 @@ impl TryFrom<Response> for RecordInfo { type Error = Error; fn try_from(resp: Response) -> Result<Self> { 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()) |