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 crate::common::{ElementName, EppObject, Extension, StringValue};
use crate::common::{ElementName, NoExtension, StringValue};
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::CommandWithExtension;
use crate::response::EppCommandResponse;
use crate::request::EppExtension;
use chrono::{DateTime, SecondsFormat, Utc};
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
///
@ -20,8 +17,11 @@ use serde::{Deserialize, Serialize};
///
/// use epp_client::config::{EppClientConfig, EppClientConnection};
/// 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::common::NoExtension;
/// use chrono::{DateTime, NaiveDate};
/// use std::str::FromStr;
///
@ -61,35 +61,30 @@ use serde::{Deserialize, Serialize};
/// ];
/// let other = "Supporting information goes here.";
///
/// // Create an EppDomainRgpRestoreReport instance
/// let domain_restore_report = EppDomainRgpRestoreReport::new(
/// "eppdev.com",
/// let domain_restore_report = RgpRestoreReport::new(
/// pre_data,
/// post_data,
/// deleted_at,
/// restored_at,
/// restore_reason,
/// &statements,
/// other,
/// generate_client_tr_id(&client).as_str()
/// other
/// );
///
/// // send it to the registry and receive a response of type EppDomainRgpRestoreReportResponse
/// let response = client.transact::<_, EppDomainRgpRestoreReportResponse>(&domain_restore_report).await.unwrap();
/// // Create an DomainUpdate instance
/// 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);
///
/// client.logout().await.unwrap();
/// }
/// ```
pub type EppDomainRgpRestoreReport =
EppObject<CommandWithExtension<DomainUpdateRequest, RgpRestoreReportRequest>>;
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)]
impl RgpRestoreReport {
/// Create a new RGP restore report request
pub fn new(
name: &str,
pre_data: &str,
post_data: &str,
deleted_at: DateTime<Utc>,
@ -97,29 +92,14 @@ impl EppDomainRgpRestoreReport {
restore_reason: &str,
statements: &[&str],
other: &str,
client_tr_id: &str,
) -> EppDomainRgpRestoreReport {
) -> RgpRestoreReport {
let statements = statements.iter().map(|&s| s.into()).collect();
let command = CommandWithExtension::<DomainUpdateRequest, RgpRestoreReportRequest> {
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: RgpRestoreReportRequest {
RgpRestoreReport {
xmlns: EPP_DOMAIN_RGP_EXT_XMLNS.to_string(),
restore: RgpRestoreReportRequestSection {
restore: RgpRestoreReportSection {
op: "report".to_string(),
report: RgpRestoreReportRequestData {
report: RgpRestoreReportSectionData {
pre_data: pre_data.into(),
post_data: post_data.into(),
deleted_at: deleted_at
@ -133,21 +113,17 @@ impl EppDomainRgpRestoreReport {
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
pub type EppDomainRgpRestoreReportResponse = EppCommandResponse;
impl EppExtension for RgpRestoreReport {
type Response = NoExtension;
}
/// Type corresponding to the &lt;report&gt; section in the EPP rgp restore extension
#[derive(Serialize, Deserialize, Debug)]
pub struct RgpRestoreReportRequestData {
pub struct RgpRestoreReportSectionData {
/// The pre-delete registration date
#[serde(rename = "rgp:preData", alias = "preData")]
pre_data: StringValue,
@ -173,22 +149,22 @@ pub struct RgpRestoreReportRequestData {
/// Type corresponding to the &lt;restore&gt; section in the rgp restore extension
#[derive(Serialize, Deserialize, Debug)]
pub struct RgpRestoreReportRequestSection {
pub struct RgpRestoreReportSection {
/// The value of the op attribute for the &lt;restore&gt; tag
op: String,
/// Data for the &lt;report&gt; tag
#[serde(rename = "rgp:report", alias = "report")]
report: RgpRestoreReportRequestData,
report: RgpRestoreReportSectionData,
}
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "rgp:update")]
/// Type for EPP XML &lt;check&gt; command for domains
pub struct RgpRestoreReportRequest {
pub struct RgpRestoreReport {
/// XML namespace for the RGP restore extension
#[serde(rename = "xmlns:rgp", alias = "xmlns")]
xmlns: String,
/// The object holding the list of domains to be checked
#[serde(rename = "rgp:restore", alias = "restore")]
restore: RgpRestoreReportRequestSection,
restore: RgpRestoreReportSection,
}

View File

@ -2,12 +2,11 @@
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::update::{DomainChangeInfo, DomainUpdateRequest, DomainUpdateRequestData};
use crate::domain::EPP_DOMAIN_XMLNS;
use crate::request::CommandWithExtension;
use crate::response::CommandResponseWithExtension;
use crate::request::EppExtension;
use serde::{Deserialize, Serialize};
/// 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::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;
///
/// #[tokio::main]
@ -45,57 +45,41 @@ use serde::{Deserialize, Serialize};
/// Err(e) => panic!("Failed to create EppClient: {}", e)
/// };
///
/// // Create an EppDomainRgpRestoreRequest instance
/// let domain_restore_req = EppDomainRgpRestoreRequest::new(
/// "eppdev.com",
/// generate_client_tr_id(&client).as_str()
/// );
/// // Create an RgpRestoreRequest instance
/// let domain_restore_req = RgpRestoreRequest::new();
///
/// // send it to the registry and receive a response of type EppDomainRgpRestoreRequestResponse
/// let response = client.transact::<_, EppDomainRgpRestoreRequestResponse>(&domain_restore_req).await.unwrap();
/// // Create an DomainUpdate instance
/// 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);
///
/// client.logout().await.unwrap();
/// }
/// ```
pub type EppDomainRgpRestoreRequest =
EppObject<CommandWithExtension<DomainUpdateRequest, RgpRestoreRequest>>;
impl EppDomainRgpRestoreRequest {
/// Creates a new EppObject for domain rgp restore request corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(name: &str, client_tr_id: &str) -> EppDomainRgpRestoreRequest {
let command = CommandWithExtension::<DomainUpdateRequest, RgpRestoreRequest> {
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 {
impl RgpRestoreRequest {
/// Creates a new instance of EppDomainRgpRestoreRequest
pub fn new() -> RgpRestoreRequest {
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
pub type EppDomainRgpRestoreRequestResponse =
EppObject<CommandResponseWithExtension<NoExtension, RgpRequestResponse>>;
impl Default for RgpRestoreRequest {
fn default() -> Self {
Self::new()
}
}
impl EppExtension for RgpRestoreRequest {
type Response = RgpRequestResponse;
}
// Request

View File

@ -14,7 +14,7 @@ mod response {
use crate::domain::delete::DomainDelete;
use crate::domain::info::DomainInfo;
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::DomainTransferCancel;
use crate::domain::transfer::DomainTransferQuery;
@ -639,13 +639,13 @@ mod response {
#[test]
fn rgp_restore_response() {
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.data.result.message, SUCCESS_MSG.into());
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());
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::info::DomainInfo;
use crate::domain::renew::DomainRenew;
use crate::domain::rgp::report::EppDomainRgpRestoreReport;
use crate::domain::rgp::request::EppDomainRgpRestoreRequest;
use crate::domain::rgp::report::RgpRestoreReport;
use crate::domain::rgp::request::RgpRestoreRequest;
use crate::domain::transfer::DomainTransferApprove;
use crate::domain::transfer::DomainTransferCancel;
use crate::domain::transfer::DomainTransferQuery;
@ -524,9 +524,19 @@ mod request {
fn rgp_restore_request() {
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);
}
@ -548,8 +558,7 @@ mod request {
];
let other = "Supporting information goes here.";
let object = EppDomainRgpRestoreReport::new(
"eppdev.com",
let domain_restore_report = RgpRestoreReport::new(
pre_data,
post_data,
deleted_at,
@ -557,10 +566,19 @@ mod request {
restore_reason,
statements,
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);
}