fix <hostObj> and <hostAttr> tags for domain update

This commit is contained in:
Ritesh Chitlangi 2021-11-18 19:59:21 +08:00
parent 5d54101317
commit bb23fb5201
5 changed files with 26 additions and 65 deletions

View File

@ -64,6 +64,15 @@ pub struct HostAttr {
pub addresses: Option<Vec<HostAddr>>,
}
/// Enum that can accept one type which corresponds to either the &lt;hostObj&gt; or &lt;hostAttr&gt;
/// list of tags
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum HostList {
HostObjList(HostObjList),
HostAttrList(HostAttrList),
}
/// The list of &lt;hostAttr&gt; types for domain transactions. Typically under an &lt;ns&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostAttrList {

View File

@ -3,7 +3,7 @@
use epp_client_macros::*;
use crate::epp::object::data::{
AuthInfo, DomainContact, HostAttr, HostAttrList, HostObjList, Period,
AuthInfo, DomainContact, HostAttr, HostAttrList, HostList, HostObjList, Period,
};
use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait};
use crate::epp::request::Command;
@ -78,15 +78,6 @@ use serde::{Deserialize, Serialize};
/// ```
pub type EppDomainCreate = EppObject<Command<DomainCreate>>;
/// Enum that can accept one type which corresponds to either the &lt;hostObj&gt; or &lt;hostAttr&gt;
/// list of tags
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum HostList {
HostObjList(HostObjList),
HostAttrList(HostAttrList),
}
/// Type for elements under the domain &lt;create&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCreateData {

View File

