Refactor Login into login.rs
This commit is contained in:
parent
76f2ca5b16
commit
2745e2b1ca
|
@ -53,10 +53,9 @@ use crate::config::EppClientConfig;
|
|||
use crate::connection::registry::{epp_connect, EppConnection};
|
||||
use crate::error;
|
||||
use crate::hello::{EppGreeting, EppHello};
|
||||
use crate::request::{generate_client_tr_id, EppLogin, EppLogout};
|
||||
use crate::response::{
|
||||
EppCommandResponse, EppCommandResponseError, EppLoginResponse, EppLogoutResponse,
|
||||
};
|
||||
use crate::login::{EppLogin, EppLoginResponse};
|
||||
use crate::request::{generate_client_tr_id, EppLogout};
|
||||
use crate::response::{EppCommandResponse, EppCommandResponseError, EppLogoutResponse};
|
||||
use crate::xml::EppXml;
|
||||
/// Instances of the EppClient type are used to transact with the registry.
|
||||
/// Once initialized, the EppClient instance can serialize EPP requests to XML and send them
|
||||
|
|
|
@ -108,6 +108,7 @@ pub mod domain;
|
|||
pub mod error;
|
||||
pub mod hello;
|
||||
pub mod host;
|
||||
pub mod login;
|
||||
pub mod message;
|
||||
pub mod request;
|
||||
pub mod response;
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
use epp_client_macros::ElementName;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
common::{ElementName, EppObject, Options, ServiceExtension, Services, StringValue},
|
||||
contact::EPP_CONTACT_XMLNS,
|
||||
domain::EPP_DOMAIN_XMLNS,
|
||||
host::EPP_HOST_XMLNS,
|
||||
request::{Command, EPP_LANG, EPP_VERSION},
|
||||
response::EppCommandResponse,
|
||||
};
|
||||
|
||||
/// The EPP Login Request
|
||||
pub type EppLogin = EppObject<Command<Login>>;
|
||||
|
||||
impl EppLogin {
|
||||
/// Creates a new EPP Login request
|
||||
pub fn new(
|
||||
username: &str,
|
||||
password: &str,
|
||||
ext_uris: &Option<Vec<String>>,
|
||||
client_tr_id: &str,
|
||||
) -> EppLogin {
|
||||
let ext_uris = ext_uris
|
||||
.as_ref()
|
||||
.map(|uris| uris.iter().map(|u| u.as_str().into()).collect());
|
||||
|
||||
let login = Login {
|
||||
username: username.into(),
|
||||
password: password.into(),
|
||||
options: Options {
|
||||
version: EPP_VERSION.into(),
|
||||
lang: EPP_LANG.into(),
|
||||
},
|
||||
services: Services {
|
||||
obj_uris: vec![
|
||||
EPP_HOST_XMLNS.into(),
|
||||
EPP_CONTACT_XMLNS.into(),
|
||||
EPP_DOMAIN_XMLNS.into(),
|
||||
],
|
||||
svc_ext: Some(ServiceExtension { ext_uris }),
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<Login> {
|
||||
command: login,
|
||||
extension: None,
|
||||
client_tr_id: client_tr_id.into(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Sets the <options> tag data
|
||||
pub fn options(&mut self, options: Options) {
|
||||
self.data.command.options = options;
|
||||
}
|
||||
|
||||
/// Sets the <svcs> tag data
|
||||
pub fn services(&mut self, services: Services) {
|
||||
self.data.command.services = services;
|
||||
}
|
||||
}
|
||||
|
||||
/// An alias of `EppCommandResponse` received in response to a successful login request
|
||||
pub type EppLoginResponse = EppCommandResponse;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
||||
#[element_name(name = "login")]
|
||||
/// Type corresponding to the <login> tag in an EPP XML login request
|
||||
pub struct Login {
|
||||
/// The username to use for the login
|
||||
#[serde(rename(serialize = "clID", deserialize = "clID"))]
|
||||
username: StringValue,
|
||||
/// The password to use for the login
|
||||
#[serde(rename = "pw", default)]
|
||||
password: StringValue,
|
||||
/// Data under the <options> tag
|
||||
options: Options,
|
||||
/// Data under the <svcs> tag
|
||||
#[serde(rename = "svcs")]
|
||||
services: Services,
|
||||
}
|
|
@ -4,16 +4,8 @@ use serde::{ser::SerializeStruct, ser::Serializer, Deserialize, Serialize};
|
|||
use std::error::Error;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::{
|
||||
common::{
|
||||
ElementName, EmptyTag, EppObject, Extension, Options, ServiceExtension, Services,
|
||||
StringValue,
|
||||
},
|
||||
contact::EPP_CONTACT_XMLNS,
|
||||
domain::EPP_DOMAIN_XMLNS,
|
||||
host::EPP_HOST_XMLNS,
|
||||
};
|
||||
use epp_client_macros::*;
|
||||
use crate::common::{ElementName, EmptyTag, EppObject, Extension, StringValue};
|
||||
use epp_client_macros::ElementName;
|
||||
|
||||
pub const EPP_VERSION: &str = "1.0";
|
||||
pub const EPP_LANG: &str = "en";
|
||||
|
@ -22,8 +14,6 @@ pub const EPP_LANG: &str = "en";
|
|||
/// without an <extension> tag
|
||||
pub type Command<T> = CommandWithExtension<T, EmptyTag>;
|
||||
|
||||
/// The EPP Login Request
|
||||
pub type EppLogin = EppObject<Command<Login>>;
|
||||
/// The EPP Logout request
|
||||
pub type EppLogout = EppObject<Command<Logout>>;
|
||||
|
||||
|
@ -84,70 +74,6 @@ pub fn generate_client_tr_id(username: &str) -> Result<String, Box<dyn Error>> {
|
|||
Ok(format!("{}:{}", username, timestamp.as_secs()))
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
||||
#[element_name(name = "login")]
|
||||
/// Type corresponding to the <login> tag in an EPP XML login request
|
||||
pub struct Login {
|
||||
/// The username to use for the login
|
||||
#[serde(rename(serialize = "clID", deserialize = "clID"))]
|
||||
username: StringValue,
|
||||
/// The password to use for the login
|
||||
#[serde(rename = "pw", default)]
|
||||
password: StringValue,
|
||||
/// Data under the <options> tag
|
||||
options: Options,
|
||||
/// Data under the <svcs> tag
|
||||
#[serde(rename = "svcs")]
|
||||
services: Services,
|
||||
}
|
||||
|
||||
impl EppLogin {
|
||||
/// Creates a new EPP Login request
|
||||
pub fn new(
|
||||
username: &str,
|
||||
password: &str,
|
||||
ext_uris: &Option<Vec<String>>,
|
||||
client_tr_id: &str,
|
||||
) -> EppLogin {
|
||||
let ext_uris = ext_uris
|
||||
.as_ref()
|
||||
.map(|uris| uris.iter().map(|u| u.as_str().into()).collect());
|
||||
|
||||
let login = Login {
|
||||
username: username.into(),
|
||||
password: password.into(),
|
||||
options: Options {
|
||||
version: EPP_VERSION.into(),
|
||||
lang: EPP_LANG.into(),
|
||||
},
|
||||
services: Services {
|
||||
obj_uris: vec![
|
||||
EPP_HOST_XMLNS.into(),
|
||||
EPP_CONTACT_XMLNS.into(),
|
||||
EPP_DOMAIN_XMLNS.into(),
|
||||
],
|
||||
svc_ext: Some(ServiceExtension { ext_uris }),
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<Login> {
|
||||
command: login,
|
||||
extension: None,
|
||||
client_tr_id: client_tr_id.into(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Sets the <options> tag data
|
||||
pub fn options(&mut self, options: Options) {
|
||||
self.data.command.options = options;
|
||||
}
|
||||
|
||||
/// Sets the <svcs> tag data
|
||||
pub fn services(&mut self, services: Services) {
|
||||
self.data.command.services = services;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
||||
#[element_name(name = "logout")]
|
||||
/// Type corresponding to the <logout> tag in an EPP XML logout request
|
||||
|
|
|
@ -13,8 +13,6 @@ pub type CommandResponse<T> = CommandResponseWithExtension<T, EmptyTag>;
|
|||
pub type EppCommandResponse = EppObject<CommandResponseStatus>;
|
||||
/// An alias of `EppCommandResponse` indicating an EPP Error
|
||||
pub type EppCommandResponseError = EppCommandResponse;
|
||||
/// An alias of `EppCommandResponse` received in response to a successful login request
|
||||
pub type EppLoginResponse = EppCommandResponse;
|
||||
/// An alias of `EppCommandResponse` received in response to a successful logout request
|
||||
pub type EppLogoutResponse = EppCommandResponse;
|
||||
|
||||
|
|
|
@ -28,9 +28,10 @@ mod response {
|
|||
use crate::host::delete::EppHostDeleteResponse;
|
||||
use crate::host::info::EppHostInfoResponse;
|
||||
use crate::host::update::EppHostUpdateResponse;
|
||||
use crate::login::EppLoginResponse;
|
||||
use crate::message::ack::EppMessageAckResponse;
|
||||
use crate::message::poll::EppMessagePollResponse;
|
||||
use crate::response::{EppCommandResponseError, EppLoginResponse, EppLogoutResponse};
|
||||
use crate::response::{EppCommandResponseError, EppLogoutResponse};
|
||||
use crate::xml::EppXml;
|
||||
|
||||
const SVTRID: &str = "RO-6879-1627224678242975";
|
||||
|
|
|
@ -35,9 +35,10 @@ mod request {
|
|||
use crate::host::update::EppHostUpdate;
|
||||
use crate::host::update::HostAddRemove;
|
||||
use crate::host::update::HostChangeInfo;
|
||||
use crate::login::EppLogin;
|
||||
use crate::message::ack::EppMessageAck;
|
||||
use crate::message::poll::EppMessagePoll;
|
||||
use crate::request::{EppLogin, EppLogout};
|
||||
use crate::request::EppLogout;
|
||||
use crate::xml::EppXml;
|
||||
use chrono::{DateTime, NaiveDate};
|
||||
use std::str::FromStr;
|
||||
|
|
Loading…
Reference in New Issue