Refactor object::data into common module
This commit is contained in:
parent
8bf0283b7e
commit
fce6c7a2eb
|
@ -1,7 +1,142 @@
|
||||||
//! Common data types included in EPP Requests and Responses
|
//! Common data types included in EPP Requests and Responses
|
||||||
|
|
||||||
use crate::epp::object::StringValue;
|
use std::fmt::Display;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
use epp_client_macros::ElementName;
|
||||||
|
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||||
|
|
||||||
|
const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0";
|
||||||
|
|
||||||
|
/// Wraps String for easier serialization to and from values that are inner text
|
||||||
|
/// for tags rather than attributes
|
||||||
|
#[derive(Default, Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||||
|
pub struct StringValue(String);
|
||||||
|
|
||||||
|
impl Display for StringValue {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for StringValue {
|
||||||
|
fn from(s: &str) -> Self {
|
||||||
|
Self(s.to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<String> for StringValue {
|
||||||
|
fn from(s: String) -> Self {
|
||||||
|
Self(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Trait to set correct value for xml tags when tags are being generated from generic types
|
||||||
|
pub trait ElementName {
|
||||||
|
const ELEMENT: &'static str;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
||||||
|
#[element_name(name = "empty")]
|
||||||
|
/// An empty placeholder tag. To be refactored to something more compliant later.
|
||||||
|
pub struct EmptyTag;
|
||||||
|
|
||||||
|
/// An EPP XML Document that is used either as an EPP XML request or
|
||||||
|
/// an EPP XML response
|
||||||
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
|
#[serde(rename = "epp")]
|
||||||
|
pub struct EppObject<T: ElementName> {
|
||||||
|
/// XML namespace for the <epp> tag
|
||||||
|
pub xmlns: String,
|
||||||
|
/// the request or response object that is set or received in the EPP XML document
|
||||||
|
#[serde(alias = "greeting", alias = "response")]
|
||||||
|
pub data: T,
|
||||||
|
// TODO: save serialized xml in the instance for debugging or client logging purposes
|
||||||
|
// #[serde(skip)]
|
||||||
|
// pub xml: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: ElementName + Serialize> Serialize for EppObject<T> {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let mut state = serializer.serialize_struct("epp", 4)?;
|
||||||
|
state.serialize_field("xmlns", &self.xmlns)?;
|
||||||
|
state.serialize_field(T::ELEMENT, &self.data)?;
|
||||||
|
state.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The <option> type in EPP XML login requests
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
|
#[serde(rename = "options")]
|
||||||
|
pub struct Options {
|
||||||
|
/// The EPP version being used
|
||||||
|
pub version: StringValue,
|
||||||
|
/// The language that will be used during EPP transactions
|
||||||
|
pub lang: StringValue,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Options {
|
||||||
|
/// Creates an Options object with version and lang data
|
||||||
|
pub fn build(version: &str, lang: &str) -> Options {
|
||||||
|
Options {
|
||||||
|
version: version.into(),
|
||||||
|
lang: lang.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type representing the <extension> tag for an EPP document
|
||||||
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
|
#[serde(rename = "extension")]
|
||||||
|
pub struct Extension<E: ElementName> {
|
||||||
|
/// Data under the <extension> tag
|
||||||
|
#[serde(alias = "upData")]
|
||||||
|
pub data: E,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<E: ElementName + Serialize> Serialize for Extension<E> {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let mut state = serializer.serialize_struct("extension", 1)?;
|
||||||
|
state.serialize_field(E::ELEMENT, &self.data)?;
|
||||||
|
state.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The <svcExtension> type in EPP XML
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
|
#[serde(rename = "svcExtension")]
|
||||||
|
pub struct ServiceExtension {
|
||||||
|
/// The service extension URIs being represented by <extURI> in EPP XML
|
||||||
|
#[serde(rename = "extURI")]
|
||||||
|
pub ext_uris: Option<Vec<StringValue>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The <svcs> type in EPP XML
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
|
pub struct Services {
|
||||||
|
/// The service URIs being used by this EPP session represented by <objURI> in EPP XML
|
||||||
|
#[serde(rename = "objURI")]
|
||||||
|
pub obj_uris: Vec<StringValue>,
|
||||||
|
/// The <svcExtention> being used in this EPP session
|
||||||
|
#[serde(rename = "svcExtension")]
|
||||||
|
pub svc_ext: Option<ServiceExtension>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: ElementName> EppObject<T> {
|
||||||
|
/// Create the enclosing EPP XML tag <epp> for data that represents an EPP XML request or response
|
||||||
|
pub fn build(data: T) -> EppObject<T> {
|
||||||
|
EppObject {
|
||||||
|
// xml: None,
|
||||||
|
data,
|
||||||
|
xmlns: EPP_XMLNS.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The <status> attribute on EPP XML for domain transactions
|
/// The <status> attribute on EPP XML for domain transactions
|
||||||
pub type DomainStatus = ContactStatus;
|
pub type DomainStatus = ContactStatus;
|
|
@ -1,7 +1,7 @@
|
||||||
/// Types for EPP contact check request
|
/// Types for EPP contact check request
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
use crate::common::{ElementName, EppObject, StringValue};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data;
|
use crate::common::{ContactAuthInfo, ElementName, EppObject, Phone, PostalInfo, StringValue};
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
||||||
|
@ -18,7 +17,7 @@ use serde::{Deserialize, Serialize};
|
||||||
///
|
///
|
||||||
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||||
/// use epp_client::EppClient;
|
/// use epp_client::EppClient;
|
||||||
/// use epp_client::epp::object::data::{Address, Phone, PostalInfo};
|
/// use epp_client::common::{Address, Phone, PostalInfo};
|
||||||
/// use epp_client::contact::create::{EppContactCreate, EppContactCreateResponse};
|
/// use epp_client::contact::create::{EppContactCreate, EppContactCreateResponse};
|
||||||
/// use epp_client::epp::generate_client_tr_id;
|
/// use epp_client::epp::generate_client_tr_id;
|
||||||
///
|
///
|
||||||
|
@ -80,8 +79,8 @@ impl EppContactCreate {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: &str,
|
id: &str,
|
||||||
email: &str,
|
email: &str,
|
||||||
postal_info: data::PostalInfo,
|
postal_info: PostalInfo,
|
||||||
voice: data::Phone,
|
voice: Phone,
|
||||||
auth_password: &str,
|
auth_password: &str,
|
||||||
client_tr_id: &str,
|
client_tr_id: &str,
|
||||||
) -> EppContactCreate {
|
) -> EppContactCreate {
|
||||||
|
@ -93,7 +92,7 @@ impl EppContactCreate {
|
||||||
voice,
|
voice,
|
||||||
fax: None,
|
fax: None,
|
||||||
email: email.into(),
|
email: email.into(),
|
||||||
auth_info: data::ContactAuthInfo::new(auth_password),
|
auth_info: ContactAuthInfo::new(auth_password),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,7 +103,7 @@ impl EppContactCreate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the <fax> data for the request
|
/// Sets the <fax> data for the request
|
||||||
pub fn set_fax(&mut self, fax: data::Phone) {
|
pub fn set_fax(&mut self, fax: Phone) {
|
||||||
self.data.command.contact.fax = Some(fax);
|
self.data.command.contact.fax = Some(fax);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,19 +124,19 @@ pub struct Contact {
|
||||||
id: StringValue,
|
id: StringValue,
|
||||||
/// Contact <postalInfo> tag
|
/// Contact <postalInfo> tag
|
||||||
#[serde(rename = "contact:postalInfo", alias = "postalInfo")]
|
#[serde(rename = "contact:postalInfo", alias = "postalInfo")]
|
||||||
postal_info: data::PostalInfo,
|
postal_info: PostalInfo,
|
||||||
/// Contact <voice> tag
|
/// Contact <voice> tag
|
||||||
#[serde(rename = "contact:voice", alias = "voice")]
|
#[serde(rename = "contact:voice", alias = "voice")]
|
||||||
voice: data::Phone,
|
voice: Phone,
|
||||||
/// Contact <fax> tag,
|
/// Contact <fax> tag,
|
||||||
#[serde(rename = "contact:fax", alias = "fax")]
|
#[serde(rename = "contact:fax", alias = "fax")]
|
||||||
fax: Option<data::Phone>,
|
fax: Option<Phone>,
|
||||||
/// Contact <email> tag
|
/// Contact <email> tag
|
||||||
#[serde(rename = "contact:email", alias = "email")]
|
#[serde(rename = "contact:email", alias = "email")]
|
||||||
email: StringValue,
|
email: StringValue,
|
||||||
/// Contact <authInfo> tag
|
/// Contact <authInfo> tag
|
||||||
#[serde(rename = "contact:authInfo", alias = "authInfo")]
|
#[serde(rename = "contact:authInfo", alias = "authInfo")]
|
||||||
auth_info: data::ContactAuthInfo,
|
auth_info: ContactAuthInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, ElementName)]
|
#[derive(Serialize, Deserialize, Debug, ElementName)]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
use crate::common::{ElementName, EppObject, StringValue};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::EppCommandResponse;
|
use crate::epp::response::EppCommandResponse;
|
||||||
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data::{ContactAuthInfo, ContactStatus, Phone, PostalInfo};
|
use crate::common::{
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
ContactAuthInfo, ContactStatus, ElementName, EppObject, Phone, PostalInfo, StringValue,
|
||||||
|
};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
|
use crate::common::{
|
||||||
|
ContactAuthInfo, ContactStatus, ElementName, EppObject, Phone, PostalInfo, StringValue,
|
||||||
|
};
|
||||||
use crate::contact::info::EppContactInfoResponse;
|
use crate::contact::info::EppContactInfoResponse;
|
||||||
use crate::epp::object::data::{ContactAuthInfo, ContactStatus, Phone, PostalInfo};
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::EppCommandResponse;
|
use crate::epp::response::EppCommandResponse;
|
||||||
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
||||||
|
@ -22,7 +23,7 @@ use serde::{Deserialize, Serialize};
|
||||||
/// use epp_client::EppClient;
|
/// use epp_client::EppClient;
|
||||||
/// use epp_client::contact::update::{EppContactUpdate, EppContactUpdateResponse};
|
/// use epp_client::contact::update::{EppContactUpdate, EppContactUpdateResponse};
|
||||||
/// use epp_client::epp::generate_client_tr_id;
|
/// use epp_client::epp::generate_client_tr_id;
|
||||||
/// use epp_client::epp::object::data::ContactStatus;
|
/// use epp_client::common::ContactStatus;
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() {
|
/// async fn main() {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
use crate::common::{ElementName, EppObject, StringValue};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data::{
|
use crate::common::{
|
||||||
DomainAuthInfo, DomainContact, HostAttr, HostAttrList, HostList, HostObjList, Period,
|
DomainAuthInfo, DomainContact, ElementName, EppObject, HostAttr, HostAttrList, HostList,
|
||||||
|
HostObjList, Period, StringValue,
|
||||||
};
|
};
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
||||||
|
@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize};
|
||||||
///
|
///
|
||||||
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||||
/// use epp_client::EppClient;
|
/// use epp_client::EppClient;
|
||||||
/// use epp_client::epp::object::data::DomainContact;
|
/// use epp_client::common::DomainContact;
|
||||||
/// use epp_client::domain::create::{EppDomainCreate, EppDomainCreateResponse};
|
/// use epp_client::domain::create::{EppDomainCreate, EppDomainCreateResponse};
|
||||||
/// use epp_client::epp::generate_client_tr_id;
|
/// use epp_client::epp::generate_client_tr_id;
|
||||||
///
|
///
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
use crate::common::{ElementName, EppObject, StringValue};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::EppCommandResponse;
|
use crate::epp::response::EppCommandResponse;
|
||||||
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
|
use crate::common::{
|
||||||
|
DomainAuthInfo, DomainContact, DomainStatus, ElementName, EppObject, HostAttr, StringValue,
|
||||||
|
};
|
||||||
use crate::domain::rgp::request::RgpRequestResponse;
|
use crate::domain::rgp::request::RgpRequestResponse;
|
||||||
use crate::epp::object::data::{DomainAuthInfo, DomainContact, DomainStatus, HostAttr};
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponseWithExtension;
|
use crate::epp::response::CommandResponseWithExtension;
|
||||||
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data::Period;
|
use crate::common::{ElementName, EppObject, Period, StringValue};
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
|
use crate::common::{ElementName, EppObject, Extension, StringValue};
|
||||||
use crate::domain::update::{DomainChangeInfo, DomainUpdateRequest, DomainUpdateRequestData};
|
use crate::domain::update::{DomainChangeInfo, DomainUpdateRequest, DomainUpdateRequestData};
|
||||||
use crate::epp::object::{ElementName, EppObject, Extension, StringValue};
|
|
||||||
use crate::epp::request::CommandWithExtension;
|
use crate::epp::request::CommandWithExtension;
|
||||||
use crate::epp::response::EppCommandResponse;
|
use crate::epp::response::EppCommandResponse;
|
||||||
use crate::epp::xml::{EPP_DOMAIN_RGP_EXT_XMLNS, EPP_DOMAIN_XMLNS};
|
use crate::epp::xml::{EPP_DOMAIN_RGP_EXT_XMLNS, EPP_DOMAIN_XMLNS};
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
|
use crate::common::{ElementName, EmptyTag, EppObject, Extension};
|
||||||
use crate::domain::update::{DomainChangeInfo, DomainUpdateRequest, DomainUpdateRequestData};
|
use crate::domain::update::{DomainChangeInfo, DomainUpdateRequest, DomainUpdateRequestData};
|
||||||
use crate::epp::object::{ElementName, EmptyTag, EppObject, Extension};
|
|
||||||
use crate::epp::request::CommandWithExtension;
|
use crate::epp::request::CommandWithExtension;
|
||||||
use crate::epp::response::CommandResponseWithExtension;
|
use crate::epp::response::CommandResponseWithExtension;
|
||||||
use crate::epp::xml::{EPP_DOMAIN_RGP_EXT_XMLNS, EPP_DOMAIN_XMLNS};
|
use crate::epp::xml::{EPP_DOMAIN_RGP_EXT_XMLNS, EPP_DOMAIN_XMLNS};
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data::{DomainAuthInfo, Period};
|
use crate::common::{DomainAuthInfo, ElementName, EppObject, Period, StringValue};
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::{CommandResponse, EppCommandResponse};
|
use crate::epp::response::{CommandResponse, EppCommandResponse};
|
||||||
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data::{DomainAuthInfo, DomainContact, DomainStatus, HostList};
|
use crate::common::{
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
DomainAuthInfo, DomainContact, DomainStatus, ElementName, EppObject, HostList, StringValue,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::EppCommandResponse;
|
use crate::epp::response::EppCommandResponse;
|
||||||
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
||||||
|
@ -19,7 +21,7 @@ use serde::{Deserialize, Serialize};
|
||||||
///
|
///
|
||||||
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||||
/// use epp_client::EppClient;
|
/// use epp_client::EppClient;
|
||||||
/// use epp_client::epp::object::data::{DomainStatus, DomainContact};
|
/// use epp_client::common::{DomainStatus, DomainContact};
|
||||||
/// use epp_client::domain::update::{EppDomainUpdate, EppDomainUpdateResponse, DomainAddRemove};
|
/// use epp_client::domain::update::{EppDomainUpdate, EppDomainUpdateResponse, DomainAddRemove};
|
||||||
/// use epp_client::epp::generate_client_tr_id;
|
/// use epp_client::epp::generate_client_tr_id;
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//! Types for EPP requests and responses
|
//! Types for EPP requests and responses
|
||||||
|
|
||||||
pub mod object;
|
|
||||||
pub mod request;
|
pub mod request;
|
||||||
pub mod response;
|
pub mod response;
|
||||||
pub mod xml;
|
pub mod xml;
|
||||||
|
|
|
@ -1,140 +0,0 @@
|
||||||
//! Data types common to EPP Requests and Responses
|
|
||||||
|
|
||||||
pub mod data;
|
|
||||||
|
|
||||||
use epp_client_macros::*;
|
|
||||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
use crate::epp::xml::EPP_XMLNS;
|
|
||||||
|
|
||||||
/// Wraps String for easier serialization to and from values that are inner text
|
|
||||||
/// for tags rather than attributes
|
|
||||||
#[derive(Default, Serialize, Deserialize, Debug, PartialEq, Clone)]
|
|
||||||
pub struct StringValue(String);
|
|
||||||
|
|
||||||
impl Display for StringValue {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&str> for StringValue {
|
|
||||||
fn from(s: &str) -> Self {
|
|
||||||
Self(s.to_owned())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<String> for StringValue {
|
|
||||||
fn from(s: String) -> Self {
|
|
||||||
Self(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trait to set correct value for xml tags when tags are being generated from generic types
|
|
||||||
pub trait ElementName {
|
|
||||||
const ELEMENT: &'static str;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
|
||||||
#[element_name(name = "empty")]
|
|
||||||
/// An empty placeholder tag. To be refactored to something more compliant later.
|
|
||||||
pub struct EmptyTag;
|
|
||||||
|
|
||||||
/// An EPP XML Document that is used either as an EPP XML request or
|
|
||||||
/// an EPP XML response
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
|
||||||
#[serde(rename = "epp")]
|
|
||||||
pub struct EppObject<T: ElementName> {
|
|
||||||
/// XML namespace for the <epp> tag
|
|
||||||
pub xmlns: String,
|
|
||||||
/// the request or response object that is set or received in the EPP XML document
|
|
||||||
#[serde(alias = "greeting", alias = "response")]
|
|
||||||
pub data: T,
|
|
||||||
// TODO: save serialized xml in the instance for debugging or client logging purposes
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub xml: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: ElementName + Serialize> Serialize for EppObject<T> {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
let mut state = serializer.serialize_struct("epp", 4)?;
|
|
||||||
state.serialize_field("xmlns", &self.xmlns)?;
|
|
||||||
state.serialize_field(T::ELEMENT, &self.data)?;
|
|
||||||
state.end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The <option> type in EPP XML login requests
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
|
||||||
#[serde(rename = "options")]
|
|
||||||
pub struct Options {
|
|
||||||
/// The EPP version being used
|
|
||||||
pub version: StringValue,
|
|
||||||
/// The language that will be used during EPP transactions
|
|
||||||
pub lang: StringValue,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Options {
|
|
||||||
/// Creates an Options object with version and lang data
|
|
||||||
pub fn build(version: &str, lang: &str) -> Options {
|
|
||||||
Options {
|
|
||||||
version: version.into(),
|
|
||||||
lang: lang.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type representing the <extension> tag for an EPP document
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
|
||||||
#[serde(rename = "extension")]
|
|
||||||
pub struct Extension<E: ElementName> {
|
|
||||||
/// Data under the <extension> tag
|
|
||||||
#[serde(alias = "upData")]
|
|
||||||
pub data: E,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E: ElementName + Serialize> Serialize for Extension<E> {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
let mut state = serializer.serialize_struct("extension", 1)?;
|
|
||||||
state.serialize_field(E::ELEMENT, &self.data)?;
|
|
||||||
state.end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The <svcExtension> type in EPP XML
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
|
||||||
#[serde(rename = "svcExtension")]
|
|
||||||
pub struct ServiceExtension {
|
|
||||||
/// The service extension URIs being represented by <extURI> in EPP XML
|
|
||||||
#[serde(rename = "extURI")]
|
|
||||||
pub ext_uris: Option<Vec<StringValue>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The <svcs> type in EPP XML
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
|
||||||
pub struct Services {
|
|
||||||
/// The service URIs being used by this EPP session represented by <objURI> in EPP XML
|
|
||||||
#[serde(rename = "objURI")]
|
|
||||||
pub obj_uris: Vec<StringValue>,
|
|
||||||
/// The <svcExtention> being used in this EPP session
|
|
||||||
#[serde(rename = "svcExtension")]
|
|
||||||
pub svc_ext: Option<ServiceExtension>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: ElementName> EppObject<T> {
|
|
||||||
/// Create the enclosing EPP XML tag <epp> for data that represents an EPP XML request or response
|
|
||||||
pub fn build(data: T) -> EppObject<T> {
|
|
||||||
EppObject {
|
|
||||||
// xml: None,
|
|
||||||
data,
|
|
||||||
xmlns: EPP_XMLNS.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,10 +4,13 @@ use serde::{ser::SerializeStruct, ser::Serializer, Deserialize, Serialize};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use crate::epp::object::{
|
use crate::{
|
||||||
ElementName, EmptyTag, EppObject, Extension, Options, ServiceExtension, Services, StringValue,
|
common::{
|
||||||
|
ElementName, EmptyTag, EppObject, Extension, Options, ServiceExtension, Services,
|
||||||
|
StringValue,
|
||||||
|
},
|
||||||
|
epp::xml::{EPP_CONTACT_XMLNS, EPP_DOMAIN_XMLNS, EPP_HOST_XMLNS, EPP_LANG, EPP_VERSION},
|
||||||
};
|
};
|
||||||
use crate::epp::xml::{EPP_CONTACT_XMLNS, EPP_DOMAIN_XMLNS, EPP_HOST_XMLNS, EPP_LANG, EPP_VERSION};
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
/// Type corresponding to the <command> tag in an EPP XML request
|
/// Type corresponding to the <command> tag in an EPP XML request
|
||||||
|
|
|
@ -4,7 +4,7 @@ use epp_client_macros::*;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use crate::epp::object::{
|
use crate::common::{
|
||||||
ElementName, EmptyTag, EppObject, Extension, Options, ServiceExtension, Services, StringValue,
|
ElementName, EmptyTag, EppObject, Extension, Options, ServiceExtension, Services, StringValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ use std::{error::Error, fmt::Debug};
|
||||||
use crate::error;
|
use crate::error;
|
||||||
|
|
||||||
pub const EPP_XML_HEADER: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="no"?>"#;
|
pub const EPP_XML_HEADER: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="no"?>"#;
|
||||||
pub const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0";
|
|
||||||
|
|
||||||
pub const EPP_DOMAIN_XMLNS: &str = "urn:ietf:params:xml:ns:domain-1.0";
|
pub const EPP_DOMAIN_XMLNS: &str = "urn:ietf:params:xml:ns:domain-1.0";
|
||||||
pub const EPP_CONTACT_XMLNS: &str = "urn:ietf:params:xml:ns:contact-1.0";
|
pub const EPP_CONTACT_XMLNS: &str = "urn:ietf:params:xml:ns:contact-1.0";
|
||||||
|
|
|
@ -5,7 +5,7 @@ use quick_xml::se;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use std::{error::Error, fmt::Debug};
|
use std::{error::Error, fmt::Debug};
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject};
|
use crate::common::{ElementName, EppObject};
|
||||||
use crate::epp::xml::{EppXml, EPP_XML_HEADER};
|
use crate::epp::xml::{EppXml, EPP_XML_HEADER};
|
||||||
use crate::error;
|
use crate::error;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
use crate::common::{ElementName, EppObject, StringValue};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_HOST_XMLNS;
|
use crate::epp::xml::EPP_HOST_XMLNS;
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data::HostAddr;
|
use crate::common::{ElementName, EppObject, HostAddr, StringValue};
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_HOST_XMLNS;
|
use crate::epp::xml::EPP_HOST_XMLNS;
|
||||||
|
@ -18,7 +17,7 @@ use serde::{Deserialize, Serialize};
|
||||||
///
|
///
|
||||||
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||||
/// use epp_client::EppClient;
|
/// use epp_client::EppClient;
|
||||||
/// use epp_client::epp::object::data::HostAddr;
|
/// use epp_client::common::HostAddr;
|
||||||
/// use epp_client::host::create::{EppHostCreate, EppHostCreateResponse};
|
/// use epp_client::host::create::{EppHostCreate, EppHostCreateResponse};
|
||||||
/// use epp_client::epp::generate_client_tr_id;
|
/// use epp_client::epp::generate_client_tr_id;
|
||||||
///
|
///
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
use crate::common::{ElementName, EppObject, StringValue};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::EppCommandResponse;
|
use crate::epp::response::EppCommandResponse;
|
||||||
use crate::epp::xml::EPP_HOST_XMLNS;
|
use crate::epp::xml::EPP_HOST_XMLNS;
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data::{HostAddr, HostStatus};
|
use crate::common::{ElementName, EppObject, HostAddr, HostStatus, StringValue};
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_HOST_XMLNS;
|
use crate::epp::xml::EPP_HOST_XMLNS;
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::data::{HostAddr, HostStatus};
|
use crate::common::{ElementName, EppObject, HostAddr, HostStatus, StringValue};
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::EppCommandResponse;
|
use crate::epp::response::EppCommandResponse;
|
||||||
use crate::epp::xml::EPP_HOST_XMLNS;
|
use crate::epp::xml::EPP_HOST_XMLNS;
|
||||||
|
@ -18,7 +17,7 @@ use serde::{Deserialize, Serialize};
|
||||||
///
|
///
|
||||||
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||||
/// use epp_client::EppClient;
|
/// use epp_client::EppClient;
|
||||||
/// use epp_client::epp::object::data::{HostAddr, HostStatus};
|
/// use epp_client::common::{HostAddr, HostStatus};
|
||||||
/// use epp_client::host::update::{EppHostUpdate, EppHostUpdateResponse, HostAddRemove, HostChangeInfo};
|
/// use epp_client::host::update::{EppHostUpdate, EppHostUpdateResponse, HostAddRemove, HostChangeInfo};
|
||||||
/// use epp_client::epp::generate_client_tr_id;
|
/// use epp_client::epp::generate_client_tr_id;
|
||||||
///
|
///
|
||||||
|
|
|
@ -100,6 +100,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
|
pub mod common;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod connection;
|
pub mod connection;
|
||||||
pub mod contact;
|
pub mod contact;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject};
|
use crate::common::{ElementName, EppObject};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use epp_client_macros::*;
|
use epp_client_macros::*;
|
||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
use crate::common::{ElementName, EppObject, StringValue};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
use crate::epp::response::CommandResponse;
|
use crate::epp::response::CommandResponse;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -26,7 +26,6 @@ mod response {
|
||||||
EppCommandResponseError, EppGreeting, EppLoginResponse, EppLogoutResponse,
|
EppCommandResponseError, EppGreeting, EppLoginResponse, EppLogoutResponse,
|
||||||
};
|
};
|
||||||
use crate::epp::xml::EppXml;
|
use crate::epp::xml::EppXml;
|
||||||
use crate::epp::*;
|
|
||||||
use crate::host::check::EppHostCheckResponse;
|
use crate::host::check::EppHostCheckResponse;
|
||||||
use crate::host::create::EppHostCreateResponse;
|
use crate::host::create::EppHostCreateResponse;
|
||||||
use crate::host::delete::EppHostDeleteResponse;
|
use crate::host::delete::EppHostDeleteResponse;
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
mod request {
|
mod request {
|
||||||
use super::super::get_xml;
|
use super::super::get_xml;
|
||||||
use super::super::CLTRID;
|
use super::super::CLTRID;
|
||||||
|
use crate::common::{
|
||||||
|
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
|
||||||
|
HostStatus, Phone, PostalInfo,
|
||||||
|
};
|
||||||
use crate::contact::check::EppContactCheck;
|
use crate::contact::check::EppContactCheck;
|
||||||
use crate::contact::create::EppContactCreate;
|
use crate::contact::create::EppContactCreate;
|
||||||
use crate::contact::delete::EppContactDelete;
|
use crate::contact::delete::EppContactDelete;
|
||||||
|
@ -23,13 +27,8 @@ mod request {
|
||||||
use crate::domain::update::DomainAddRemove;
|
use crate::domain::update::DomainAddRemove;
|
||||||
use crate::domain::update::DomainChangeInfo;
|
use crate::domain::update::DomainChangeInfo;
|
||||||
use crate::domain::update::EppDomainUpdate;
|
use crate::domain::update::EppDomainUpdate;
|
||||||
use crate::epp::object::data::{
|
|
||||||
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
|
|
||||||
HostStatus, Phone, PostalInfo,
|
|
||||||
};
|
|
||||||
use crate::epp::request::{EppHello, EppLogin, EppLogout};
|
use crate::epp::request::{EppHello, EppLogin, EppLogout};
|
||||||
use crate::epp::xml::EppXml;
|
use crate::epp::xml::EppXml;
|
||||||
use crate::epp::*;
|
|
||||||
use crate::host::check::EppHostCheck;
|
use crate::host::check::EppHostCheck;
|
||||||
use crate::host::create::EppHostCreate;
|
use crate::host::create::EppHostCreate;
|
||||||
use crate::host::delete::EppHostDelete;
|
use crate::host::delete::EppHostDelete;
|
||||||
|
|
Loading…
Reference in New Issue