diff --git a/epp-client/src/connection/client.rs b/epp-client/src/connection/client.rs index 07adaaa..fd7d320 100644 --- a/epp-client/src/connection/client.rs +++ b/epp-client/src/connection/client.rs @@ -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 diff --git a/epp-client/src/lib.rs b/epp-client/src/lib.rs index 727d149..71b256d 100644 --- a/epp-client/src/lib.rs +++ b/epp-client/src/lib.rs @@ -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; diff --git a/epp-client/src/login.rs b/epp-client/src/login.rs new file mode 100644 index 0000000..9dbebdc --- /dev/null +++ b/epp-client/src/login.rs @@ -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>; + +impl EppLogin { + /// Creates a new EPP Login request + pub fn new( + username: &str, + password: &str, + ext_uris: &Option>, + 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:: { + command: login, + extension: None, + client_tr_id: client_tr_id.into(), + }) + } + + /// Sets the tag data + pub fn options(&mut self, options: Options) { + self.data.command.options = options; + } + + /// Sets the 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 tag + options: Options, + /// Data under the tag + #[serde(rename = "svcs")] + services: Services, +} diff --git a/epp-client/src/request.rs b/epp-client/src/request.rs index 66fd806..8d1ef50 100644 --- a/epp-client/src/request.rs +++ b/epp-client/src/request.rs @@ -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 = CommandWithExtension; -/// The EPP Login Request -pub type EppLogin = EppObject>; /// The EPP Logout request pub type EppLogout = EppObject>; @@ -84,70 +74,6 @@ pub fn generate_client_tr_id(username: &str) -> Result> { 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 tag - options: Options, - /// Data under the tag - #[serde(rename = "svcs")] - services: Services, -} - -impl EppLogin { - /// Creates a new EPP Login request - pub fn new( - username: &str, - password: &str, - ext_uris: &Option>, - 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:: { - command: login, - extension: None, - client_tr_id: client_tr_id.into(), - }) - } - - /// Sets the tag data - pub fn options(&mut self, options: Options) { - self.data.command.options = options; - } - - /// Sets the 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 diff --git a/epp-client/src/response.rs b/epp-client/src/response.rs index b42d7de..a8e6e36 100644 --- a/epp-client/src/response.rs +++ b/epp-client/src/response.rs @@ -13,8 +13,6 @@ pub type CommandResponse = CommandResponseWithExtension; pub type EppCommandResponse = EppObject; /// 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; diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index ab823a2..51c6525 100644 --- a/epp-client/src/tests/de.rs +++ b/epp-client/src/tests/de.rs @@ -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"; diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs index 9714591..ece42dc 100644 --- a/epp-client/src/tests/se.rs +++ b/epp-client/src/tests/se.rs @@ -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;