logout and login added to connection initialization
This commit is contained in:
parent
6f9f526385
commit
0ced95dee7
|
@ -10,7 +10,7 @@ use tokio::{net::TcpStream, io::AsyncWriteExt, io::AsyncReadExt, io::split, io::
|
|||
|
||||
use crate::config::{CONFIG, EppClientConnection};
|
||||
use crate::error;
|
||||
use crate::epp::request::{EppRequest, Login};
|
||||
use crate::epp::request::{EppRequest, Login, Logout};
|
||||
use crate::epp::xml::EppXml;
|
||||
|
||||
pub struct ConnectionStream {
|
||||
|
@ -142,8 +142,8 @@ impl EppClient {
|
|||
credentials: credentials
|
||||
};
|
||||
|
||||
let client_trid = EppRequest::generate_client_trid(&client.credentials.0)?;
|
||||
let login_request = Login::new(&client.credentials.0, &client.credentials.1, client_trid.as_str());
|
||||
let client_tr_id = EppRequest::generate_client_tr_id(&client.credentials.0)?;
|
||||
let login_request = Login::new(&client.credentials.0, &client.credentials.1, client_tr_id.as_str());
|
||||
|
||||
client.transact(&login_request).await?;
|
||||
|
||||
|
@ -168,6 +168,19 @@ impl EppClient {
|
|||
pub fn greeting(&self) -> String {
|
||||
return String::from(&self.connection.greeting)
|
||||
}
|
||||
|
||||
pub async fn logout(&mut self) {
|
||||
let client_tr_id = EppRequest::generate_client_tr_id(&self.credentials.0).unwrap();
|
||||
let epp_logout = Logout::new(client_tr_id.as_str());
|
||||
|
||||
self.transact(&epp_logout).await;
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for EppClient {
|
||||
fn drop(&mut self) {
|
||||
block_on(self.logout());
|
||||
}
|
||||
}
|
||||
|
||||
async fn epp_connect(registry_creds: &EppClientConnection) -> Result<ConnectionStream, error::Error> {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub mod object;
|
||||
pub mod quick_xml;
|
||||
pub mod request;
|
||||
pub mod xml;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
#[serde(rename = "epp")]
|
||||
pub struct EppObject<T> {
|
||||
pub xmlns: String,
|
||||
#[serde(rename = "xmlns:xsi")]
|
||||
pub xmlns_xsi: String,
|
||||
#[serde(rename = "xsi:schemaLocation")]
|
||||
pub xsi_schema_location: String,
|
||||
pub data: T,
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
use quick_xml::se;
|
||||
use serde::Serialize;
|
||||
use std::error::Error;
|
||||
|
||||
use crate::epp::request::EppObject;
|
||||
use crate::epp::object::EppObject;
|
||||
use crate::epp::xml::{EppXml, EPP_XML_HEADER};
|
||||
|
||||
impl EppXml for EppObject {
|
||||
impl<T: Serialize> EppXml for EppObject<T> {
|
||||
fn serialize(&self) -> Result<String, Box<dyn Error>> {
|
||||
let epp_xml = format!("{}\r\n{}", EPP_XML_HEADER, se::to_string(self)?);
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ use serde::{Deserialize, Serialize};
|
|||
use std::error::Error;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::epp::object::EppObject;
|
||||
|
||||
const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0";
|
||||
const EPP_XMLNS_XSI: &str = "http://www.w3.org/2001/XMLSchema-instance";
|
||||
const EPP_XSI_SCHEMA_LOCATION: &str = "urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd";
|
||||
|
@ -37,21 +39,16 @@ pub enum RequestType {
|
|||
#[serde(rename = "clTRID")]
|
||||
client_tr_id: StringValue,
|
||||
},
|
||||
#[serde(rename = "command")]
|
||||
CommandLogout {
|
||||
logout: Logout,
|
||||
#[serde(rename = "clTRID")]
|
||||
client_tr_id: StringValue,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
#[serde(rename = "epp")]
|
||||
pub struct EppObject {
|
||||
xmlns: String,
|
||||
#[serde(rename = "xmlns:xsi")]
|
||||
xmlns_xsi: String,
|
||||
#[serde(rename = "xsi:schemaLocation")]
|
||||
xsi_schema_location: String,
|
||||
data: RequestType,
|
||||
}
|
||||
|
||||
impl EppObject {
|
||||
pub fn new(data: RequestType) -> EppObject {
|
||||
impl<RequestType> EppObject<RequestType> {
|
||||
pub fn new(data: RequestType) -> EppObject<RequestType> {
|
||||
EppObject {
|
||||
data: data,
|
||||
xmlns: EPP_XMLNS.to_string(),
|
||||
|
@ -60,13 +57,13 @@ impl EppObject {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn generate_client_trid(username: &str) -> Result<String, Box<dyn Error>> {
|
||||
pub fn generate_client_tr_id(username: &str) -> Result<String, Box<dyn Error>> {
|
||||
let timestamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
|
||||
Ok(format!("{}:{}", username, timestamp.as_secs()))
|
||||
}
|
||||
}
|
||||
|
||||
pub type EppRequest = EppObject;
|
||||
pub type EppRequest = EppObject<RequestType>;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
|
@ -165,3 +162,16 @@ impl Login {
|
|||
self.services = services;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub struct Logout;
|
||||
|
||||
impl Logout {
|
||||
pub fn new(client_tr_id: &str) -> EppRequest {
|
||||
EppRequest::new(RequestType::CommandLogout {
|
||||
logout: Logout,
|
||||
client_tr_id: client_tr_id.to_string_value(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
|
Loading…
Reference in New Issue