@ -2,7 +2,6 @@
use epp_client_macros::*;
use crate::epp::object::data::HostObjList;
use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait};
use crate::epp::request::domain::update::{DomainChangeInfo, DomainUpdate, DomainUpdateData};
use crate::epp::request::{CommandWithExtension, Extension};
@ -84,7 +83,7 @@ use serde::{Deserialize, Serialize};
/// }
/// ```
pub type EppDomainRgpRestoreReport =
EppObject<CommandWithExtension<DomainUpdate<HostObjList>, RgpRestoreReport>>;
EppObject<CommandWithExtension<DomainUpdate, RgpRestoreReport>>;
/// Type corresponding to the &lt;report&gt; section in the EPP rgp restore extension
#[derive(Serialize, Deserialize, Debug)]
@ -152,7 +151,7 @@ impl EppDomainRgpRestoreReport {
.map(|s| s.to_string_value())
.collect::<Vec<StringValue>>();
let command = CommandWithExtension::<DomainUpdate<HostObjList>, RgpRestoreReport> {
let command = CommandWithExtension::<DomainUpdate, RgpRestoreReport> {
command: DomainUpdate {
domain: DomainUpdateData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),

View File

@ -2,7 +2,6 @@
use epp_client_macros::*;
use crate::epp::object::data::HostObjList;
use crate::epp::object::{ElementName, EppObject, StringValueTrait};
use crate::epp::request::domain::update::{DomainChangeInfo, DomainUpdate, DomainUpdateData};
use crate::epp::request::{CommandWithExtension, Extension};
@ -61,7 +60,7 @@ use serde::{Deserialize, Serialize};
/// }
/// ```
pub type EppDomainRgpRestoreRequest =
EppObject<CommandWithExtension<DomainUpdate<HostObjList>, RgpRestoreRequest>>;
EppObject<CommandWithExtension<DomainUpdate, RgpRestoreRequest>>;
/// Type corresponding to the &lt;restore&gt; tag for an rgp restore request
#[derive(Serialize, Deserialize, Debug)]
@ -86,7 +85,7 @@ pub struct RgpRestoreRequest {
impl EppDomainRgpRestoreRequest {
/// Creates a new EppObject for domain rgp restore request corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(name: &str, client_tr_id: &str) -> EppDomainRgpRestoreRequest {
let command = CommandWithExtension::<DomainUpdate<HostObjList>, RgpRestoreRequest> {
let command = CommandWithExtension::<DomainUpdate, RgpRestoreRequest> {
command: DomainUpdate {
domain: DomainUpdateData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),

View File

@ -2,7 +2,7 @@
use epp_client_macros::*;
use crate::epp::object::data::{AuthInfo, DomainContact, DomainStatus, HostAttrList, HostObjList};
use crate::epp::object::data::{AuthInfo, DomainContact, DomainStatus, HostList};
use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait};
use crate::epp::request::Command;
use crate::epp::xml::EPP_DOMAIN_XMLNS;
@ -80,10 +80,7 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap();
/// }
/// ```
pub type EppDomainUpdate = EppObject<Command<DomainUpdate<HostObjList>>>;
/// Type that represents the &lt;epp&gt; request for domain &lt;update&gt; command
/// with &lt;hostAttr&gt; elements in the request for &lt;ns&gt; list
pub type EppDomainUpdateWithHostAttr = EppObject<Command<DomainUpdate<HostAttrList>>>;
pub type EppDomainUpdate = EppObject<Command<DomainUpdate>>;
/// Type for elements under the &lt;chg&gt; tag for domain update
#[derive(Serialize, Deserialize, Debug)]
@ -97,11 +94,11 @@ pub struct DomainChangeInfo {
/// Type for elements under the &lt;add&gt; and &lt;rem&gt; tags for domain update
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainAddRemove<T> {
pub struct DomainAddRemove {
/// The list of nameservers to add or remove
/// Type T can be either a `HostObjList` or `HostAttrList`
#[serde(rename = "ns")]
pub ns: Option<T>,
pub ns: Option<HostList>,
/// The list of contacts to add to or remove from the domain
#[serde(rename = "contact")]
pub contacts: Option<Vec<DomainContact>>,
@ -112,18 +109,18 @@ pub struct DomainAddRemove<T> {
/// Type for elements under the &lt;update&gt; tag for domain update
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainUpdateData<T> {
pub struct DomainUpdateData {
/// XML namespace for domain commands
pub xmlns: String,
/// The name of the domain to update
pub name: StringValue,
/// `DomainAddRemove` Object containing the list of elements to be added
/// to the domain
pub add: Option<DomainAddRemove<T>>,
pub add: Option<DomainAddRemove>,
/// `DomainAddRemove` Object containing the list of elements to be removed
/// from the domain
#[serde(rename = "rem")]
pub remove: Option<DomainAddRemove<T>>,
pub remove: Option<DomainAddRemove>,
/// The data under the &lt;chg&gt; tag for domain update
#[serde(rename = "chg")]
pub change_info: Option<DomainChangeInfo>,
@ -132,16 +129,16 @@ pub struct DomainUpdateData<T> {
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "update")]
/// Type for EPP XML &lt;update&gt; command for domains
pub struct DomainUpdate<T> {
pub struct DomainUpdate {
#[serde(rename = "update")]
pub domain: DomainUpdateData<T>,
pub domain: DomainUpdateData,
}
impl EppDomainUpdate {
/// Creates a new EppObject for domain update corresponding to the &lt;epp&gt; tag in EPP XML
/// with the &lt;ns&gt; tag containing &lt;hostObj&gt; tags
pub fn new(name: &str, client_tr_id: &str) -> EppDomainUpdate {
EppObject::build(Command::<DomainUpdate<HostObjList>>::new(
EppObject::build(Command::<DomainUpdate>::new(
DomainUpdate {
domain: DomainUpdateData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
@ -161,46 +158,12 @@ impl EppDomainUpdate {
}
/// Sets the data for the &lt;add&gt; tag
pub fn add(&mut self, add: DomainAddRemove<HostObjList>) {
pub fn add(&mut self, add: DomainAddRemove) {
self.data.command.domain.add = Some(add);
}
/// Sets the data for the &lt;rem&gt; tag
pub fn remove(&mut self, remove: DomainAddRemove<HostObjList>) {
self.data.command.domain.remove = Some(remove);
}
}
impl EppDomainUpdateWithHostAttr {
/// Creates a new EppObject for domain update corresponding to the &lt;epp&gt; tag in EPP XML
/// with the &lt;ns&gt; tag containing &lt;hostAttr&gt; tags
pub fn new(name: &str, client_tr_id: &str) -> EppDomainUpdateWithHostAttr {
EppObject::build(Command::<DomainUpdate<HostAttrList>>::new(
DomainUpdate {
domain: DomainUpdateData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.to_string_value(),
add: None,
remove: None,
change_info: None,
},
},
client_tr_id,
))
}
/// Sets the data for the &lt;chg&gt; tag
pub fn info(&mut self, info: DomainChangeInfo) {
self.data.command.domain.change_info = Some(info);
}
/// Sets the data for the &lt;add&gt; tag
pub fn add(&mut self, add: DomainAddRemove<HostAttrList>) {
self.data.command.domain.add = Some(add);
}
/// Sets the data for the &lt;rem&gt; tag
pub fn remove(&mut self, remove: DomainAddRemove<HostAttrList>) {
pub fn remove(&mut self, remove: DomainAddRemove) {
self.data.command.domain.remove = Some(remove);
}
}