tested domain creation call

This commit is contained in:
Ritesh Chitlangi 2021-07-23 14:07:40 +08:00
parent 5f0a5092a5
commit 5c9afa665b
11 changed files with 137 additions and 61 deletions

View File

@ -1,29 +1,26 @@
use epp_client::{epp::request::generate_client_tr_id, connection::client::EppClient, connection, epp::xml::EppXml}; use epp_client::EppClient;
use epp_client::epp::object::StringValueTrait; use epp_client::{epp::request::generate_client_tr_id, epp::xml::EppXml};
use epp_client::epp::object::data::ContactStatus; use epp_client::epp::object::data::{PostalInfo, Address, Phone, DomainContact, ContactStatus};
use epp_client::epp::request::domain::check::EppDomainCheck; use epp_client::epp::EppDomainCheck;
use epp_client::epp::response::domain::check::EppDomainCheckResponse; use epp_client::epp::EppDomainCheckResponse;
use epp_client::epp::request::contact::check::EppContactCheck; use epp_client::epp::EppContactCheck;
use epp_client::epp::response::contact::check::EppContactCheckResponse; use epp_client::epp::EppContactCheckResponse;
use epp_client::epp::object::data::{PostalInfo, Address, Phone}; use epp_client::epp::EppContactCreate;
use epp_client::epp::request::contact::create::EppContactCreate; use epp_client::epp::EppContactCreateResponse;
use epp_client::epp::response::contact::create::EppContactCreateResponse; use epp_client::epp::EppContactInfo;
use epp_client::epp::request::contact::info::EppContactInfo; use epp_client::epp::EppContactInfoResponse;
use epp_client::epp::response::contact::info::EppContactInfoResponse; use epp_client::epp::EppContactUpdate;
use epp_client::epp::request::contact::update::EppContactUpdate; use epp_client::epp::EppContactUpdateResponse;
use epp_client::epp::response::contact::update::EppContactUpdateResponse; use epp_client::epp::EppContactDelete;
use epp_client::epp::request::contact::delete::EppContactDelete; use epp_client::epp::EppContactDeleteResponse;
use epp_client::epp::response::contact::delete::EppContactDeleteResponse; use epp_client::epp::EppDomainCreate;
use epp_client::epp::request::domain::create::DomainContact; use epp_client::epp::EppDomainCreateResponse;
use epp_client::epp::request::domain::create::{HostObjList, HostAttrList};
use epp_client::epp::request::domain::create::EppDomainCreate;
//use epp_client::epp::response::domain::create::EppDomainCreateResponse;
async fn check_domains(client: &mut EppClient) { async fn check_domains(client: &mut EppClient) {
let domains = vec!["eppdev.com", "hexonet.net"]; let domains = vec!["eppdev.com", "hexonet.net"];
let domain_check = EppDomainCheck::new(domains, generate_client_tr_id("eppdev").unwrap().as_str()); let domain_check = EppDomainCheck::new(domains, generate_client_tr_id("eppdev").unwrap().as_str());
client.transact::<EppDomainCheck, EppDomainCheckResponse>(&domain_check).await.unwrap(); client.transact::<_, EppDomainCheckResponse>(&domain_check).await.unwrap();
} }
async fn check_contacts(client: &mut EppClient) { async fn check_contacts(client: &mut EppClient) {
@ -42,7 +39,7 @@ async fn create_contact(client: &mut EppClient) {
let mut fax = Phone::new("+47.86698799"); let mut fax = Phone::new("+47.86698799");
fax.set_extension("677"); fax.set_extension("677");
let mut contact_create = EppContactCreate::new("eppdev-contact-1", "contact@eppdev.net", postal_info, voice, "eppdev-387323", generate_client_tr_id("eppdev").unwrap().as_str()); let mut contact_create = EppContactCreate::new("eppdev-contact-2", "contact@eppdev.net", postal_info, voice, "eppdev-387323", generate_client_tr_id("eppdev").unwrap().as_str());
contact_create.set_fax(fax); contact_create.set_fax(fax);
// println!("xml: {}", contact_create.serialize().unwrap()); // println!("xml: {}", contact_create.serialize().unwrap());
@ -66,7 +63,7 @@ async fn update_contact(client: &mut EppClient) {
} }
async fn query_contact(client: &mut EppClient) { async fn query_contact(client: &mut EppClient) {
let mut contact_info = EppContactInfo::new("eppdev-contact-1", "eppdev-387323", generate_client_tr_id("eppdev").unwrap().as_str()); let mut contact_info = EppContactInfo::new("eppdev-contact-2", "eppdev-387323", generate_client_tr_id("eppdev").unwrap().as_str());
client.transact::<_, EppContactInfoResponse>(&contact_info).await.unwrap(); client.transact::<_, EppContactInfoResponse>(&contact_info).await.unwrap();
} }
@ -77,20 +74,28 @@ async fn delete_contact(client: &mut EppClient) {
client.transact::<_, EppContactDeleteResponse>(&contact_delete).await.unwrap(); client.transact::<_, EppContactDeleteResponse>(&contact_delete).await.unwrap();
} }
async fn create_domain() { async fn create_domain(client: &mut EppClient) {
let contacts = vec![ let contacts = vec![
DomainContact {
contact_type: "admin".to_string(),
id: "eppdev-contact-2".to_string()
},
DomainContact { DomainContact {
contact_type: "tech".to_string(), contact_type: "tech".to_string(),
id: "eppdev-contact-1".to_string() id: "eppdev-contact-2".to_string()
}, },
DomainContact { DomainContact {
contact_type: "billing".to_string(), contact_type: "billing".to_string(),
id: "eppdev-contact-1".to_string() id: "eppdev-contact-2".to_string()
} }
]; ];
let domain_create = EppDomainCreate::<HostAttrList>::new("eppdev.com", 1, vec!["ns1.test.com", "ns2.test.com"], "eppdev-contact-1", "eppdevauth123", contacts, generate_client_tr_id("eppdev").unwrap().as_str()); // let domain_create = EppDomainCreate::new_with_ns("eppdev.com", 1, vec!["ns1.test.com", "ns2.test.com"], "eppdev-contact-1", "eppdevauth123", contacts, generate_client_tr_id("eppdev").unwrap().as_str());
println!("{}", domain_create.serialize().unwrap()); let domain_create = EppDomainCreate::new("eppdev.com", 1, "eppdev-contact-2", "epP4uthd#v", contacts, generate_client_tr_id("eppdev").unwrap().as_str());
// println!("{}", domain_create.serialize().unwrap());
client.transact::<_, EppDomainCreateResponse>(&domain_create).await.unwrap();
} }
async fn hello(client: &mut EppClient) { async fn hello(client: &mut EppClient) {
@ -101,13 +106,13 @@ async fn hello(client: &mut EppClient) {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
// let mut client = match EppClient::new("hexonet").await { let mut client = match EppClient::new("hexonet").await {
// Ok(client) => { Ok(client) => {
// println!("{:?}", client.greeting()); println!("{:?}", client.greeting());
// client client
// }, },
// Err(e) => panic!("Error: {}", e) Err(e) => panic!("Error: {}", e)
// }; };
// hello(&mut client).await; // hello(&mut client).await;
@ -123,5 +128,5 @@ async fn main() {
// delete_contact(&mut client).await; // delete_contact(&mut client).await;
// create_domain().await; // create_domain(&mut client).await;
} }

View File

@ -8,6 +8,7 @@ use crate::error;
use crate::epp::request::{generate_client_tr_id, EppHello, EppLogin, EppLogout}; use crate::epp::request::{generate_client_tr_id, EppHello, EppLogin, EppLogout};
use crate::epp::response::{EppGreeting, EppCommandResponseStatus, EppCommandResponse, EppCommandResponseError}; use crate::epp::response::{EppGreeting, EppCommandResponseStatus, EppCommandResponse, EppCommandResponseError};
use crate::epp::xml::EppXml; use crate::epp::xml::EppXml;
use crate::epp::object::{ElementName, EppObject};
async fn connect(registry: &'static str) -> Result<EppClient, Box<dyn Error>> { async fn connect(registry: &'static str) -> Result<EppClient, Box<dyn Error>> {
let registry_creds = match CONFIG.registry(registry) { let registry_creds = match CONFIG.registry(registry) {

View File

@ -4,3 +4,18 @@ pub mod quick_xml;
pub mod request; pub mod request;
pub mod response; pub mod response;
pub mod xml; pub mod xml;
pub use request::contact::check::*;
pub use request::contact::create::*;
pub use request::contact::delete::*;
pub use request::contact::info::*;
pub use request::contact::update::*;
pub use request::domain::check::*;
pub use request::domain::create::*;
pub use response::contact::check::*;
pub use response::contact::create::*;
pub use response::contact::delete::*;
pub use response::contact::info::*;
pub use response::contact::update::*;
pub use response::domain::check::*;
pub use response::domain::create::*;

View File

@ -1,6 +1,14 @@
use crate::epp::object::{StringValue, StringValueTrait}; use crate::epp::object::{StringValue, StringValueTrait};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainContact {
#[serde(rename = "$value")]
pub id: String,
#[serde(rename = "type")]
pub contact_type: String,
}
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Period { pub struct Period {
unit: String, unit: String,

View File

@ -1,12 +1,13 @@
use epp_client_macros::*; use epp_client_macros::*;
use crate::epp::command::Command; use crate::epp::command::Command;
use crate::epp::object::data::{AuthInfo, Period}; use crate::epp::object::data::{AuthInfo, DomainContact, Period};
use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait}; use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait};
use crate::epp::xml::EPP_DOMAIN_XMLNS; use crate::epp::xml::EPP_DOMAIN_XMLNS;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub type EppDomainCreate<T> = EppObject<Command<DomainCreate<T>>>; pub type EppDomainCreate = EppObject<Command<DomainCreate<HostObjList>>>;
pub type EppDomainCreateWithHostAttr = EppObject<Command<DomainCreate<HostAttrList>>>;
pub enum HostType { pub enum HostType {
HostObj, HostObj,
@ -17,14 +18,6 @@ pub trait HostList {
fn new(ns: Vec<&str>) -> Self; fn new(ns: Vec<&str>) -> Self;
} }
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainContact {
#[serde(rename = "$value")]
pub id: String,
#[serde(rename = "type")]
pub contact_type: String,
}
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct HostAttr { pub struct HostAttr {
#[serde(rename = "hostName")] #[serde(rename = "hostName")]
@ -73,9 +66,9 @@ pub struct DomainData<T> {
name: StringValue, name: StringValue,
period: Period, period: Period,
ns: Option<T>, ns: Option<T>,
registrant: StringValue, registrant: Option<StringValue>,
#[serde(rename = "contact")] #[serde(rename = "contact")]
contacts: Vec<DomainContact>, contacts: Option<Vec<DomainContact>>,
#[serde(rename = "authInfo")] #[serde(rename = "authInfo")]
auth_info: AuthInfo, auth_info: AuthInfo,
} }
@ -87,8 +80,8 @@ pub struct DomainCreate<T> {
domain: DomainData<T>, domain: DomainData<T>,
} }
impl<T: HostList> EppDomainCreate<T> { impl EppDomainCreate {
pub fn new( pub fn new_with_ns(
name: &str, name: &str,
period: u16, period: u16,
ns: Vec<&str>, ns: Vec<&str>,
@ -96,41 +89,88 @@ impl<T: HostList> EppDomainCreate<T> {
auth_password: &str, auth_password: &str,
contacts: Vec<DomainContact>, contacts: Vec<DomainContact>,
client_tr_id: &str, client_tr_id: &str,
) -> EppDomainCreate<T> { ) -> EppDomainCreate {
EppObject::build(Command::<DomainCreate<T>> { EppObject::build(Command::<DomainCreate<HostObjList>> {
command: DomainCreate { command: DomainCreate {
domain: DomainData { domain: DomainData {
xmlns: EPP_DOMAIN_XMLNS.to_string(), xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.to_string_value(), name: name.to_string_value(),
period: Period::new(period), period: Period::new(period),
ns: Some(T::new(ns)), ns: Some(HostObjList::new(ns)),
registrant: registrant_id.to_string_value(), registrant: Some(registrant_id.to_string_value()),
auth_info: AuthInfo::new(auth_password), auth_info: AuthInfo::new(auth_password),
contacts: contacts, contacts: Some(contacts),
}, },
}, },
client_tr_id: client_tr_id.to_string_value(), client_tr_id: client_tr_id.to_string_value(),
}) })
} }
pub fn new_without_ns( pub fn new(
name: &str, name: &str,
period: u16, period: u16,
registrant_id: &str, registrant_id: &str,
auth_password: &str, auth_password: &str,
contacts: Vec<DomainContact>, contacts: Vec<DomainContact>,
client_tr_id: &str, client_tr_id: &str,
) -> EppDomainCreate<T> { ) -> EppDomainCreate {
EppObject::build(Command::<DomainCreate<T>> { EppObject::build(Command::<DomainCreate<HostObjList>> {
command: DomainCreate { command: DomainCreate {
domain: DomainData { domain: DomainData {
xmlns: EPP_DOMAIN_XMLNS.to_string(), xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.to_string_value(), name: name.to_string_value(),
period: Period::new(period), period: Period::new(period),
ns: None, ns: None,
registrant: registrant_id.to_string_value(), registrant: Some(registrant_id.to_string_value()),
auth_info: AuthInfo::new(auth_password), auth_info: AuthInfo::new(auth_password),
contacts: contacts, contacts: Some(contacts),
},
},
client_tr_id: client_tr_id.to_string_value(),
})
}
pub fn new_without_contacts(
name: &str,
period: u16,
auth_password: &str,
client_tr_id: &str,
) -> EppDomainCreate {
EppObject::build(Command::<DomainCreate<HostObjList>> {
command: DomainCreate {
domain: DomainData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.to_string_value(),
period: Period::new(period),
ns: None,
registrant: None,
auth_info: AuthInfo::new(auth_password),
contacts: None,
},
},
client_tr_id: client_tr_id.to_string_value(),
})
}
pub fn new_with_host_attr(
name: &str,
period: u16,
ns: Vec<&str>,
registrant_id: &str,
auth_password: &str,
contacts: Vec<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreateWithHostAttr {
EppObject::build(Command::<DomainCreate<HostAttrList>> {
command: DomainCreate {
domain: DomainData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.to_string_value(),
period: Period::new(period),
ns: Some(HostAttrList::new(ns)),
registrant: Some(registrant_id.to_string_value()),
auth_info: AuthInfo::new(auth_password),
contacts: Some(contacts),
}, },
}, },
client_tr_id: client_tr_id.to_string_value(), client_tr_id: client_tr_id.to_string_value(),

View File

@ -21,6 +21,7 @@ pub struct ContactCheckDataItem {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheckData { pub struct ContactCheckData {
#[serde(rename = "xmlns:contact")]
xmlns: String, xmlns: String,
#[serde(rename = "cd")] #[serde(rename = "cd")]
pub contact_list: Vec<ContactCheckDataItem>, pub contact_list: Vec<ContactCheckDataItem>,

View File

@ -7,6 +7,7 @@ pub type EppContactCreateResponse = EppObject<CommandResponse<ContactCreateResul
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct ContactCreateData { pub struct ContactCreateData {
#[serde(rename = "xmlns:contact")]
xmlns: String, xmlns: String,
pub id: StringValue, pub id: StringValue,
#[serde(rename = "crDate")] #[serde(rename = "crDate")]

View File

@ -8,6 +8,7 @@ pub type EppContactInfoResponse = EppObject<CommandResponse<ContactInfoResult>>;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct ContactInfoData { pub struct ContactInfoData {
#[serde(rename = "xmlns:contact")]
xmlns: String, xmlns: String,
pub id: StringValue, pub id: StringValue,
pub roid: StringValue, pub roid: StringValue,

View File

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

View File

@ -3,10 +3,11 @@ use serde::{Deserialize, Serialize};
use crate::epp::object::{EppObject, StringValue}; use crate::epp::object::{EppObject, StringValue};
use crate::epp::response::CommandResponse; use crate::epp::response::CommandResponse;
pub type EppDomainCheckResponse = EppObject<CommandResponse<DomainCheckResult>>; pub type EppDomainCreateResponse = EppObject<CommandResponse<DomainCreateResult>>;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct DomainCreateData { pub struct DomainCreateData {
#[serde(rename = "xmlns:domain")]
xmlns: String, xmlns: String,
name: StringValue, name: StringValue,
#[serde(rename = "crDate")] #[serde(rename = "crDate")]

View File

@ -3,6 +3,8 @@ pub mod connection;
pub mod epp; pub mod epp;
pub mod error; pub mod error;
pub use connection::client::EppClient;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::config; use super::config;