From 2e0165a839bdb12bcf7a331782dfe4b760eb3dad Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Thu, 2 Dec 2021 10:28:37 -0800 Subject: [PATCH] Add namestore extension model --- epp-client/src/common.rs | 2 +- epp-client/src/extensions/namestore.rs | 88 ++++++++++++++++++++++++++ epp-client/src/lib.rs | 1 + 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 epp-client/src/extensions/namestore.rs diff --git a/epp-client/src/common.rs b/epp-client/src/common.rs index 7b5ec42..09cf440 100644 --- a/epp-client/src/common.rs +++ b/epp-client/src/common.rs @@ -98,7 +98,7 @@ impl Options { #[serde(rename = "extension")] pub struct Extension { /// Data under the <extension> tag - #[serde(alias = "upData")] + #[serde(alias = "upData", alias = "namestoreExt")] pub data: E, } diff --git a/epp-client/src/extensions/namestore.rs b/epp-client/src/extensions/namestore.rs new file mode 100644 index 0000000..0bdb935 --- /dev/null +++ b/epp-client/src/extensions/namestore.rs @@ -0,0 +1,88 @@ +//! Types for EPP namestore request and responses + +use epp_client_macros::ElementName; +use serde::{Deserialize, Serialize}; + +use crate::{ + common::{ElementName, StringValue}, + request::EppExtension, +}; + +pub const XMLNS: &str = "http://www.verisign-grs.com/epp/namestoreExt-1.1"; + +/// Type that represents the <epp> request for domain <check> command +/// +/// ## Usage +/// +/// ```no_run +/// use std::collections::HashMap; +/// +/// use epp_client::config::{EppClientConfig, RegistryConfig}; +/// use epp_client::EppClient; +/// use epp_client::domain::check::DomainCheck; +/// use epp_client::generate_client_tr_id; +/// use epp_client::extensions::namestore::NameStore; +/// +/// #[tokio::main] +/// async fn main() { +/// // Create a config +/// let mut registry: HashMap = HashMap::new(); +/// registry.insert( +/// "registry_name".to_owned(), +/// RegistryConfig { +/// host: "example.com".to_owned(), +/// port: 700, +/// username: "username".to_owned(), +/// password: "password".to_owned(), +/// ext_uris: None, +/// tls_files: None, +/// }, +/// ); +/// let config = EppClientConfig { registry }; +/// +/// // Create an instance of EppClient, passing the config and the registry you want to connect to +/// let mut client = match EppClient::new(&config, "registry_name").await { +/// Ok(client) => client, +/// Err(e) => panic!("Failed to create EppClient: {}", e) +/// }; +/// +/// let namestore_ext = NameStore::new("com"); +/// +/// // Create an DomainCheck instance +/// let domain_check = DomainCheck::::new( +/// vec!["eppdev-100.com", "eppdev-200.com"], +/// ).with_extension(namestore_ext); +/// +/// // send it to the registry and receive a response of type EppDomainCheckResponse +/// let response = client.transact(domain_check, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// +/// println!("{:?}", response); +/// +/// client.logout().await.unwrap(); +/// } +/// ``` +impl NameStore { + /// Create a new RGP restore report request + pub fn new(subproduct: &str) -> NameStore { + NameStore { + xmlns: XMLNS.to_string(), + subproduct: subproduct.into(), + } + } +} + +impl EppExtension for NameStore { + type Response = NameStore; +} + +#[derive(Serialize, Deserialize, Debug, ElementName)] +#[element_name(name = "namestoreExt:namestoreExt")] +/// Type for EPP XML <namestoreExt> extension +pub struct NameStore { + /// XML namespace for the RGP restore extension + #[serde(rename = "xmlns:namestoreExt", alias = "xmlns")] + pub xmlns: String, + /// The object holding the list of domains to be checked + #[serde(rename = "namestoreExt:subProduct", alias = "subProduct")] + pub subproduct: StringValue, +} diff --git a/epp-client/src/lib.rs b/epp-client/src/lib.rs index 58eb2ad..09f6665 100644 --- a/epp-client/src/lib.rs +++ b/epp-client/src/lib.rs @@ -135,6 +135,7 @@ pub mod domain { } pub mod extensions { + pub mod namestore; pub mod rgp; }