From 0b4257948471c2bafaa6007e05154dd1666e8798 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Tue, 30 Nov 2021 15:39:54 -0800 Subject: [PATCH] Remove credentials from Client and Connection and remove login, logout, and generate_client_tr_id --- README.md | 35 +++++----- epp-client/README.md | 35 +++++----- epp-client/src/client.rs | 83 +++--------------------- epp-client/src/config.rs | 23 ------- epp-client/src/contact/check.rs | 14 ++-- epp-client/src/contact/create.rs | 14 ++-- epp-client/src/contact/delete.rs | 14 ++-- epp-client/src/contact/info.rs | 14 ++-- epp-client/src/contact/update.rs | 14 ++-- epp-client/src/domain/check.rs | 14 ++-- epp-client/src/domain/create.rs | 14 ++-- epp-client/src/domain/delete.rs | 14 ++-- epp-client/src/domain/info.rs | 14 ++-- epp-client/src/domain/renew.rs | 14 ++-- epp-client/src/domain/transfer.rs | 76 +++++++++++++--------- epp-client/src/domain/update.rs | 14 ++-- epp-client/src/extensions/namestore.rs | 15 +++-- epp-client/src/extensions/rgp/report.rs | 14 ++-- epp-client/src/extensions/rgp/request.rs | 15 +++-- epp-client/src/host/check.rs | 14 ++-- epp-client/src/host/create.rs | 14 ++-- epp-client/src/host/delete.rs | 14 ++-- epp-client/src/host/info.rs | 14 ++-- epp-client/src/host/update.rs | 14 ++-- epp-client/src/lib.rs | 16 ++--- epp-client/src/message/ack.rs | 14 ++-- epp-client/src/message/poll.rs | 14 ++-- epp-client/src/request.rs | 8 --- 28 files changed, 264 insertions(+), 308 deletions(-) diff --git a/README.md b/README.md index 106ac5d..4207041 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,10 @@ use std::collections::HashMap; use epp_client::config::{EppClientConfig, RegistryConfig}; use epp_client::EppClient; -use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse}; -use epp_client::generate_client_tr_id; +use epp_client::domain::check::DomainCheck; +use epp_client::common::NoExtension; +use epp_client::login::Login; +use epp_client::logout::Logout; #[tokio::main] async fn main() { @@ -67,37 +69,32 @@ async fn main() { 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 + // 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) }; - // Make a domain check call, which returns an object of type EppDomainCheckResponse - // that contains the result of the call - let domain_check = EppDomainCheck::new( - vec!["eppdev.com", "eppdev.net"] - generate_client_tr_id(&client).as_str() + let login = Login::::new("username", "password", &None); + client.transact(login, "transaction-id").await.unwrap(); + + // Create an DomainCheck instance + let domain_check = DomainCheck::::new( + vec!["eppdev-100.com", "eppdev-100.net"], ); - let response = client.transact::<_, EppDomainCheckResponse>(&domain_check).await.unwrap(); + // send it to the registry and receive a response of type EppDomainCheckResponse + let response = client.transact(domain_check, "transaction-id").await.unwrap(); - // print the availability results - response.data.res_data.unwrap().check_data.domain_list - .iter() - .for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available)); + println!("{:?}", response); - // Close the connection - client.logout().await.unwrap(); + let logout = Logout::::new(); + client.transact(logout, "transaction-id").await.unwrap(); } ``` diff --git a/epp-client/README.md b/epp-client/README.md index 106ac5d..4207041 100644 --- a/epp-client/README.md +++ b/epp-client/README.md @@ -55,8 +55,10 @@ use std::collections::HashMap; use epp_client::config::{EppClientConfig, RegistryConfig}; use epp_client::EppClient; -use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse}; -use epp_client::generate_client_tr_id; +use epp_client::domain::check::DomainCheck; +use epp_client::common::NoExtension; +use epp_client::login::Login; +use epp_client::logout::Logout; #[tokio::main] async fn main() { @@ -67,37 +69,32 @@ async fn main() { 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 + // 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) }; - // Make a domain check call, which returns an object of type EppDomainCheckResponse - // that contains the result of the call - let domain_check = EppDomainCheck::new( - vec!["eppdev.com", "eppdev.net"] - generate_client_tr_id(&client).as_str() + let login = Login::::new("username", "password", &None); + client.transact(login, "transaction-id").await.unwrap(); + + // Create an DomainCheck instance + let domain_check = DomainCheck::::new( + vec!["eppdev-100.com", "eppdev-100.net"], ); - let response = client.transact::<_, EppDomainCheckResponse>(&domain_check).await.unwrap(); + // send it to the registry and receive a response of type EppDomainCheckResponse + let response = client.transact(domain_check, "transaction-id").await.unwrap(); - // print the availability results - response.data.res_data.unwrap().check_data.domain_list - .iter() - .for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available)); + println!("{:?}", response); - // Close the connection - client.logout().await.unwrap(); + let logout = Logout::::new(); + client.transact(logout, "transaction-id").await.unwrap(); } ``` diff --git a/epp-client/src/client.rs b/epp-client/src/client.rs index 6740532..bdee383 100644 --- a/epp-client/src/client.rs +++ b/epp-client/src/client.rs @@ -8,7 +8,6 @@ //! 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::common::NoExtension; //! //! #[tokio::main] @@ -21,9 +20,6 @@ //! RegistryConfig { //! host: "example.com".to_owned(), //! port: 700, -//! username: "username".to_owned(), -//! password: "password".to_owned(), -//! ext_uris: None, //! tls_files: None, //! }, //! ); @@ -41,45 +37,30 @@ //! //! // Execute an EPP Command against the registry with distinct request and response objects //! let domain_check = DomainCheck::::new(vec!["eppdev.com", "eppdev.net"]); -//! let response = client.transact(domain_check, generate_client_tr_id(&client).as_str()).await.unwrap(); +//! let response = client.transact(domain_check, "transaction-id").await.unwrap(); //! println!("{:?}", response); //! //! } //! ``` -use std::time::SystemTime; use std::{error::Error, fmt::Debug}; -use crate::common::{EppObject, NoExtension}; +use crate::common::EppObject; use crate::config::EppClientConfig; use crate::error; use crate::hello::{Greeting, Hello}; -use crate::login::Login; -use crate::logout::Logout; use crate::registry::{epp_connect, EppConnection}; -use crate::request::{generate_client_tr_id, EppExtension, EppRequest}; -use crate::response::{Response, ResponseStatus}; +use crate::request::{EppExtension, EppRequest}; +use crate::response::Response; use crate::xml::EppXml; /// Instances of the EppClient type are used to transact with the registry. /// Once initialized, the EppClient instance can serialize EPP requests to XML and send them /// to the registry and deserialize the XML responses from the registry to local types pub struct EppClient { - credentials: (String, String), - ext_uris: Option>, connection: EppConnection, } -/// A function to generate a simple client TRID. Should only be used for testing, library users -/// should generate a client TRID according to their own requirements -pub fn default_client_tr_id_fn(client: &EppClient) -> String { - let timestamp = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { - Ok(time) => time, - Err(e) => panic!("Error in client TRID gen function: {}", e), - }; - format!("{}:{}", &client.username(), timestamp.as_secs()) -} - impl EppClient { /// Creates a new EppClient object and does an EPP Login to a given registry to become ready /// for subsequent transactions on this client instance @@ -93,43 +74,12 @@ impl EppClient { }; let stream = epp_connect(registry_creds).await?; - let credentials = registry_creds.credentials(); - let ext_uris = registry_creds.ext_uris(); - - let ext_uris = - ext_uris.map(|uris| uris.iter().map(|u| u.to_string()).collect::>()); - let connection = EppConnection::new(registry.to_string(), stream).await?; - EppClient::build(connection, credentials, ext_uris).await + + Ok(EppClient { connection }) } - /// Makes a login request to the registry and initializes an EppClient instance with it - async fn build( - connection: EppConnection, - credentials: (String, String), - ext_uris: Option>, - ) -> Result> { - let mut client = EppClient { - connection, - credentials, - ext_uris, - }; - - let client_tr_id = generate_client_tr_id(&client.credentials.0)?; - let login_request = Login::::new( - &client.credentials.0, - &client.credentials.1, - &client.ext_uris, - ); - - client - .transact(login_request, client_tr_id.as_str()) - .await?; - - Ok(client) - } - - /// Executes an EPP Hello call and returns the response as an `EppGreeting` + /// Executes an EPP Hello call and returns the response as an `Greeting` pub async fn hello(&mut self) -> Result> { let hello_xml = EppObject::::build(Hello).serialize()?; @@ -154,11 +104,6 @@ impl EppClient { T::deserialize_response(&response) } - /// Fetches the username used in the registry connection - pub fn username(&self) -> String { - self.credentials.0.to_string() - } - /// Accepts raw EPP XML and returns the raw EPP XML response to it. /// Not recommended for direct use but sometimes can be useful for debugging pub async fn transact_xml(&mut self, xml: &str) -> Result> { @@ -170,20 +115,8 @@ impl EppClient { String::from(&self.connection.greeting) } - /// Returns the greeting received on establishment of the connection as an `EppGreeting` + /// Returns the greeting received on establishment of the connection as an `Greeting` pub fn greeting(&self) -> Result { EppObject::::deserialize(&self.connection.greeting).map(|obj| obj.data) } - - /// Sends the EPP Logout command to log out of the EPP session - pub async fn logout(&mut self) -> Result, error::Error> { - let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap(); - let epp_logout = Logout::::new(); - - let response = self.transact(epp_logout, client_tr_id.as_str()).await?; - - self.connection.shutdown().await?; - - Ok(response) - } } diff --git a/epp-client/src/config.rs b/epp-client/src/config.rs index 5647190..2ed6319 100644 --- a/epp-client/src/config.rs +++ b/epp-client/src/config.rs @@ -16,9 +16,6 @@ //! RegistryConfig { //! host: "example.com".to_owned(), //! port: 700, -//! username: "username".to_owned(), -//! password: "password".to_owned(), -//! ext_uris: None, //! tls_files: None, //! }, //! ); @@ -26,12 +23,6 @@ //! //! // Get configuration for the relevant registry section //! let registry = config.registry("verisign").unwrap(); -//! -//! // Get username and password -//! let credentials = registry.credentials(); -//! -//! // Get EPP service extensions -//! let service_extensions = registry.ext_uris().unwrap(); //! ``` use std::collections::HashMap; @@ -63,19 +54,5 @@ impl EppClientConfig { pub struct RegistryConfig { pub host: String, pub port: u16, - pub username: String, - pub password: String, - pub ext_uris: Option>, pub tls_files: Option, } - -impl RegistryConfig { - /// Returns the EPP username and password as a tuple - pub fn credentials(&self) -> (String, String) { - (self.username.to_string(), self.password.to_string()) - } - /// Returns the service extension URIs to be set in the connection to the registry - pub fn ext_uris(&self) -> Option<&Vec> { - self.ext_uris.as_ref() - } -} diff --git a/epp-client/src/contact/check.rs b/epp-client/src/contact/check.rs index 4ea81ff..6cc90d7 100644 --- a/epp-client/src/contact/check.rs +++ b/epp-client/src/contact/check.rs @@ -33,8 +33,9 @@ impl EppRequest for ContactCheck { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::contact::check::ContactCheck; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -45,9 +46,6 @@ impl EppRequest for ContactCheck { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -59,6 +57,9 @@ impl EppRequest for ContactCheck { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an ContactCheck instance /// let contact_check = ContactCheck::::new( /// &["epp-client-c1", "epp-client-c2"] @@ -66,10 +67,11 @@ impl EppRequest for ContactCheck { /// /// // send it to the registry and receive a response of type ContactCheckResponse /// -/// let response = client.transact(contact_check, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(contact_check, "transaction-id").await.unwrap(); /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl ContactCheck { diff --git a/epp-client/src/contact/create.rs b/epp-client/src/contact/create.rs index 207b331..cf7bb99 100644 --- a/epp-client/src/contact/create.rs +++ b/epp-client/src/contact/create.rs @@ -33,8 +33,9 @@ impl EppRequest for ContactCreate { /// use epp_client::EppClient; /// use epp_client::common::{Address, Phone, PostalInfo}; /// use epp_client::contact::create::ContactCreate; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -45,9 +46,6 @@ impl EppRequest for ContactCreate { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -59,6 +57,9 @@ impl EppRequest for ContactCreate { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create the address, postal_info, voice instances /// let street = vec!["58", "Orchid Road"]; /// let address = Address::new(&street, "New York", "New York", "392374", "US".parse().unwrap()); @@ -79,11 +80,12 @@ impl EppRequest for ContactCreate { /// contact_create.set_fax(fax); /// /// // send it to the registry and receive a response of type ContactCreateResponse -/// let response = client.transact(contact_create, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(contact_create, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl ContactCreate { diff --git a/epp-client/src/contact/delete.rs b/epp-client/src/contact/delete.rs index 8172c8b..610ba33 100644 --- a/epp-client/src/contact/delete.rs +++ b/epp-client/src/contact/delete.rs @@ -33,8 +33,9 @@ impl EppRequest for ContactDelete { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::contact::delete::ContactDelete; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -45,9 +46,6 @@ impl EppRequest for ContactDelete { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -59,17 +57,21 @@ impl EppRequest for ContactDelete { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an ContactDelete instance /// let contact_delete = ContactDelete::::new( /// "eppdev-contact-100" /// ); /// /// // send it to the registry and receive a response of type ContactDeleteResponse -/// let response = client.transact(contact_delete, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(contact_delete, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl ContactDelete { diff --git a/epp-client/src/contact/info.rs b/epp-client/src/contact/info.rs index 0af462f..13d31c5 100644 --- a/epp-client/src/contact/info.rs +++ b/epp-client/src/contact/info.rs @@ -34,8 +34,9 @@ impl EppRequest for ContactInfo { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::contact::info::ContactInfo; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -46,9 +47,6 @@ impl EppRequest for ContactInfo { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -60,6 +58,9 @@ impl EppRequest for ContactInfo { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an ContactInfo instance /// let contact_info = ContactInfo::::new( /// "eppdev-contact-100", @@ -67,11 +68,12 @@ impl EppRequest for ContactInfo { /// ); /// /// // send it to the registry and receive a response of type ContactInfoResponse -/// let response = client.transact(contact_info, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(contact_info, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl ContactInfo { diff --git a/epp-client/src/contact/update.rs b/epp-client/src/contact/update.rs index 9064c33..73a11c6 100644 --- a/epp-client/src/contact/update.rs +++ b/epp-client/src/contact/update.rs @@ -35,9 +35,10 @@ impl EppRequest for ContactUpdate { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::contact::update::ContactUpdate; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::ContactStatus; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -48,9 +49,6 @@ impl EppRequest for ContactUpdate { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -62,6 +60,9 @@ impl EppRequest for ContactUpdate { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an ContactUpdate instance /// let mut contact_update = ContactUpdate::::new( /// "eppdev-contact-100" @@ -76,11 +77,12 @@ impl EppRequest for ContactUpdate { /// contact_update.add(add_statuses); /// /// // send it to the registry and receive a response of type ContactUpdateResponse -/// let response = client.transact(contact_update, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(contact_update, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl ContactUpdate { diff --git a/epp-client/src/domain/check.rs b/epp-client/src/domain/check.rs index 8b48acf..7205c2f 100644 --- a/epp-client/src/domain/check.rs +++ b/epp-client/src/domain/check.rs @@ -32,8 +32,9 @@ impl EppRequest for DomainCheck { /// 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::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -44,9 +45,6 @@ impl EppRequest for DomainCheck { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -58,17 +56,21 @@ impl EppRequest for DomainCheck { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an DomainCheck instance /// let domain_check = DomainCheck::::new( /// vec!["eppdev-100.com", "eppdev-100.net"], /// ); /// /// // 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(); +/// let response = client.transact(domain_check, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainCheck { diff --git a/epp-client/src/domain/create.rs b/epp-client/src/domain/create.rs index 4ac62cb..73d684e 100644 --- a/epp-client/src/domain/create.rs +++ b/epp-client/src/domain/create.rs @@ -36,8 +36,9 @@ impl EppRequest for DomainCreate { /// use epp_client::EppClient; /// use epp_client::common::DomainContact; /// use epp_client::domain::create::DomainCreate; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// use epp_client::common::HostAttrList; /// use epp_client::common::HostList; /// use epp_client::common::HostObjList; @@ -51,9 +52,6 @@ impl EppRequest for DomainCreate { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -65,6 +63,9 @@ impl EppRequest for DomainCreate { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// let contacts = vec![ /// DomainContact { /// contact_type: "admin".to_string(), @@ -94,11 +95,12 @@ impl EppRequest for DomainCreate { /// ); /// /// // send it to the registry and receive a response of type EppDomainCreateResponse -/// let response = client.transact(domain_create, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_create, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainCreate { diff --git a/epp-client/src/domain/delete.rs b/epp-client/src/domain/delete.rs index fd3166e..488497c 100644 --- a/epp-client/src/domain/delete.rs +++ b/epp-client/src/domain/delete.rs @@ -33,8 +33,9 @@ impl EppRequest for DomainDelete { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::domain::delete::DomainDelete; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -45,9 +46,6 @@ impl EppRequest for DomainDelete { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -59,15 +57,19 @@ impl EppRequest for DomainDelete { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an DomainDelete instance /// let mut domain_delete = DomainDelete::::new("eppdev-100.com"); /// /// // send it to the registry and receive a response of type DomainDeleteResponse -/// let response = client.transact(domain_delete, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_delete, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainDelete { diff --git a/epp-client/src/domain/info.rs b/epp-client/src/domain/info.rs index c09a8ef..cbf4b09 100644 --- a/epp-client/src/domain/info.rs +++ b/epp-client/src/domain/info.rs @@ -34,8 +34,9 @@ impl EppRequest for DomainInfo { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::domain::info::DomainInfo; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -46,9 +47,6 @@ impl EppRequest for DomainInfo { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -60,15 +58,19 @@ impl EppRequest for DomainInfo { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an DomainInfo instance /// let domain_info = DomainInfo::::new("eppdev-100.com"); /// /// // send it to the registry and receive a response of type DomainInfoResponse -/// let response = client.transact(domain_info, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_info, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainInfo { diff --git a/epp-client/src/domain/renew.rs b/epp-client/src/domain/renew.rs index 84e5958..16893fe 100644 --- a/epp-client/src/domain/renew.rs +++ b/epp-client/src/domain/renew.rs @@ -35,8 +35,9 @@ impl EppRequest for DomainRenew { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::domain::renew::DomainRenew; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -47,9 +48,6 @@ impl EppRequest for DomainRenew { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -61,6 +59,9 @@ impl EppRequest for DomainRenew { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create a date object to set the current expiry date /// let exp_date = NaiveDate::from_ymd(2022, 7, 27); /// @@ -68,11 +69,12 @@ impl EppRequest for DomainRenew { /// let domain_renew = DomainRenew::::new("eppdev-100.com", exp_date, 1); /// /// // send it to the registry and receive a response of type DomainRenewResponse -/// let response = client.transact(domain_renew, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_renew, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainRenew { diff --git a/epp-client/src/domain/transfer.rs b/epp-client/src/domain/transfer.rs index 409d208..b109a26 100644 --- a/epp-client/src/domain/transfer.rs +++ b/epp-client/src/domain/transfer.rs @@ -93,8 +93,9 @@ impl EppRequest for DomainTransferQuery { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::domain::transfer::DomainTransferRequest; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -105,9 +106,6 @@ impl EppRequest for DomainTransferQuery { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -119,17 +117,21 @@ impl EppRequest for DomainTransferQuery { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an DomainTransferRequest instance /// let domain_transfer_request = DomainTransferRequest::::new( /// "eppdev-100.net", 1, "epP4uthd#v" /// ); /// /// // send it to the registry and receive a response of type DomainTransferRequestResponse -/// let response = client.transact(domain_transfer_request, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_transfer_request, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainTransferRequest { @@ -166,8 +168,9 @@ impl DomainTransferRequest { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::domain::transfer::DomainTransferApprove; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -178,9 +181,6 @@ impl DomainTransferRequest { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -192,17 +192,27 @@ impl DomainTransferRequest { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// +/// // 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 DomainTransferApprove instance /// let domain_transfer_approve = DomainTransferApprove::::new( /// "eppdev-100.net" /// ); /// /// // send it to the registry and receive a response of type DomainTransferApproveResponse -/// let response = client.transact(domain_transfer_approve, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_transfer_approve, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainTransferApprove { @@ -239,8 +249,9 @@ impl DomainTransferApprove { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::domain::transfer::DomainTransferReject; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -251,9 +262,6 @@ impl DomainTransferApprove { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -265,17 +273,21 @@ impl DomainTransferApprove { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an DomainTransferReject instance /// let domain_transfer_reject = DomainTransferReject::::new( /// "eppdev-100.net" /// ); /// /// // send it to the registry and receive a response of type DomainTransferRejectResponse -/// let response = client.transact(domain_transfer_reject, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_transfer_reject, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainTransferReject { @@ -312,8 +324,9 @@ impl DomainTransferReject { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::domain::transfer::DomainTransferCancel; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -324,9 +337,6 @@ impl DomainTransferReject { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -338,17 +348,21 @@ impl DomainTransferReject { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an DomainTransferCancel instance /// let domain_transfer_cancel = DomainTransferCancel::::new( /// "eppdev-100.net" /// ); /// /// // send it to the registry and receive a response of type DomainTransferCancelResponse -/// let response = client.transact(domain_transfer_cancel, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_transfer_cancel, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainTransferCancel { @@ -385,8 +399,9 @@ impl DomainTransferCancel { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::domain::transfer::DomainTransferQuery; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -397,9 +412,6 @@ impl DomainTransferCancel { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -411,17 +423,21 @@ impl DomainTransferCancel { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an DomainTransferQuery instance /// let domain_transfer_query = DomainTransferQuery::::new( /// "eppdev-100.net", "epP4uthd#v" /// ); /// /// // send it to the registry and receive a response of type DomainTransferQueryResponse -/// let response = client.transact(domain_transfer_query, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_transfer_query, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainTransferQuery { diff --git a/epp-client/src/domain/update.rs b/epp-client/src/domain/update.rs index 1219ddd..fffa78b 100644 --- a/epp-client/src/domain/update.rs +++ b/epp-client/src/domain/update.rs @@ -42,8 +42,9 @@ impl EppRequest for DomainUpdate { /// use epp_client::EppClient; /// use epp_client::common::{DomainStatus, DomainContact}; /// use epp_client::domain::update::{DomainUpdate, DomainAddRemove}; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -54,9 +55,6 @@ impl EppRequest for DomainUpdate { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -68,6 +66,9 @@ impl EppRequest for DomainUpdate { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an DomainUpdate instance /// let mut domain_update = DomainUpdate::::new("eppdev-100.com"); /// @@ -96,11 +97,12 @@ impl EppRequest for DomainUpdate { /// domain_update.remove(remove); /// /// // send it to the registry and receive a response of type EppDomainUpdateResponse -/// let response = client.transact(domain_update, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_update, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl DomainUpdate { diff --git a/epp-client/src/extensions/namestore.rs b/epp-client/src/extensions/namestore.rs index 0bdb935..35d3cfc 100644 --- a/epp-client/src/extensions/namestore.rs +++ b/epp-client/src/extensions/namestore.rs @@ -20,8 +20,10 @@ pub const XMLNS: &str = "http://www.verisign-grs.com/epp/namestoreExt-1.1"; /// 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; +/// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -32,9 +34,6 @@ pub const XMLNS: &str = "http://www.verisign-grs.com/epp/namestoreExt-1.1"; /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -46,6 +45,9 @@ pub const XMLNS: &str = "http://www.verisign-grs.com/epp/namestoreExt-1.1"; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// let namestore_ext = NameStore::new("com"); /// /// // Create an DomainCheck instance @@ -54,11 +56,12 @@ pub const XMLNS: &str = "http://www.verisign-grs.com/epp/namestoreExt-1.1"; /// ).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(); +/// let response = client.transact(domain_check, "test-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl NameStore { diff --git a/epp-client/src/extensions/rgp/report.rs b/epp-client/src/extensions/rgp/report.rs index 4192c8b..d75386c 100644 --- a/epp-client/src/extensions/rgp/report.rs +++ b/epp-client/src/extensions/rgp/report.rs @@ -21,8 +21,9 @@ use super::EPP_DOMAIN_RGP_EXT_XMLNS; /// use epp_client::common::{DomainStatus, DomainContact}; /// use epp_client::extensions::rgp::report::RgpRestoreReport; /// use epp_client::domain::update::DomainUpdate; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// use chrono::{DateTime, NaiveDate}; /// use std::str::FromStr; /// @@ -35,9 +36,6 @@ use super::EPP_DOMAIN_RGP_EXT_XMLNS; /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -49,6 +47,9 @@ use super::EPP_DOMAIN_RGP_EXT_XMLNS; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// let pre_data = /// "Pre-delete registration data goes here. Both XML and free text are allowed."; /// let post_data = @@ -76,11 +77,12 @@ use super::EPP_DOMAIN_RGP_EXT_XMLNS; /// let mut domain_update = DomainUpdate::::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(domain_update, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_update, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl RgpRestoreReport { diff --git a/epp-client/src/extensions/rgp/request.rs b/epp-client/src/extensions/rgp/request.rs index 7e83f6a..aea78c9 100644 --- a/epp-client/src/extensions/rgp/request.rs +++ b/epp-client/src/extensions/rgp/request.rs @@ -21,7 +21,9 @@ use super::EPP_DOMAIN_RGP_EXT_XMLNS; /// use epp_client::EppClient; /// use epp_client::extensions::rgp::request::RgpRestoreRequest; /// use epp_client::domain::update::DomainUpdate; -/// use epp_client::generate_client_tr_id; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -32,9 +34,6 @@ use super::EPP_DOMAIN_RGP_EXT_XMLNS; /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -46,6 +45,9 @@ use super::EPP_DOMAIN_RGP_EXT_XMLNS; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an RgpRestoreRequest instance /// let domain_restore_req = RgpRestoreRequest::new(); /// @@ -53,11 +55,12 @@ use super::EPP_DOMAIN_RGP_EXT_XMLNS; /// let mut domain_update = DomainUpdate::::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(domain_update, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(domain_update, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl RgpRestoreRequest { diff --git a/epp-client/src/host/check.rs b/epp-client/src/host/check.rs index 367cc49..a5e417d 100644 --- a/epp-client/src/host/check.rs +++ b/epp-client/src/host/check.rs @@ -34,8 +34,9 @@ impl EppRequest for HostCheck { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::host::check::HostCheck; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -46,9 +47,6 @@ impl EppRequest for HostCheck { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -60,17 +58,21 @@ impl EppRequest for HostCheck { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an HostCheck instance /// let host_check = HostCheck::::new( /// &["ns1.eppdev-101.com", "ns2.eppdev-101.com"] /// ); /// /// // send it to the registry and receive a response of type HostCheckResponse -/// let response = client.transact(host_check, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(host_check, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl HostCheck { diff --git a/epp-client/src/host/create.rs b/epp-client/src/host/create.rs index 6c1a67c..bebd794 100644 --- a/epp-client/src/host/create.rs +++ b/epp-client/src/host/create.rs @@ -33,8 +33,9 @@ impl EppRequest for HostCreate { /// use epp_client::EppClient; /// use epp_client::common::HostAddr; /// use epp_client::host::create::HostCreate; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -45,9 +46,6 @@ impl EppRequest for HostCreate { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -59,6 +57,9 @@ impl EppRequest for HostCreate { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create a vector of IP addresses to assign to the host /// let addresses = vec![ /// HostAddr::new("v4", "29.245.122.14"), @@ -69,11 +70,12 @@ impl EppRequest for HostCreate { /// let host_create = HostCreate::::new("ns1.eppdev-101.com", addresses); /// /// // send it to the registry and receive a response of type HostCreateResponse -/// let response = client.transact(host_create, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(host_create, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl HostCreate { diff --git a/epp-client/src/host/delete.rs b/epp-client/src/host/delete.rs index c05eecd..4eef93e 100644 --- a/epp-client/src/host/delete.rs +++ b/epp-client/src/host/delete.rs @@ -33,8 +33,9 @@ impl EppRequest for HostDelete { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::host::delete::HostDelete; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -45,9 +46,6 @@ impl EppRequest for HostDelete { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -59,15 +57,19 @@ impl EppRequest for HostDelete { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an HostDelete instance /// let host_delete = HostDelete::::new("ns2.eppdev-101.com"); /// /// // send it to the registry and receive a response of type HostDeleteResponse -/// let response = client.transact(host_delete, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(host_delete, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl HostDelete { diff --git a/epp-client/src/host/info.rs b/epp-client/src/host/info.rs index 020aa29..7f5475a 100644 --- a/epp-client/src/host/info.rs +++ b/epp-client/src/host/info.rs @@ -32,8 +32,9 @@ impl EppRequest for HostInfo { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::host::info::HostInfo; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -44,9 +45,6 @@ impl EppRequest for HostInfo { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -58,15 +56,19 @@ impl EppRequest for HostInfo { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an HostInfo instance /// let host_info = HostInfo::::new("ns2.eppdev-101.com"); /// /// // send it to the registry and receive a response of type HostInfoResponse -/// let response = client.transact(host_info, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(host_info, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl HostInfo { diff --git a/epp-client/src/host/update.rs b/epp-client/src/host/update.rs index f2c36a8..a53861a 100644 --- a/epp-client/src/host/update.rs +++ b/epp-client/src/host/update.rs @@ -34,8 +34,9 @@ impl EppRequest for HostUpdate { /// use epp_client::EppClient; /// use epp_client::common::{HostAddr, HostStatus}; /// use epp_client::host::update::{HostUpdate, HostAddRemove, HostChangeInfo}; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -46,9 +47,6 @@ impl EppRequest for HostUpdate { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -60,6 +58,9 @@ impl EppRequest for HostUpdate { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an HostUpdate instance /// let mut host_update = HostUpdate::::new("ns1.eppdev-101.com"); /// @@ -85,11 +86,12 @@ impl EppRequest for HostUpdate { /// host_update.info(HostChangeInfo { name: "ns2.eppdev-101.com".into() }); /// /// // send it to the registry and receive a response of type HostUpdateResponse -/// let response = client.transact(host_update, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(host_update, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl HostUpdate { diff --git a/epp-client/src/lib.rs b/epp-client/src/lib.rs index 09f6665..4d920d5 100644 --- a/epp-client/src/lib.rs +++ b/epp-client/src/lib.rs @@ -44,8 +44,9 @@ //! 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::common::NoExtension; +//! use epp_client::login::Login; +//! use epp_client::logout::Logout; //! //! #[tokio::main] //! async fn main() { @@ -57,9 +58,6 @@ //! RegistryConfig { //! host: "example.com".to_owned(), //! port: 700, -//! username: "username".to_owned(), -//! password: "password".to_owned(), -//! ext_uris: None, //! tls_files: None, //! }, //! ); @@ -71,13 +69,16 @@ //! Err(e) => panic!("Failed to create EppClient: {}", e) //! }; //! +//! let login = Login::::new("username", "password", &None); +//! client.transact(login, "transaction-id").await.unwrap(); +//! //! // Make a domain check call, which returns an object of type EppDomainCheckResponse //! // that contains the result of the call //! let domain_check = DomainCheck::::new( //! vec!["eppdev.com", "eppdev.net"], //! ); //! -//! let response = client.transact(domain_check, generate_client_tr_id(&client).as_str()).await.unwrap(); +//! let response = client.transact(domain_check, "transaction-id").await.unwrap(); //! //! // print the availability results //! response.res_data.unwrap().check_data.domain_list @@ -85,8 +86,8 @@ //! .for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available)); //! //! // Close the connection -//! client.logout().await.unwrap(); -//! +//! let logout = Logout::::new(); +//! client.transact(logout, "transaction-id").await.unwrap(); //! } //! ``` //! @@ -154,7 +155,6 @@ pub mod message { pub mod poll; } -pub use client::default_client_tr_id_fn as generate_client_tr_id; pub use client::EppClient; #[cfg(test)] diff --git a/epp-client/src/message/ack.rs b/epp-client/src/message/ack.rs index ad2cc20..fd19844 100644 --- a/epp-client/src/message/ack.rs +++ b/epp-client/src/message/ack.rs @@ -30,8 +30,9 @@ impl EppRequest for MessageAck { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::message::ack::MessageAck; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -42,9 +43,6 @@ impl EppRequest for MessageAck { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -56,15 +54,19 @@ impl EppRequest for MessageAck { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an MessageAck instance /// let message_ack = MessageAck::::new(12345); /// /// // send it to the registry and receive a response of type MessageAckResponse -/// let response = client.transact(message_ack, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(message_ack, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl MessageAck { diff --git a/epp-client/src/message/poll.rs b/epp-client/src/message/poll.rs index db6c8da..932b94b 100644 --- a/epp-client/src/message/poll.rs +++ b/epp-client/src/message/poll.rs @@ -31,8 +31,9 @@ impl EppRequest for MessagePoll { /// use epp_client::config::{EppClientConfig, RegistryConfig}; /// use epp_client::EppClient; /// use epp_client::message::poll::MessagePoll; -/// use epp_client::generate_client_tr_id; /// use epp_client::common::NoExtension; +/// use epp_client::login::Login; +/// use epp_client::logout::Logout; /// /// #[tokio::main] /// async fn main() { @@ -43,9 +44,6 @@ impl EppRequest for MessagePoll { /// RegistryConfig { /// host: "example.com".to_owned(), /// port: 700, -/// username: "username".to_owned(), -/// password: "password".to_owned(), -/// ext_uris: None, /// tls_files: None, /// }, /// ); @@ -57,15 +55,19 @@ impl EppRequest for MessagePoll { /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// +/// let login = Login::::new("username", "password", &None); +/// client.transact(login, "transaction-id").await.unwrap(); +/// /// // Create an MessagePoll instance /// let message_poll = MessagePoll::::new(); /// /// // send it to the registry and receive a response of type MessagePollResponse -/// let response = client.transact(message_poll, generate_client_tr_id(&client).as_str()).await.unwrap(); +/// let response = client.transact(message_poll, "transaction-id").await.unwrap(); /// /// println!("{:?}", response); /// -/// client.logout().await.unwrap(); +/// let logout = Logout::::new(); +/// client.transact(logout, "transaction-id").await.unwrap(); /// } /// ``` impl MessagePoll { diff --git a/epp-client/src/request.rs b/epp-client/src/request.rs index de737c3..cec5de3 100644 --- a/epp-client/src/request.rs +++ b/epp-client/src/request.rs @@ -1,9 +1,7 @@ //! Types for EPP requests use serde::{de::DeserializeOwned, ser::SerializeStruct, ser::Serializer, Deserialize, Serialize}; -use std::error::Error; use std::fmt::Debug; -use std::time::SystemTime; use crate::{ common::{ElementName, EppObject, Extension, StringValue}, @@ -87,9 +85,3 @@ impl Command { } } } - -/// Basic client TRID generation function. Mainly used for testing. Users of the library should use their own clTRID generation function. -pub fn generate_client_tr_id(username: &str) -> Result> { - let timestamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; - Ok(format!("{}:{}", username, timestamp.as_secs())) -}