//! Types for EPP domain check request use epp_client_macros::*; use crate::epp::object::data::{DomainAuthInfo, DomainContact, DomainStatus, HostList}; use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait}; use crate::epp::request::Command; use crate::epp::xml::EPP_DOMAIN_XMLNS; use serde::{Deserialize, Serialize}; /// Type that represents the <epp> request for domain <update> command /// with <hostObj> elements in the request for <ns> list /// /// ## Usage /// /// ```no_run /// use std::collections::HashMap; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; /// use epp_client::epp::object::data::{DomainStatus, DomainContact}; /// use epp_client::epp::{EppDomainUpdate, EppDomainUpdateResponse, DomainAddRemove}; /// use epp_client::epp::generate_client_tr_id; /// /// #[tokio::main] /// async fn main() { /// // Create a config /// let mut registry: HashMap = HashMap::new(); /// registry.insert( /// "registry_name".to_owned(), /// EppClientConnection { /// 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) /// }; /// /// // Create an EppDomainUpdate instance /// let mut domain_update = EppDomainUpdate::new("eppdev-100.com", generate_client_tr_id(&client).as_str()); /// /// let add = DomainAddRemove { /// ns: None, /// contacts: None, /// statuses: Some(vec![ /// DomainStatus { /// status: "clientUpdateProhibited".to_string() /// } /// ]) /// }; /// /// let remove = DomainAddRemove { /// ns: None, /// contacts: Some(vec![ /// DomainContact { /// contact_type: "billing".to_string(), /// id: "eppdev-contact-2".to_string() /// } /// ]), /// statuses: None, /// }; /// /// domain_update.add(add); /// domain_update.remove(remove); /// /// // send it to the registry and receive a response of type EppDomainUpdateResponse /// let response = client.transact::<_, EppDomainUpdateResponse>(&domain_update).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` pub type EppDomainUpdate = EppObject>; /// Type for elements under the <chg> tag for domain update #[derive(Serialize, Deserialize, Debug)] pub struct DomainChangeInfo { /// The new registrant contact for the domain #[serde(rename = "domain:registrant", alias = "update")] pub registrant: Option, /// The new auth info for the domain #[serde(rename = "domain:authInfo", alias = "authInfo")] pub auth_info: Option, } /// Type for elements under the <add> and <rem> tags for domain update #[derive(Serialize, Deserialize, Debug)] pub struct DomainAddRemove { /// The list of nameservers to add or remove /// Type T can be either a `HostObjList` or `HostAttrList` #[serde(rename = "domain:ns", alias = "ns")] pub ns: Option, /// The list of contacts to add to or remove from the domain #[serde(rename = "domain:contact", alias = "contact")] pub contacts: Option>, /// The list of statuses to add to or remove from the domain #[serde(rename = "domain:status", alias = "status")] pub statuses: Option>, } /// Type for elements under the <update> tag for domain update #[derive(Serialize, Deserialize, Debug)] pub struct DomainUpdateData { /// XML namespace for domain commands #[serde(rename = "xmlns:domain", alias = "xmlns")] pub xmlns: String, /// The name of the domain to update #[serde(rename = "domain:name", alias = "name")] pub name: StringValue, /// `DomainAddRemove` Object containing the list of elements to be added /// to the domain #[serde(rename = "domain:add", alias = "add")] pub add: Option, /// `DomainAddRemove` Object containing the list of elements to be removed /// from the domain #[serde(rename = "domain:rem", alias = "rem")] pub remove: Option, /// The data under the <chg> tag for domain update #[serde(rename = "domain:chg", alias = "chg")] pub change_info: Option, } #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "update")] /// Type for EPP XML <update> command for domains pub struct DomainUpdate { #[serde(rename = "domain:update", alias = "update")] pub domain: DomainUpdateData, } impl EppDomainUpdate { /// Creates a new EppObject for domain update corresponding to the <epp> tag in EPP XML /// with the <ns> tag containing <hostObj> tags pub fn new(name: &str, client_tr_id: &str) -> EppDomainUpdate { EppObject::build(Command::::new( DomainUpdate { domain: DomainUpdateData { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.to_string_value(), add: None, remove: None, change_info: None, }, }, client_tr_id, )) } /// Sets the data for the <chg> tag pub fn info(&mut self, info: DomainChangeInfo) { self.data.command.domain.change_info = Some(info); } /// Sets the data for the <add> tag pub fn add(&mut self, add: DomainAddRemove) { self.data.command.domain.add = Some(add); } /// Sets the data for the <rem> tag pub fn remove(&mut self, remove: DomainAddRemove) { self.data.command.domain.remove = Some(remove); } }