Refactor domain create models

This commit is contained in:
Nick Rempel 2021-11-24 21:43:54 -08:00 committed by masalachai
parent c082a5e3bf
commit 341e06dc14
8 changed files with 151 additions and 141 deletions

View File

@ -1 +1,2 @@
pub mod check; pub mod check;
pub mod create;

View File

@ -7,6 +7,7 @@ use crate::epp::object::data::{
}; };
use crate::epp::object::{ElementName, EppObject, StringValue}; use crate::epp::object::{ElementName, EppObject, StringValue};
use crate::epp::request::Command; use crate::epp::request::Command;
use crate::epp::response::CommandResponse;
use crate::epp::xml::EPP_DOMAIN_XMLNS; use crate::epp::xml::EPP_DOMAIN_XMLNS;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -21,7 +22,7 @@ use serde::{Deserialize, Serialize};
/// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::config::{EppClientConfig, EppClientConnection};
/// use epp_client::EppClient; /// use epp_client::EppClient;
/// use epp_client::epp::object::data::DomainContact; /// use epp_client::epp::object::data::DomainContact;
/// use epp_client::epp::{EppDomainCreate, EppDomainCreateResponse}; /// use epp_client::domain::create::{EppDomainCreate, EppDomainCreateResponse};
/// use epp_client::epp::generate_client_tr_id; /// use epp_client::epp::generate_client_tr_id;
/// ///
/// #[tokio::main] /// #[tokio::main]
@ -76,11 +77,130 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap(); /// client.logout().await.unwrap();
/// } /// }
/// ``` /// ```
pub type EppDomainCreate = EppObject<Command<DomainCreate>>; pub type EppDomainCreate = EppObject<Command<DomainCreateRequest>>;
impl EppDomainCreate {
/// Creates a new EppObject for domain create corresponding to the &lt;epp&gt; tag in EPP XML
/// with the &lt;ns&gt; tag containing &lt;hostObj&gt; tags
pub fn new_with_ns(
name: &str,
period: u16,
ns: &[&str],
registrant_id: &str,
auth_password: &str,
contacts: Vec<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreate {
let ns_list = ns.iter().map(|&n| n.into()).collect();
let domain_create = DomainCreateRequest {
domain: DomainCreateRequestData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
period: Period::new(period),
ns: Some(HostList::HostObjList(HostObjList { hosts: ns_list })),
registrant: Some(registrant_id.into()),
auth_info: DomainAuthInfo::new(auth_password),
contacts: Some(contacts),
},
};
EppObject::build(Command::<DomainCreateRequest>::new(
domain_create,
client_tr_id,
))
}
/// Creates a new EppObject for domain create corresponding to the &lt;epp&gt; tag in EPP XML
/// without any nameservers
pub fn new(
name: &str,
period: u16,
registrant_id: &str,
auth_password: &str,
contacts: Vec<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreate {
let domain_create = DomainCreateRequest {
domain: DomainCreateRequestData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
period: Period::new(period),
ns: None,
registrant: Some(registrant_id.into()),
auth_info: DomainAuthInfo::new(auth_password),
contacts: Some(contacts),
},
};
EppObject::build(Command::<DomainCreateRequest>::new(
domain_create,
client_tr_id,
))
}
/// Creates a new EppObject for domain create corresponding to the &lt;epp&gt; tag in EPP XML
/// without any contacts
pub fn new_without_contacts(
name: &str,
period: u16,
auth_password: &str,
client_tr_id: &str,
) -> EppDomainCreate {
let domain_create = DomainCreateRequest {
domain: DomainCreateRequestData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
period: Period::new(period),
ns: None,
registrant: None,
auth_info: DomainAuthInfo::new(auth_password),
contacts: None,
},
};
EppObject::build(Command::<DomainCreateRequest>::new(
domain_create,
client_tr_id,
))
}
/// Creates a new EppObject for domain create corresponding to the &lt;epp&gt; tag in EPP XML
/// with the &lt;ns&gt; tag containing &lt;hostAttr&gt; tags
pub fn new_with_host_attr(
name: &str,
period: u16,
ns: Vec<HostAttr>,
registrant_id: &str,
auth_password: &str,
contacts: Vec<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreate {
let domain_create = DomainCreateRequest {
domain: DomainCreateRequestData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
period: Period::new(period),
ns: Some(HostList::HostAttrList(HostAttrList { hosts: ns })),
registrant: Some(registrant_id.into()),
auth_info: DomainAuthInfo::new(auth_password),
contacts: Some(contacts),
},
};
EppObject::build(Command::<DomainCreateRequest>::new(
domain_create,
client_tr_id,
))
}
}
/// Type that represents the &lt;epp&gt; tag for the EPP XML domain create response
pub type EppDomainCreateResponse = EppObject<CommandResponse<DomainCreateResponse>>;
// Request
/// Type for elements under the domain &lt;create&gt; tag /// Type for elements under the domain &lt;create&gt; tag
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct DomainCreateData { pub struct DomainCreateRequestData {
/// XML namespace for domain commands /// XML namespace for domain commands
#[serde(rename = "xmlns:domain", alias = "xmlns")] #[serde(rename = "xmlns:domain", alias = "xmlns")]
xmlns: String, xmlns: String,
@ -108,112 +228,36 @@ pub struct DomainCreateData {
#[derive(Serialize, Deserialize, Debug, ElementName)] #[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "create")] #[element_name(name = "create")]
/// Type for EPP XML &lt;create&gt; command for domains /// Type for EPP XML &lt;create&gt; command for domains
pub struct DomainCreate { pub struct DomainCreateRequest {
/// The data for the domain to be created with /// The data for the domain to be created with
/// T being the type of nameserver list (`HostObjList` or `HostAttrList`) /// T being the type of nameserver list (`HostObjList` or `HostAttrList`)
/// to be supplied /// to be supplied
#[serde(rename = "domain:create", alias = "create")] #[serde(rename = "domain:create", alias = "create")]
domain: DomainCreateData, domain: DomainCreateRequestData,
} }
impl EppDomainCreate { // Response
/// Creates a new EppObject for domain create corresponding to the &lt;epp&gt; tag in EPP XML
/// with the &lt;ns&gt; tag containing &lt;hostObj&gt; tags
pub fn new_with_ns(
name: &str,
period: u16,
ns: &[&str],
registrant_id: &str,
auth_password: &str,
contacts: Vec<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreate {
let ns_list = ns.iter().map(|&n| n.into()).collect();
let domain_create = DomainCreate { /// Type that represents the &lt;chkData&gt; tag for domain create response
domain: DomainCreateData { #[derive(Serialize, Deserialize, Debug)]
xmlns: EPP_DOMAIN_XMLNS.to_string(), pub struct DomainCreateResponseData {
name: name.into(), /// XML namespace for domain response data
period: Period::new(period), #[serde(rename = "xmlns:domain")]
ns: Some(HostList::HostObjList(HostObjList { hosts: ns_list })), xmlns: String,
registrant: Some(registrant_id.into()), /// The domain name
auth_info: DomainAuthInfo::new(auth_password), pub name: StringValue,
contacts: Some(contacts), /// The creation date
}, #[serde(rename = "crDate")]
}; pub created_at: StringValue,
/// The expiry date
EppObject::build(Command::<DomainCreate>::new(domain_create, client_tr_id)) #[serde(rename = "exDate")]
pub expiring_at: StringValue,
} }
/// Creates a new EppObject for domain create corresponding to the &lt;epp&gt; tag in EPP XML /// Type that represents the &lt;resData&gt; tag for domain create response
/// without any nameservers #[derive(Serialize, Deserialize, Debug)]
pub fn new( pub struct DomainCreateResponse {
name: &str, /// Data under the &lt;chkData&gt; tag
period: u16, #[serde(rename = "creData")]
registrant_id: &str, pub create_data: DomainCreateResponseData,
auth_password: &str,
contacts: Vec<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreate {
let domain_create = DomainCreate {
domain: DomainCreateData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
period: Period::new(period),
ns: None,
registrant: Some(registrant_id.into()),
auth_info: DomainAuthInfo::new(auth_password),
contacts: Some(contacts),
},
};
EppObject::build(Command::<DomainCreate>::new(domain_create, client_tr_id))
}
/// Creates a new EppObject for domain create corresponding to the &lt;epp&gt; tag in EPP XML
/// without any contacts
pub fn new_without_contacts(
name: &str,
period: u16,
auth_password: &str,
client_tr_id: &str,
) -> EppDomainCreate {
let domain_create = DomainCreate {
domain: DomainCreateData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
period: Period::new(period),
ns: None,
registrant: None,
auth_info: DomainAuthInfo::new(auth_password),
contacts: None,
},
};
EppObject::build(Command::<DomainCreate>::new(domain_create, client_tr_id))
}
/// Creates a new EppObject for domain create corresponding to the &lt;epp&gt; tag in EPP XML
/// with the &lt;ns&gt; tag containing &lt;hostAttr&gt; tags
pub fn new_with_host_attr(
name: &str,
period: u16,
ns: Vec<HostAttr>,
registrant_id: &str,
auth_password: &str,
contacts: Vec<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreate {
let domain_create = DomainCreate {
domain: DomainCreateData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
period: Period::new(period),
ns: Some(HostList::HostAttrList(HostAttrList { hosts: ns })),
registrant: Some(registrant_id.into()),
auth_info: DomainAuthInfo::new(auth_password),
contacts: Some(contacts),
},
};
EppObject::build(Command::<DomainCreate>::new(domain_create, client_tr_id))
}
} }

View File

@ -10,7 +10,6 @@ pub use request::contact::create::*;
pub use request::contact::delete::*; pub use request::contact::delete::*;
pub use request::contact::info::*; pub use request::contact::info::*;
pub use request::contact::update::*; pub use request::contact::update::*;
pub use request::domain::create::*;
pub use request::domain::delete::*; pub use request::domain::delete::*;
pub use request::domain::info::*; pub use request::domain::info::*;
pub use request::domain::renew::*; pub use request::domain::renew::*;
@ -31,7 +30,6 @@ pub use response::contact::create::*;
pub use response::contact::delete::*; pub use response::contact::delete::*;
pub use response::contact::info::*; pub use response::contact::info::*;
pub use response::contact::update::*; pub use response::contact::update::*;
pub use response::domain::create::*;
pub use response::domain::delete::*; pub use response::domain::delete::*;
pub use response::domain::info::*; pub use response::domain::info::*;
pub use response::domain::renew::*; pub use response::domain::renew::*;

View File

@ -1,6 +1,5 @@
//! Types for EPP domain requests //! Types for EPP domain requests
pub mod create;
pub mod delete; pub mod delete;
pub mod info; pub mod info;
pub mod renew; pub mod renew;

View File

@ -1,6 +1,5 @@
//! Types for EPP domain responses //! Types for EPP domain responses
pub mod create;
pub mod delete; pub mod delete;
pub mod info; pub mod info;
pub mod renew; pub mod renew;

View File

@ -1,33 +0,0 @@
//! Types for EPP domain create response
use serde::{Deserialize, Serialize};
use crate::epp::object::{EppObject, StringValue};
use crate::epp::response::CommandResponse;
/// Type that represents the &lt;epp&gt; tag for the EPP XML domain create response
pub type EppDomainCreateResponse = EppObject<CommandResponse<DomainCreateResult>>;
/// Type that represents the &lt;chkData&gt; tag for domain create response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCreateData {
/// XML namespace for domain response data
#[serde(rename = "xmlns:domain")]
xmlns: String,
/// The domain name
pub name: StringValue,
/// The creation date
#[serde(rename = "crDate")]
pub created_at: StringValue,
/// The expiry date
#[serde(rename = "exDate")]
pub expiring_at: StringValue,
}
/// Type that represents the &lt;resData&gt; tag for domain create response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCreateResult {
/// Data under the &lt;chkData&gt; tag
#[serde(rename = "creData")]
pub create_data: DomainCreateData,
}

View File

@ -4,6 +4,7 @@ mod response {
use super::super::get_xml; use super::super::get_xml;
use super::super::CLTRID; use super::super::CLTRID;
use crate::domain::check::EppDomainCheckResponse; use crate::domain::check::EppDomainCheckResponse;
use crate::domain::create::EppDomainCreateResponse;
use crate::epp::response::ExpiryType; use crate::epp::response::ExpiryType;
use crate::epp::response::Relative; use crate::epp::response::Relative;
use crate::epp::response::{ use crate::epp::response::{

View File

@ -4,6 +4,7 @@ mod request {
use super::super::get_xml; use super::super::get_xml;
use super::super::CLTRID; use super::super::CLTRID;
use crate::domain::check::EppDomainCheck; use crate::domain::check::EppDomainCheck;
use crate::domain::create::EppDomainCreate;
use crate::epp::object::data::{ use crate::epp::object::data::{
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr, Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
HostStatus, Phone, PostalInfo, HostStatus, Phone, PostalInfo,