added domain creation call

This commit is contained in:
Ritesh Chitlangi 2021-07-23 02:41:22 +08:00
parent b8b1d06d76
commit 5f0a5092a5
8 changed files with 212 additions and 10 deletions

View File

@ -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::<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());
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;
}

View File

@ -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")]

View File

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

View File

@ -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<T> = EppObject<Command<DomainCreate<T>>>;
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<HostAttr>,
}
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::<Vec<HostAttr>>();
HostAttrList { hosts: ns_list }
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct HostObjList {
#[serde(rename = "hostObj")]
hosts: Vec<StringValue>,
}
impl HostList for HostObjList {
fn new(ns: Vec<&str>) -> HostObjList {
let ns_list = ns
.iter()
.map(|n| n.to_string_value())
.collect::<Vec<StringValue>>();
HostObjList { hosts: ns_list }
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainData<T> {
xmlns: String,
name: StringValue,
period: Period,
ns: Option<T>,
registrant: StringValue,
#[serde(rename = "contact")]
contacts: Vec<DomainContact>,
#[serde(rename = "authInfo")]
auth_info: AuthInfo,
}
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "create")]
pub struct DomainCreate<T> {
#[serde(rename = "create")]
domain: DomainData<T>,
}
impl<T: HostList> EppDomainCreate<T> {
pub fn new(
name: &str,
period: u16,
ns: Vec<&str>,
registrant_id: &str,
auth_password: &str,
contacts: Vec<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreate<T> {
EppObject::build(Command::<DomainCreate<T>> {
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<DomainContact>,
client_tr_id: &str,
) -> EppDomainCreate<T> {
EppObject::build(Command::<DomainCreate<T>> {
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(),
})
}
}

View File

@ -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<ContactCheckDataItem>,

View File

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

View File

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

View File

@ -0,0 +1,22 @@
use serde::{Deserialize, Serialize};
use crate::epp::object::{EppObject, StringValue};
use crate::epp::response::CommandResponse;
pub type EppDomainCheckResponse = EppObject<CommandResponse<DomainCheckResult>>;
#[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,
}