1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
//! Types for EPP host update request use epp_client_macros::*; use crate::epp::object::data::{HostAddr, HostStatus}; use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait}; use crate::epp::request::Command; use crate::epp::xml::EPP_HOST_XMLNS; use serde::{Deserialize, Serialize}; /// Type that represents the <epp> request for host <update> command /// /// ## Usage /// /// ```ignore /// use epp_client::EppClient; /// use epp_client::epp::object::StringValueTrait; /// use epp_client::epp::object::data::{HostAddr, HostStatus}; /// use epp_client::epp::{EppHostUpdate, EppHostUpdateResponse, HostAddRemove, HostChangeInfo}; /// use epp_client::epp::generate_client_tr_id; /// /// #[tokio::main] /// async fn main() { /// // Create an instance of EppClient, specifying the name of the registry as in /// // the config file /// let mut client = match EppClient::new("verisign").await { /// Ok(client) => client, /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// /// // Create an EppHostUpdate instance /// let mut host_update = EppHostUpdate::new("ns1.eppdev-101.com", generate_client_tr_id(&client).as_str()); /// /// /// Prepare the add and remove sections for the update /// let add = HostAddRemove { /// addresses: Some(vec![ /// HostAddr::new("v4", "177.34.126.17") /// ]), /// statuses: None /// }; /// /// let remove = HostAddRemove { /// addresses: Some(vec![ /// HostAddr::new("v6", "2404:6800:4001:801::200e") /// ]), /// statuses: None, /// }; /// /// host_update.add(add); /// host_update.remove(remove); /// /// // Send a <chg> section as well /// host_update.info(HostChangeInfo { name: "ns2.eppdev-101.com".to_string_value() }); /// /// // send it to the registry and receive a response of type EppHostUpdateResponse /// let response = client.transact::<_, EppHostUpdateResponse>(&host_update).await.unwrap(); /// /// println!("{:?}", response); /// } /// ``` pub type EppHostUpdate = EppObject<Command<HostUpdate>>; /// Type for data under the <chg> tag #[derive(Serialize, Deserialize, Debug)] pub struct HostChangeInfo { /// The new name for the host pub name: StringValue, } /// Type for data under the <add> and <rem> tags #[derive(Serialize, Deserialize, Debug)] pub struct HostAddRemove { /// The IP addresses to be added to or removed from the host #[serde(rename = "addr")] pub addresses: Option<Vec<HostAddr>>, /// The statuses to be added to or removed from the host #[serde(rename = "status")] pub statuses: Option<Vec<HostStatus>>, } /// Type for data under the host <update> tag #[derive(Serialize, Deserialize, Debug)] pub struct HostUpdateData { /// XML namespace for host commands xmlns: String, /// The name of the host name: StringValue, /// The IP addresses and statuses to be added to the host add: Option<HostAddRemove>, /// The IP addresses and statuses to be removed from the host #[serde(rename = "rem")] remove: Option<HostAddRemove>, /// The host details that need to be updated #[serde(rename = "chg")] change_info: Option<HostChangeInfo>, } #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "update")] /// Type for EPP XML <update> command for hosts pub struct HostUpdate { /// The instance holding the data for the host to be updated #[serde(rename = "update")] host: HostUpdateData, } impl EppHostUpdate { /// Creates a new EppObject for host update corresponding to the <epp> tag in EPP XML pub fn new(name: &str, client_tr_id: &str) -> EppHostUpdate { EppObject::build(Command::<HostUpdate>::new( HostUpdate { host: HostUpdateData { xmlns: EPP_HOST_XMLNS.to_string(), name: name.to_string_value(), add: None, remove: None, change_info: None, }, }, client_tr_id, )) } /// Sets the data for the <chg> element of the host update pub fn info(&mut self, info: HostChangeInfo) { self.data.command.host.change_info = Some(info); } /// Sets the data for the <add> element of the host update pub fn add(&mut self, add: HostAddRemove) { self.data.command.host.add = Some(add); } /// Sets the data for the <rem> element of the host update pub fn remove(&mut self, remove: HostAddRemove) { self.data.command.host.remove = Some(remove); } }