Migrate rgp extension to new API

This commit is contained in:
Nicholas Rempel 2021-11-26 14:21:38 -08:00 committed by masalachai
parent 31fc61f4b0
commit 9e1d11f9f3
4 changed files with 104 additions and 126 deletions

View File

@ -2,16 +2,13 @@
use epp_client_macros::*; use epp_client_macros::*;
use crate::common::{ElementName, EppObject, Extension, StringValue}; use crate::common::{ElementName, NoExtension, StringValue};
use crate::domain::rgp::EPP_DOMAIN_RGP_EXT_XMLNS; use crate::domain::rgp::EPP_DOMAIN_RGP_EXT_XMLNS;
use crate::domain::update::{DomainChangeInfo, DomainUpdateRequest, DomainUpdateRequestData}; use crate::request::EppExtension;
use crate::domain::EPP_DOMAIN_XMLNS;
use crate::request::CommandWithExtension;
use crate::response::EppCommandResponse;
use chrono::{DateTime, SecondsFormat, Utc}; use chrono::{DateTime, SecondsFormat, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Type that represents the <epp> request for domain rgp restore report command /// Type that represents the domain rgp restore report extension
/// ///
/// ## Usage /// ## Usage
/// ///
@ -20,8 +17,11 @@ 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::domain::rgp::report::{EppDomainRgpRestoreReport, EppDomainRgpRestoreReportResponse}; /// use epp_client::common::{DomainStatus, DomainContact};
/// use epp_client::domain::rgp::report::RgpRestoreReport;
/// use epp_client::domain::update::DomainUpdate;
/// use epp_client::generate_client_tr_id; /// use epp_client::generate_client_tr_id;
/// use epp_client::common::NoExtension;
/// use chrono::{DateTime, NaiveDate}; /// use chrono::{DateTime, NaiveDate};
/// use std::str::FromStr; /// use std::str::FromStr;
/// ///
@ -61,35 +61,30 @@ use serde::{Deserialize, Serialize};
/// ]; /// ];
/// let other = "Supporting information goes here."; /// let other = "Supporting information goes here.";
/// ///
/// // Create an EppDomainRgpRestoreReport instance /// let domain_restore_report = RgpRestoreReport::new(
/// let domain_restore_report = EppDomainRgpRestoreReport::new(
/// "eppdev.com",
/// pre_data, /// pre_data,
/// post_data, /// post_data,
/// deleted_at, /// deleted_at,
/// restored_at, /// restored_at,
/// restore_reason, /// restore_reason,
/// &statements, /// &statements,
/// other, /// other
/// generate_client_tr_id(&client).as_str()
/// ); /// );
/// ///
/// // send it to the registry and receive a response of type EppDomainRgpRestoreReportResponse /// // Create an DomainUpdate instance
/// let response = client.transact::<_, EppDomainRgpRestoreReportResponse>(&domain_restore_report).await.unwrap(); /// let mut domain_update = DomainUpdate::<RgpRestoreReport>::new("eppdev-100.com").with_extension(domain_restore_report);
///
/// // send it to the registry and receive a response of type EppDomainUpdateResponse
/// let response = client.transact_new(domain_update, generate_client_tr_id(&client).as_str()).await.unwrap();
/// ///
/// println!("{:?}", response); /// println!("{:?}", response);
/// ///
/// client.logout().await.unwrap(); /// client.logout().await.unwrap();
/// } /// }
/// ``` /// ```
pub type EppDomainRgpRestoreReport = impl RgpRestoreReport {
EppObject<CommandWithExtension<DomainUpdateRequest, RgpRestoreReportRequest>>; /// Create a new RGP restore report request
impl EppDomainRgpRestoreReport {
/// Creates a new EppObject for domain rgp restore report corresponding to the &lt;epp&gt; tag in EPP XML
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
name: &str,
pre_data: &str, pre_data: &str,
post_data: &str, post_data: &str,
deleted_at: DateTime<Utc>, deleted_at: DateTime<Utc>,
@ -97,57 +92,38 @@ impl EppDomainRgpRestoreReport {
restore_reason: &str, restore_reason: &str,
statements: &[&str], statements: &[&str],
other: &str, other: &str,
client_tr_id: &str, ) -> RgpRestoreReport {
) -> EppDomainRgpRestoreReport {
let statements = statements.iter().map(|&s| s.into()).collect(); let statements = statements.iter().map(|&s| s.into()).collect();
let command = CommandWithExtension::<DomainUpdateRequest, RgpRestoreReportRequest> { RgpRestoreReport {
command: DomainUpdateRequest { xmlns: EPP_DOMAIN_RGP_EXT_XMLNS.to_string(),
domain: DomainUpdateRequestData { restore: RgpRestoreReportSection {
xmlns: EPP_DOMAIN_XMLNS.to_string(), op: "report".to_string(),
name: name.into(), report: RgpRestoreReportSectionData {
add: None, pre_data: pre_data.into(),
remove: None, post_data: post_data.into(),
change_info: Some(DomainChangeInfo { deleted_at: deleted_at
registrant: None, .to_rfc3339_opts(SecondsFormat::AutoSi, true)
auth_info: None, .into(),
}), restored_at: restored_at
.to_rfc3339_opts(SecondsFormat::AutoSi, true)
.into(),
restore_reason: restore_reason.into(),
statements,
other: other.into(),
}, },
}, },
extension: Some(Extension { }
data: RgpRestoreReportRequest {
xmlns: EPP_DOMAIN_RGP_EXT_XMLNS.to_string(),
restore: RgpRestoreReportRequestSection {
op: "report".to_string(),
report: RgpRestoreReportRequestData {
pre_data: pre_data.into(),
post_data: post_data.into(),
deleted_at: deleted_at
.to_rfc3339_opts(SecondsFormat::AutoSi, true)
.into(),
restored_at: restored_at
.to_rfc3339_opts(SecondsFormat::AutoSi, true)
.into(),
restore_reason: restore_reason.into(),
statements,
other: other.into(),
},
},
},
}),
client_tr_id: client_tr_id.into(),
};
EppObject::build(command)
} }
} }
/// Type that represents the &lt;epp&gt; tag for the EPP XML rgp restore report response impl EppExtension for RgpRestoreReport {
pub type EppDomainRgpRestoreReportResponse = EppCommandResponse; type Response = NoExtension;
}
/// Type corresponding to the &lt;report&gt; section in the EPP rgp restore extension /// Type corresponding to the &lt;report&gt; section in the EPP rgp restore extension
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct RgpRestoreReportRequestData { pub struct RgpRestoreReportSectionData {
/// The pre-delete registration date /// The pre-delete registration date
#[serde(rename = "rgp:preData", alias = "preData")] #[serde(rename = "rgp:preData", alias = "preData")]
pre_data: StringValue, pre_data: StringValue,
@ -173,22 +149,22 @@ pub struct RgpRestoreReportRequestData {
/// Type corresponding to the &lt;restore&gt; section in the rgp restore extension /// Type corresponding to the &lt;restore&gt; section in the rgp restore extension
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct RgpRestoreReportRequestSection { pub struct RgpRestoreReportSection {
/// The value of the op attribute for the &lt;restore&gt; tag /// The value of the op attribute for the &lt;restore&gt; tag
op: String, op: String,
/// Data for the &lt;report&gt; tag /// Data for the &lt;report&gt; tag
#[serde(rename = "rgp:report", alias = "report")] #[serde(rename = "rgp:report", alias = "report")]
report: RgpRestoreReportRequestData, report: RgpRestoreReportSectionData,
} }
#[derive(Serialize, Deserialize, Debug, ElementName)] #[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "rgp:update")] #[element_name(name = "rgp:update")]
/// Type for EPP XML &lt;check&gt; command for domains /// Type for EPP XML &lt;check&gt; command for domains
pub struct RgpRestoreReportRequest { pub struct RgpRestoreReport {
/// XML namespace for the RGP restore extension /// XML namespace for the RGP restore extension
#[serde(rename = "xmlns:rgp", alias = "xmlns")] #[serde(rename = "xmlns:rgp", alias = "xmlns")]
xmlns: String, xmlns: String,
/// The object holding the list of domains to be checked /// The object holding the list of domains to be checked
#[serde(rename = "rgp:restore", alias = "restore")] #[serde(rename = "rgp:restore", alias = "restore")]
restore: RgpRestoreReportRequestSection, restore: RgpRestoreReportSection,
} }

View File

@ -2,12 +2,11 @@
use epp_client_macros::*; use epp_client_macros::*;
use crate::common::{ElementName, EppObject, Extension, NoExtension}; use crate::common::ElementName;
use crate::domain::rgp::EPP_DOMAIN_RGP_EXT_XMLNS; use crate::domain::rgp::EPP_DOMAIN_RGP_EXT_XMLNS;
use crate::domain::update::{DomainChangeInfo, DomainUpdateRequest, DomainUpdateRequestData};
use crate::domain::EPP_DOMAIN_XMLNS; use crate::request::EppExtension;
use crate::request::CommandWithExtension;
use crate::response::CommandResponseWithExtension;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Type that represents the &lt;epp&gt; request for a domain rgp restore request command /// Type that represents the &lt;epp&gt; request for a domain rgp restore request command
@ -19,7 +18,8 @@ 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::domain::rgp::request::{EppDomainRgpRestoreRequest, EppDomainRgpRestoreRequestResponse}; /// use epp_client::domain::rgp::request::RgpRestoreRequest;
/// use epp_client::domain::update::DomainUpdate;
/// use epp_client::generate_client_tr_id; /// use epp_client::generate_client_tr_id;
/// ///
/// #[tokio::main] /// #[tokio::main]
@ -45,57 +45,41 @@ use serde::{Deserialize, Serialize};
/// Err(e) => panic!("Failed to create EppClient: {}", e) /// Err(e) => panic!("Failed to create EppClient: {}", e)
/// }; /// };
/// ///
/// // Create an EppDomainRgpRestoreRequest instance /// // Create an RgpRestoreRequest instance
/// let domain_restore_req = EppDomainRgpRestoreRequest::new( /// let domain_restore_req = RgpRestoreRequest::new();
/// "eppdev.com",
/// generate_client_tr_id(&client).as_str()
/// );
/// ///
/// // send it to the registry and receive a response of type EppDomainRgpRestoreRequestResponse /// // Create an DomainUpdate instance
/// let response = client.transact::<_, EppDomainRgpRestoreRequestResponse>(&domain_restore_req).await.unwrap(); /// let mut domain_update = DomainUpdate::<RgpRestoreRequest>::new("eppdev-100.com").with_extension(domain_restore_req);
///
/// // send it to the registry and receive a response of type EppDomainUpdateResponse
/// let response = client.transact_new(domain_update, generate_client_tr_id(&client).as_str()).await.unwrap();
/// ///
/// println!("{:?}", response); /// println!("{:?}", response);
/// ///
/// client.logout().await.unwrap(); /// client.logout().await.unwrap();
/// } /// }
/// ``` /// ```
pub type EppDomainRgpRestoreRequest = impl RgpRestoreRequest {
EppObject<CommandWithExtension<DomainUpdateRequest, RgpRestoreRequest>>; /// Creates a new instance of EppDomainRgpRestoreRequest
pub fn new() -> RgpRestoreRequest {
impl EppDomainRgpRestoreRequest { RgpRestoreRequest {
/// Creates a new EppObject for domain rgp restore request corresponding to the &lt;epp&gt; tag in EPP XML xmlns: EPP_DOMAIN_RGP_EXT_XMLNS.to_string(),
pub fn new(name: &str, client_tr_id: &str) -> EppDomainRgpRestoreRequest { restore: RgpRestoreRequestData {
let command = CommandWithExtension::<DomainUpdateRequest, RgpRestoreRequest> { op: "request".to_string(),
command: DomainUpdateRequest {
domain: DomainUpdateRequestData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
add: None,
remove: None,
change_info: Some(DomainChangeInfo {
registrant: None,
auth_info: None,
}),
},
}, },
extension: Some(Extension { }
data: RgpRestoreRequest {
xmlns: EPP_DOMAIN_RGP_EXT_XMLNS.to_string(),
restore: RgpRestoreRequestData {
op: "request".to_string(),
},
},
}),
client_tr_id: client_tr_id.into(),
};
EppObject::build(command)
} }
} }
/// Type that represents the &lt;epp&gt; tag for the EPP XML rgp restore request response impl Default for RgpRestoreRequest {
pub type EppDomainRgpRestoreRequestResponse = fn default() -> Self {
EppObject<CommandResponseWithExtension<NoExtension, RgpRequestResponse>>; Self::new()
}
}
impl EppExtension for RgpRestoreRequest {
type Response = RgpRequestResponse;
}
// Request // Request

View File

@ -14,7 +14,7 @@ mod response {
use crate::domain::delete::DomainDelete; use crate::domain::delete::DomainDelete;
use crate::domain::info::DomainInfo; use crate::domain::info::DomainInfo;
use crate::domain::renew::DomainRenew; use crate::domain::renew::DomainRenew;
use crate::domain::rgp::request::EppDomainRgpRestoreRequestResponse; use crate::domain::rgp::request::RgpRestoreRequest;
use crate::domain::transfer::DomainTransferApprove; use crate::domain::transfer::DomainTransferApprove;
use crate::domain::transfer::DomainTransferCancel; use crate::domain::transfer::DomainTransferCancel;
use crate::domain::transfer::DomainTransferQuery; use crate::domain::transfer::DomainTransferQuery;
@ -639,13 +639,13 @@ mod response {
#[test] #[test]
fn rgp_restore_response() { fn rgp_restore_response() {
let xml = get_xml("response/domain/rgp_restore.xml").unwrap(); let xml = get_xml("response/domain/rgp_restore.xml").unwrap();
let object = EppDomainRgpRestoreRequestResponse::deserialize(xml.as_str()).unwrap(); let object = DomainUpdate::<RgpRestoreRequest>::deserialize_response(xml.as_str()).unwrap();
let ext = object.data.extension.unwrap(); let ext = object.extension.unwrap();
assert_eq!(object.data.result.code, 1000); assert_eq!(object.result.code, 1000);
assert_eq!(object.data.result.message, SUCCESS_MSG.into()); assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(ext.data.rgp_status.status, "pendingRestore".to_string()); assert_eq!(ext.data.rgp_status.status, "pendingRestore".to_string());
assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
} }
} }

View File

@ -21,8 +21,8 @@ mod request {
use crate::domain::delete::DomainDelete; use crate::domain::delete::DomainDelete;
use crate::domain::info::DomainInfo; use crate::domain::info::DomainInfo;
use crate::domain::renew::DomainRenew; use crate::domain::renew::DomainRenew;
use crate::domain::rgp::report::EppDomainRgpRestoreReport; use crate::domain::rgp::report::RgpRestoreReport;
use crate::domain::rgp::request::EppDomainRgpRestoreRequest; use crate::domain::rgp::request::RgpRestoreRequest;
use crate::domain::transfer::DomainTransferApprove; use crate::domain::transfer::DomainTransferApprove;
use crate::domain::transfer::DomainTransferCancel; use crate::domain::transfer::DomainTransferCancel;
use crate::domain::transfer::DomainTransferQuery; use crate::domain::transfer::DomainTransferQuery;
@ -524,9 +524,19 @@ mod request {
fn rgp_restore_request() { fn rgp_restore_request() {
let xml = get_xml("request/domain/rgp_restore_request.xml").unwrap(); let xml = get_xml("request/domain/rgp_restore_request.xml").unwrap();
let object = EppDomainRgpRestoreRequest::new("eppdev.com", CLTRID); let domain_restore_request = RgpRestoreRequest::new();
let serialized = object.serialize().unwrap(); let mut object = DomainUpdate::<RgpRestoreReport>::new("eppdev.com")
.with_extension(domain_restore_request);
let change_info = DomainChangeInfo {
registrant: None,
auth_info: None,
};
object.info(change_info);
let serialized = object.serialize_request(CLTRID).unwrap();
assert_eq!(xml, serialized); assert_eq!(xml, serialized);
} }
@ -548,8 +558,7 @@ mod request {
]; ];
let other = "Supporting information goes here."; let other = "Supporting information goes here.";
let object = EppDomainRgpRestoreReport::new( let domain_restore_report = RgpRestoreReport::new(
"eppdev.com",
pre_data, pre_data,
post_data, post_data,
deleted_at, deleted_at,
@ -557,10 +566,19 @@ mod request {
restore_reason, restore_reason,
statements, statements,
other, other,
CLTRID,
); );
let serialized = object.serialize().unwrap(); let mut object = DomainUpdate::<RgpRestoreReport>::new("eppdev.com")
.with_extension(domain_restore_report);
let change_info = DomainChangeInfo {
registrant: None,
auth_info: None,
};
object.info(change_info);
let serialized = object.serialize_request(CLTRID).unwrap();
assert_eq!(xml, serialized); assert_eq!(xml, serialized);
} }