Refactor host info models

This commit is contained in:
Nicholas Rempel 2021-11-26 10:38:57 -08:00 committed by masalachai
parent b8f9eb1f8f
commit 388f153763
10 changed files with 62 additions and 69 deletions

View File

@ -5,11 +5,9 @@ pub mod request;
pub mod response;
pub mod xml;
pub use request::host::update::*;
pub use request::message::ack::*;
pub use request::message::poll::*;
pub use response::host::update::*;
pub use response::message::ack::*;
pub use response::message::poll::*;

View File

@ -1,6 +1,5 @@
//! Types for EPP requests
pub mod host;
pub mod message;
use serde::{ser::SerializeStruct, ser::Serializer, Deserialize, Serialize};

View File

@ -1,3 +0,0 @@
//! Types for EPP host requests
pub mod update;

View File

@ -1,6 +1,5 @@
//! Types for EPP responses
pub mod host;
pub mod message;
use epp_client_macros::*;

View File

@ -1,3 +0,0 @@
//! Types for EPP host responses
pub mod update;

View File

@ -1,6 +0,0 @@
//! Types for EPP host check response
use crate::epp::response::EppCommandResponse;
/// Type that represents the <epp> tag for the EPP XML host update response
pub type EppHostUpdateResponse = EppCommandResponse;

View File

@ -2,3 +2,4 @@ pub mod check;
pub mod create;
pub mod delete;
pub mod info;
pub mod update;

View File

@ -5,6 +5,7 @@ use epp_client_macros::*;
use crate::epp::object::data::{HostAddr, HostStatus};
use crate::epp::object::{ElementName, EppObject, StringValue};
use crate::epp::request::Command;
use crate::epp::response::EppCommandResponse;
use crate::epp::xml::EPP_HOST_XMLNS;
use serde::{Deserialize, Serialize};
@ -18,7 +19,7 @@ use serde::{Deserialize, Serialize};
/// use epp_client::config::{EppClientConfig, EppClientConnection};
/// use epp_client::EppClient;
/// use epp_client::epp::object::data::{HostAddr, HostStatus};
/// use epp_client::epp::{EppHostUpdate, EppHostUpdateResponse, HostAddRemove, HostChangeInfo};
/// use epp_client::host::update::{EppHostUpdate, EppHostUpdateResponse, HostAddRemove, HostChangeInfo};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
@ -76,62 +77,14 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap();
/// }
/// ```
pub type EppHostUpdate = EppObject<Command<HostUpdate>>;
/// Type for data under the &lt;chg&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostChangeInfo {
/// The new name for the host
#[serde(rename = "host:name", alias = "name")]
pub name: StringValue,
}
/// Type for data under the &lt;add&gt; and &lt;rem&gt; tags
#[derive(Serialize, Deserialize, Debug)]
pub struct HostAddRemove {
/// The IP addresses to be added to or removed from the host
#[serde(rename = "host:addr", alias = "addr")]
pub addresses: Option<Vec<HostAddr>>,
/// The statuses to be added to or removed from the host
#[serde(rename = "host:status", alias = "status")]
pub statuses: Option<Vec<HostStatus>>,
}
/// Type for data under the host &lt;update&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostUpdateData {
/// XML namespace for host commands
#[serde(rename = "xmlns:host", alias = "xmlns")]
xmlns: String,
/// The name of the host
#[serde(rename = "host:name", alias = "name")]
name: StringValue,
/// The IP addresses and statuses to be added to the host
#[serde(rename = "host:add", alias = "add")]
add: Option<HostAddRemove>,
/// The IP addresses and statuses to be removed from the host
#[serde(rename = "host:rem", alias = "rem")]
remove: Option<HostAddRemove>,
/// The host details that need to be updated
#[serde(rename = "host:chg", alias = "chg")]
change_info: Option<HostChangeInfo>,
}
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "update")]
/// Type for EPP XML &lt;update&gt; command for hosts
pub struct HostUpdate {
/// The instance holding the data for the host to be updated
#[serde(rename = "host:update", alias = "update")]
host: HostUpdateData,
}
pub type EppHostUpdate = EppObject<Command<HostUpdateRequest>>;
impl EppHostUpdate {
/// Creates a new EppObject for host update corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(name: &str, client_tr_id: &str) -> EppHostUpdate {
EppObject::build(Command::<HostUpdate>::new(
HostUpdate {
host: HostUpdateData {
EppObject::build(Command::<HostUpdateRequest>::new(
HostUpdateRequest {
host: HostUpdateRequestData {
xmlns: EPP_HOST_XMLNS.to_string(),
name: name.into(),
add: None,
@ -158,3 +111,54 @@ impl EppHostUpdate {
self.data.command.host.remove = Some(remove);
}
}
/// Type that represents the &lt;epp&gt; tag for the EPP XML host update response
pub type EppHostUpdateResponse = EppCommandResponse;
/// Type for data under the &lt;chg&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostChangeInfo {
/// The new name for the host
#[serde(rename = "host:name", alias = "name")]
pub name: StringValue,
}
/// Type for data under the &lt;add&gt; and &lt;rem&gt; tags
#[derive(Serialize, Deserialize, Debug)]
pub struct HostAddRemove {
/// The IP addresses to be added to or removed from the host
#[serde(rename = "host:addr", alias = "addr")]
pub addresses: Option<Vec<HostAddr>>,
/// The statuses to be added to or removed from the host
#[serde(rename = "host:status", alias = "status")]
pub statuses: Option<Vec<HostStatus>>,
}
/// Type for data under the host &lt;update&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostUpdateRequestData {
/// XML namespace for host commands
#[serde(rename = "xmlns:host", alias = "xmlns")]
xmlns: String,
/// The name of the host
#[serde(rename = "host:name", alias = "name")]
name: StringValue,
/// The IP addresses and statuses to be added to the host
#[serde(rename = "host:add", alias = "add")]
add: Option<HostAddRemove>,
/// The IP addresses and statuses to be removed from the host
#[serde(rename = "host:rem", alias = "rem")]
remove: Option<HostAddRemove>,
/// The host details that need to be updated
#[serde(rename = "host:chg", alias = "chg")]
change_info: Option<HostChangeInfo>,
}
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "update")]
/// Type for EPP XML &lt;update&gt; command for hosts
pub struct HostUpdateRequest {
/// The instance holding the data for the host to be updated
#[serde(rename = "host:update", alias = "update")]
host: HostUpdateRequestData,
}

View File

@ -31,6 +31,7 @@ mod response {
use crate::host::create::EppHostCreateResponse;
use crate::host::delete::EppHostDeleteResponse;
use crate::host::info::EppHostInfoResponse;
use crate::host::update::EppHostUpdateResponse;
const SVTRID: &str = "RO-6879-1627224678242975";
const SUCCESS_MSG: &str = "Command completed successfully";

View File

@ -34,6 +34,9 @@ mod request {
use crate::host::create::EppHostCreate;
use crate::host::delete::EppHostDelete;
use crate::host::info::EppHostInfo;
use crate::host::update::EppHostUpdate;
use crate::host::update::HostAddRemove;
use crate::host::update::HostChangeInfo;
use chrono::{DateTime, NaiveDate};
use std::str::FromStr;