diff --git a/epp-client/src/connection/client.rs b/epp-client/src/connection/client.rs index 9980dd4..07adaaa 100644 --- a/epp-client/src/connection/client.rs +++ b/epp-client/src/connection/client.rs @@ -52,9 +52,10 @@ use std::{error::Error, fmt::Debug}; use crate::config::EppClientConfig; use crate::connection::registry::{epp_connect, EppConnection}; use crate::error; -use crate::request::{generate_client_tr_id, EppHello, EppLogin, EppLogout}; +use crate::hello::{EppGreeting, EppHello}; +use crate::request::{generate_client_tr_id, EppLogin, EppLogout}; use crate::response::{ - EppCommandResponse, EppCommandResponseError, EppGreeting, EppLoginResponse, EppLogoutResponse, + EppCommandResponse, EppCommandResponseError, EppLoginResponse, EppLogoutResponse, }; use crate::xml::EppXml; /// Instances of the EppClient type are used to transact with the registry. diff --git a/epp-client/src/hello.rs b/epp-client/src/hello.rs new file mode 100644 index 0000000..426bc41 --- /dev/null +++ b/epp-client/src/hello.rs @@ -0,0 +1,299 @@ +use std::fmt::Debug; + +use epp_client_macros::ElementName; +use serde::{Deserialize, Deserializer, Serialize}; + +use crate::common::{ElementName, EppObject, Options, ServiceExtension, Services, StringValue}; + +/// The EPP Hello request +pub type EppHello = EppObject; + +impl EppHello { + /// Creates a new Epp Hello request + pub fn new() -> EppHello { + EppObject::build(Hello {}) + } +} + +impl Default for EppHello { + fn default() -> Self { + Self::new() + } +} + +/// The EPP Greeting that is received on a successful connection and in response to an EPP hello +pub type EppGreeting = EppObject; + +// Request + +#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] +#[element_name(name = "hello")] +/// Type corresponding to the tag in an EPP XML hello request +pub struct Hello; + +// Response + +/// Type for data within the section of an EPP greeting +#[derive(Serialize, Debug, PartialEq)] +pub struct ServiceMenu { + pub options: Options, + pub services: Services, +} + +/// Simplified service menu type for deserialization to `ServiceMenu` type from EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +struct FlattenedServiceMenu { + pub version: StringValue, + pub lang: StringValue, + #[serde(rename = "objURI")] + pub obj_uris: Vec, + #[serde(rename = "svcExtension")] + pub svc_ext: Option, +} + +impl<'de> Deserialize<'de> for ServiceMenu { + /// Deserializes the data to the `ServiceMenu` type + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let flattened_svc_menu = FlattenedServiceMenu::deserialize(deserializer)?; + + let svc_menu = ServiceMenu { + options: Options { + version: flattened_svc_menu.version, + lang: flattened_svc_menu.lang, + }, + services: Services { + obj_uris: flattened_svc_menu.obj_uris, + svc_ext: flattened_svc_menu.svc_ext, + }, + }; + + Ok(svc_menu) + } +} + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct All; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct NoAccess; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Null; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Personal; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct PersonalAndOther; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Other; + +/// Type corresponding to possible type values +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub enum AccessType { + /// Data for the tag + #[serde(rename = "all")] + All(All), + /// Data for the tag + #[serde(rename = "none")] + NoAccess(NoAccess), + /// Data for the tag + #[serde(rename = "null")] + Null(Null), + /// Data for the tag + #[serde(rename = "personal")] + Personal(Personal), + /// Data for the tag + #[serde(rename = "personalAndOther")] + PersonalAndOther(PersonalAndOther), + /// Data for the tag + #[serde(rename = "other")] + Other(Other), +} + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Access { + #[serde(flatten)] + pub ty: AccessType, +} + +/// Type corresponding to possible type values +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub enum PurposeType { + /// Data for the tag + #[serde(rename = "admin")] + Admin, + /// Data for the tag + #[serde(rename = "contact")] + Contact, + /// Data for the tag + #[serde(rename = "prov")] + Prov, + /// Data for the tag + #[serde(rename = "other")] + OtherPurpose, +} + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Purpose { + #[serde(rename = "$value")] + pub purpose: Vec, +} + +/// Type corresponding to possible type values +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub enum RecipientType { + /// Data for the tag + #[serde(rename = "other")] + Other, + /// Data for the tag + #[serde(rename = "ours")] + Ours, + /// Data for the tag + #[serde(rename = "public")] + Public, + /// Data for the tag + #[serde(rename = "same")] + Same, + /// Data for the tag + #[serde(rename = "unrelated")] + Unrelated, +} + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Recipient { + #[serde(rename = "$value")] + pub recipient: Vec, +} + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Business; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Indefinite; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Legal; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct No; + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Stated; + +/// Type corresponding to possible type values +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub enum RetentionType { + /// Data for the tag + #[serde(rename = "business")] + Business(Business), + /// Data for the tag + #[serde(rename = "indefinite")] + Indefinite(Indefinite), + /// Data for the tag + #[serde(rename = "legal")] + Legal(Legal), + /// Data for the tag + #[serde(rename = "none")] + No(No), + /// Data for the tag + #[serde(rename = "stated")] + Stated(Stated), +} + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Retention { + #[serde(flatten)] + pub ty: RetentionType, +} + +/// Type corresponding to in the EPP greeting XML (pending more compliant implementation) +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Statement { + /// Data for the tag + pub purpose: Purpose, + /// Data for the tag + pub recipient: Recipient, + /// Data for the tag + pub retention: Retention, +} + +/// Type corresponding to value in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Absolute { + #[serde(rename = "$value")] + pub absolute: StringValue, +} + +/// Type corresponding to value in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Relative { + #[serde(rename = "$value")] + pub relative: StringValue, +} + +/// Type corresponding to possible type values +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub enum ExpiryType { + /// Data for the tag + #[serde(rename = "absolute")] + Absolute(Absolute), + /// Data for the tag + #[serde(rename = "relative")] + Relative(Relative), +} + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Expiry { + #[serde(flatten)] + pub ty: ExpiryType, +} + +/// Type corresponding to in the EPP greeting XML +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Dcp { + /// Data for the tag + pub access: Access, + /// Data for the tags + pub statement: Vec, + /// Data for the tag + pub expiry: Option, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] +#[serde(rename_all = "lowercase")] +#[element_name(name = "greeting")] +/// Type corresponding to the tag in the EPP greeting XML +pub struct Greeting { + /// The service ID + #[serde(rename = "svID")] + pub service_id: String, + /// The date from the EPP server + #[serde(rename = "svDate")] + pub service_date: String, + /// Data under the element + #[serde(rename = "svcMenu")] + pub svc_menu: ServiceMenu, + /// Data under the element + pub dcp: Dcp, +} diff --git a/epp-client/src/lib.rs b/epp-client/src/lib.rs index a37fb55..727d149 100644 --- a/epp-client/src/lib.rs +++ b/epp-client/src/lib.rs @@ -106,6 +106,7 @@ pub mod connection; pub mod contact; pub mod domain; pub mod error; +pub mod hello; pub mod host; pub mod message; pub mod request; diff --git a/epp-client/src/request.rs b/epp-client/src/request.rs index 9973ff2..66fd806 100644 --- a/epp-client/src/request.rs +++ b/epp-client/src/request.rs @@ -22,8 +22,6 @@ pub const EPP_LANG: &str = "en"; /// without an <extension> tag pub type Command = CommandWithExtension; -/// The EPP Hello request -pub type EppHello = EppObject; /// The EPP Login Request pub type EppLogin = EppObject>; /// The EPP Logout request @@ -86,24 +84,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 = "hello")] -/// Type corresponding to the tag in an EPP XML hello request -pub struct Hello; - -impl EppHello { - /// Creates a new Epp Hello request - pub fn new() -> EppHello { - EppObject::build(Hello {}) - } -} - -impl Default for EppHello { - fn default() -> Self { - Self::new() - } -} - #[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] #[element_name(name = "login")] /// Type corresponding to the <login> tag in an EPP XML login request diff --git a/epp-client/src/response.rs b/epp-client/src/response.rs index 74343e2..b42d7de 100644 --- a/epp-client/src/response.rs +++ b/epp-client/src/response.rs @@ -1,18 +1,14 @@ //! Types for EPP responses use epp_client_macros::*; -use serde::{Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Serialize}; use std::fmt::Debug; -use crate::common::{ - ElementName, EmptyTag, EppObject, Extension, Options, ServiceExtension, Services, StringValue, -}; +use crate::common::{ElementName, EmptyTag, EppObject, Extension, StringValue}; /// Type corresponding to the <response> tag in an EPP response without an <extension> section pub type CommandResponse = CommandResponseWithExtension; -/// The EPP Greeting that is received on a successful connection and in response to an EPP hello -pub type EppGreeting = EppObject; /// A generic EPP Response to an EPP command with a result section, a status code and a message pub type EppCommandResponse = EppObject; /// An alias of `EppCommandResponse` indicating an EPP Error @@ -22,271 +18,6 @@ pub type EppLoginResponse = EppCommandResponse; /// An alias of `EppCommandResponse` received in response to a successful logout request pub type EppLogoutResponse = EppCommandResponse; -/// Type for data within the section of an EPP greeting -#[derive(Serialize, Debug, PartialEq)] -pub struct ServiceMenu { - pub options: Options, - pub services: Services, -} - -/// Simplified service menu type for deserialization to `ServiceMenu` type from EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -struct FlattenedServiceMenu { - pub version: StringValue, - pub lang: StringValue, - #[serde(rename = "objURI")] - pub obj_uris: Vec, - #[serde(rename = "svcExtension")] - pub svc_ext: Option, -} - -impl<'de> Deserialize<'de> for ServiceMenu { - /// Deserializes the data to the `ServiceMenu` type - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let flattened_svc_menu = FlattenedServiceMenu::deserialize(deserializer)?; - - let svc_menu = ServiceMenu { - options: Options { - version: flattened_svc_menu.version, - lang: flattened_svc_menu.lang, - }, - services: Services { - obj_uris: flattened_svc_menu.obj_uris, - svc_ext: flattened_svc_menu.svc_ext, - }, - }; - - Ok(svc_menu) - } -} - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct All; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct NoAccess; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Null; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Personal; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct PersonalAndOther; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Other; - -/// Type corresponding to possible type values -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub enum AccessType { - /// Data for the tag - #[serde(rename = "all")] - All(All), - /// Data for the tag - #[serde(rename = "none")] - NoAccess(NoAccess), - /// Data for the tag - #[serde(rename = "null")] - Null(Null), - /// Data for the tag - #[serde(rename = "personal")] - Personal(Personal), - /// Data for the tag - #[serde(rename = "personalAndOther")] - PersonalAndOther(PersonalAndOther), - /// Data for the tag - #[serde(rename = "other")] - Other(Other), -} - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Access { - #[serde(flatten)] - pub ty: AccessType, -} - -/// Type corresponding to possible type values -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub enum PurposeType { - /// Data for the tag - #[serde(rename = "admin")] - Admin, - /// Data for the tag - #[serde(rename = "contact")] - Contact, - /// Data for the tag - #[serde(rename = "prov")] - Prov, - /// Data for the tag - #[serde(rename = "other")] - OtherPurpose, -} - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Purpose { - #[serde(rename = "$value")] - pub purpose: Vec, -} - -/// Type corresponding to possible type values -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub enum RecipientType { - /// Data for the tag - #[serde(rename = "other")] - Other, - /// Data for the tag - #[serde(rename = "ours")] - Ours, - /// Data for the tag - #[serde(rename = "public")] - Public, - /// Data for the tag - #[serde(rename = "same")] - Same, - /// Data for the tag - #[serde(rename = "unrelated")] - Unrelated, -} - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Recipient { - #[serde(rename = "$value")] - pub recipient: Vec, -} - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Business; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Indefinite; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Legal; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct No; - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Stated; - -/// Type corresponding to possible type values -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub enum RetentionType { - /// Data for the tag - #[serde(rename = "business")] - Business(Business), - /// Data for the tag - #[serde(rename = "indefinite")] - Indefinite(Indefinite), - /// Data for the tag - #[serde(rename = "legal")] - Legal(Legal), - /// Data for the tag - #[serde(rename = "none")] - No(No), - /// Data for the tag - #[serde(rename = "stated")] - Stated(Stated), -} - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Retention { - #[serde(flatten)] - pub ty: RetentionType, -} - -/// Type corresponding to in the EPP greeting XML (pending more compliant implementation) -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Statement { - /// Data for the tag - pub purpose: Purpose, - /// Data for the tag - pub recipient: Recipient, - /// Data for the tag - pub retention: Retention, -} - -/// Type corresponding to value in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Absolute { - #[serde(rename = "$value")] - pub absolute: StringValue, -} - -/// Type corresponding to value in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Relative { - #[serde(rename = "$value")] - pub relative: StringValue, -} - -/// Type corresponding to possible type values -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub enum ExpiryType { - /// Data for the tag - #[serde(rename = "absolute")] - Absolute(Absolute), - /// Data for the tag - #[serde(rename = "relative")] - Relative(Relative), -} - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Expiry { - #[serde(flatten)] - pub ty: ExpiryType, -} - -/// Type corresponding to in the EPP greeting XML -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Dcp { - /// Data for the tag - pub access: Access, - /// Data for the tags - pub statement: Vec, - /// Data for the tag - pub expiry: Option, -} - -#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] -#[serde(rename_all = "lowercase")] -#[element_name(name = "greeting")] -/// Type corresponding to the tag in the EPP greeting XML -pub struct Greeting { - /// The service ID - #[serde(rename = "svID")] - pub service_id: String, - /// The date from the EPP server - #[serde(rename = "svDate")] - pub service_date: String, - /// Data under the element - #[serde(rename = "svcMenu")] - pub svc_menu: ServiceMenu, - /// Data under the element - pub dcp: Dcp, -} - /// Type corresponding to the tag an EPP response XML #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Undef; diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index 1357c07..ab823a2 100644 --- a/epp-client/src/tests/de.rs +++ b/epp-client/src/tests/de.rs @@ -20,6 +20,9 @@ mod response { use crate::domain::transfer::EppDomainTransferRejectResponse; use crate::domain::transfer::EppDomainTransferRequestResponse; use crate::domain::update::EppDomainUpdateResponse; + use crate::hello::EppGreeting; + use crate::hello::ExpiryType; + use crate::hello::Relative; use crate::host::check::EppHostCheckResponse; use crate::host::create::EppHostCreateResponse; use crate::host::delete::EppHostDeleteResponse; @@ -27,11 +30,7 @@ mod response { use crate::host::update::EppHostUpdateResponse; use crate::message::ack::EppMessageAckResponse; use crate::message::poll::EppMessagePollResponse; - use crate::response::ExpiryType; - use crate::response::Relative; - use crate::response::{ - EppCommandResponseError, EppGreeting, EppLoginResponse, EppLogoutResponse, - }; + use crate::response::{EppCommandResponseError, EppLoginResponse, 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 4103a82..9714591 100644 --- a/epp-client/src/tests/se.rs +++ b/epp-client/src/tests/se.rs @@ -27,6 +27,7 @@ mod request { use crate::domain::update::DomainAddRemove; use crate::domain::update::DomainChangeInfo; use crate::domain::update::EppDomainUpdate; + use crate::hello::EppHello; use crate::host::check::EppHostCheck; use crate::host::create::EppHostCreate; use crate::host::delete::EppHostDelete; @@ -36,7 +37,7 @@ mod request { use crate::host::update::HostChangeInfo; use crate::message::ack::EppMessageAck; use crate::message::poll::EppMessagePoll; - use crate::request::{EppHello, EppLogin, EppLogout}; + use crate::request::{EppLogin, EppLogout}; use crate::xml::EppXml; use chrono::{DateTime, NaiveDate}; use std::str::FromStr;