From 5f0a5092a5347366298a4282dda84f3589ef917f Mon Sep 17 00:00:00 2001 From: Ritesh Chitlangi Date: Fri, 23 Jul 2021 02:41:22 +0800 Subject: [PATCH] added domain creation call --- epp-client/examples/client.rs | 37 ++++- epp-client/src/epp/object/data.rs | 20 +++ epp-client/src/epp/request/domain.rs | 1 + epp-client/src/epp/request/domain/create.rs | 139 ++++++++++++++++++ epp-client/src/epp/response/contact/check.rs | 1 - epp-client/src/epp/response/contact/create.rs | 1 - epp-client/src/epp/response/contact/info.rs | 1 - epp-client/src/epp/response/domain/create.rs | 22 +++ 8 files changed, 212 insertions(+), 10 deletions(-) create mode 100644 epp-client/src/epp/request/domain/create.rs create mode 100644 epp-client/src/epp/response/domain/create.rs diff --git a/epp-client/examples/client.rs b/epp-client/examples/client.rs index bd7fde6..ff407ae 100644 --- a/epp-client/examples/client.rs +++ b/epp-client/examples/client.rs @@ -1,4 +1,5 @@ use epp_client::{epp::request::generate_client_tr_id, connection::client::EppClient, connection, epp::xml::EppXml}; +use epp_client::epp::object::StringValueTrait; use epp_client::epp::object::data::ContactStatus; use epp_client::epp::request::domain::check::EppDomainCheck; use epp_client::epp::response::domain::check::EppDomainCheckResponse; @@ -13,6 +14,10 @@ use epp_client::epp::request::contact::update::EppContactUpdate; use epp_client::epp::response::contact::update::EppContactUpdateResponse; use epp_client::epp::request::contact::delete::EppContactDelete; use epp_client::epp::response::contact::delete::EppContactDeleteResponse; +use epp_client::epp::request::domain::create::DomainContact; +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) { let domains = vec!["eppdev.com", "hexonet.net"]; @@ -72,6 +77,22 @@ async fn delete_contact(client: &mut EppClient) { client.transact::<_, EppContactDeleteResponse>(&contact_delete).await.unwrap(); } +async fn create_domain() { + let contacts = vec![ + DomainContact { + contact_type: "tech".to_string(), + id: "eppdev-contact-1".to_string() + }, + DomainContact { + contact_type: "billing".to_string(), + id: "eppdev-contact-1".to_string() + } + ]; + let domain_create = EppDomainCreate::::new("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()); +} + async fn hello(client: &mut EppClient) { let greeting = client.hello().await.unwrap(); @@ -80,13 +101,13 @@ async fn hello(client: &mut EppClient) { #[tokio::main] async fn main() { - let mut client = match EppClient::new("hexonet").await { - Ok(client) => { - println!("{:?}", client.greeting()); - client - }, - Err(e) => panic!("Error: {}", e) - }; + // let mut client = match EppClient::new("hexonet").await { + // Ok(client) => { + // println!("{:?}", client.greeting()); + // client + // }, + // Err(e) => panic!("Error: {}", e) + // }; // hello(&mut client).await; @@ -101,4 +122,6 @@ async fn main() { // update_contact(&mut client).await; // delete_contact(&mut client).await; + + // create_domain().await; } diff --git a/epp-client/src/epp/object/data.rs b/epp-client/src/epp/object/data.rs index d5a855f..93de1fc 100644 --- a/epp-client/src/epp/object/data.rs +++ b/epp-client/src/epp/object/data.rs @@ -1,6 +1,26 @@ use crate::epp::object::{StringValue, StringValueTrait}; use serde::{Deserialize, Serialize}; +#[derive(Serialize, Deserialize, Debug)] +pub struct Period { + unit: String, + #[serde(rename = "$value")] + length: u16, +} + +impl Period { + pub fn new(length: u16) -> Period { + Period { + unit: "y".to_string(), + length: length, + } + } + + pub fn set_unit(&mut self, unit: &str) { + self.unit = unit.to_string(); + } +} + #[derive(Serialize, Deserialize, Debug)] pub struct ContactStatus { #[serde(rename = "s")] diff --git a/epp-client/src/epp/request/domain.rs b/epp-client/src/epp/request/domain.rs index 3e8ff0f..3aa3078 100644 --- a/epp-client/src/epp/request/domain.rs +++ b/epp-client/src/epp/request/domain.rs @@ -1 +1,2 @@ pub mod check; +pub mod create; diff --git a/epp-client/src/epp/request/domain/create.rs b/epp-client/src/epp/request/domain/create.rs new file mode 100644 index 0000000..569281c --- /dev/null +++ b/epp-client/src/epp/request/domain/create.rs @@ -0,0 +1,139 @@ +use epp_client_macros::*; + +use crate::epp::command::Command; +use crate::epp::object::data::{AuthInfo, Period}; +use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait}; +use crate::epp::xml::EPP_DOMAIN_XMLNS; +use serde::{Deserialize, Serialize}; + +pub type EppDomainCreate = EppObject>>; + +pub enum HostType { + HostObj, + HostAttr, +} + +pub trait HostList { + 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)] +pub struct HostAttr { + #[serde(rename = "hostName")] + host_name: StringValue, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct HostAttrList { + #[serde(rename = "hostAttr")] + hosts: Vec, +} + +impl HostList for HostAttrList { + fn new(ns: Vec<&str>) -> HostAttrList { + let ns_list = ns + .iter() + .map(|n| HostAttr { + host_name: n.to_string_value(), + }) + .collect::>(); + + HostAttrList { hosts: ns_list } + } +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct HostObjList { + #[serde(rename = "hostObj")] + hosts: Vec, +} + +impl HostList for HostObjList { + fn new(ns: Vec<&str>) -> HostObjList { + let ns_list = ns + .iter() + .map(|n| n.to_string_value()) + .collect::>(); + + HostObjList { hosts: ns_list } + } +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct DomainData { + xmlns: String, + name: StringValue, + period: Period, + ns: Option, + registrant: StringValue, + #[serde(rename = "contact")] + contacts: Vec, + #[serde(rename = "authInfo")] + auth_info: AuthInfo, +} + +#[derive(Serialize, Deserialize, Debug, ElementName)] +#[element_name(name = "create")] +pub struct DomainCreate { + #[serde(rename = "create")] + domain: DomainData, +} + +impl EppDomainCreate { + pub fn new( + name: &str, + period: u16, + ns: Vec<&str>, + registrant_id: &str, + auth_password: &str, + contacts: Vec, + client_tr_id: &str, + ) -> EppDomainCreate { + EppObject::build(Command::> { + command: DomainCreate { + domain: DomainData { + xmlns: EPP_DOMAIN_XMLNS.to_string(), + name: name.to_string_value(), + period: Period::new(period), + ns: Some(T::new(ns)), + registrant: registrant_id.to_string_value(), + auth_info: AuthInfo::new(auth_password), + contacts: contacts, + }, + }, + client_tr_id: client_tr_id.to_string_value(), + }) + } + + pub fn new_without_ns( + name: &str, + period: u16, + registrant_id: &str, + auth_password: &str, + contacts: Vec, + client_tr_id: &str, + ) -> EppDomainCreate { + EppObject::build(Command::> { + command: DomainCreate { + domain: DomainData { + xmlns: EPP_DOMAIN_XMLNS.to_string(), + name: name.to_string_value(), + period: Period::new(period), + ns: None, + registrant: registrant_id.to_string_value(), + auth_info: AuthInfo::new(auth_password), + contacts: contacts, + }, + }, + client_tr_id: client_tr_id.to_string_value(), + }) + } +} diff --git a/epp-client/src/epp/response/contact/check.rs b/epp-client/src/epp/response/contact/check.rs index 82d6d5d..8415294 100644 --- a/epp-client/src/epp/response/contact/check.rs +++ b/epp-client/src/epp/response/contact/check.rs @@ -21,7 +21,6 @@ pub struct ContactCheckDataItem { #[derive(Serialize, Deserialize, Debug)] pub struct ContactCheckData { - #[serde(rename = "xmlns:contact")] xmlns: String, #[serde(rename = "cd")] pub contact_list: Vec, diff --git a/epp-client/src/epp/response/contact/create.rs b/epp-client/src/epp/response/contact/create.rs index 62f2d27..45f57b0 100644 --- a/epp-client/src/epp/response/contact/create.rs +++ b/epp-client/src/epp/response/contact/create.rs @@ -7,7 +7,6 @@ pub type EppContactCreateResponse = EppObject>; #[derive(Serialize, Deserialize, Debug)] pub struct ContactInfoData { - #[serde(rename = "xmlns:contact")] xmlns: String, pub id: StringValue, pub roid: StringValue, diff --git a/epp-client/src/epp/response/domain/create.rs b/epp-client/src/epp/response/domain/create.rs new file mode 100644 index 0000000..ce572d8 --- /dev/null +++ b/epp-client/src/epp/response/domain/create.rs @@ -0,0 +1,22 @@ +use serde::{Deserialize, Serialize}; + +use crate::epp::object::{EppObject, StringValue}; +use crate::epp::response::CommandResponse; + +pub type EppDomainCheckResponse = EppObject>; + +#[derive(Serialize, Deserialize, Debug)] +pub struct DomainCreateData { + xmlns: String, + name: StringValue, + #[serde(rename = "crDate")] + created_at: StringValue, + #[serde(rename = "exDate")] + expiry_date: StringValue, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct DomainCreateResult { + #[serde(rename = "creData")] + pub create_data: DomainCreateData, +}