From 20ab056dcf15543ed0e0139a43251ee2fa4d1954 Mon Sep 17 00:00:00 2001 From: Ritesh Chitlangi Date: Tue, 26 Jul 2022 14:49:37 +0800 Subject: [PATCH] update doc and release 0.4 --- .drone.yml | 1 + .gitignore | 2 +- Cargo.toml | 2 +- README.md | 84 ++++++++++++------------------------------------------ src/lib.rs | 38 ++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 67 deletions(-) diff --git a/.drone.yml b/.drone.yml index 3116267..ba08de9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -83,6 +83,7 @@ steps: branch: - 0.2 - 0.3 + - 0.4 event: push - name: notify diff --git a/.gitignore b/.gitignore index 73e23a9..0cbe46f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ **/target **/certs /config -/epp-client/examples +/examples Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index 60862c6..ac741d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epp-client" -version = "0.3.1" +version = "0.4.0" edition = "2018" license = "MIT" authors = ["Ritesh Chitlangi "] diff --git a/README.md b/README.md index 54159f8..0f353ef 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ to eventually be RFC compliant with the EPP protocol. Just add the following to your project's `Cargo.toml` ```toml -epp-client = "0.3" +epp-client = "0.4" ``` ## Operation @@ -51,90 +51,44 @@ epp-client = "0.3" You can create a mut variable of type `EppClient` with the domain registry config. ```rust -use std::collections::HashMap; +use std::net::ToSocketAddrs; +use std::time::Duration; -use epp_client::config::{EppClientConfig, RegistryConfig}; use epp_client::EppClient; -use epp_client::domain::check::DomainCheck; -use epp_client::common::NoExtension; +use epp_client::domain::DomainCheck; use epp_client::login::Login; -use epp_client::logout::Logout; #[tokio::main] async fn main() { - // Configure the client to connect to one of more registries - let mut registry: HashMap = HashMap::new(); - registry.insert( - "registry_name".to_owned(), - RegistryConfig { - host: "example.com".to_owned(), - port: 700, - 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 { + // Create an instance of EppClient + let host = "example.com"; + let addr = (host, 700).to_socket_addrs().unwrap().next().unwrap(); + let timeout = Duration::from_secs(5); + let mut client = match EppClient::connect("registry_name".to_string(), addr, host, None, timeout).await { Ok(client) => client, Err(e) => panic!("Failed to create EppClient: {}", e) }; - let login = Login::::new("username", "password", None); - client.transact(login, "transaction-id").await.unwrap(); + 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"], - ); + // Execute an EPP Command against the registry with distinct request and response objects + let domain_check = DomainCheck { domains: &["eppdev.com", "eppdev.net"] }; + let response = client.transact(&domain_check, "transaction-id").await.unwrap(); - // send it to the registry and receive a response of type EppDomainCheckResponse - let response = client.transact(domain_check, "transaction-id").await.unwrap(); - - println!("{:?}", response); - - let logout = Logout::::new(); - client.transact(logout, "transaction-id").await.unwrap(); + response.res_data.unwrap().list + .iter() + .for_each(|chk| println!("Domain: {}, Available: {}", chk.id, chk.available)); } ``` -The output would look similar to the following: +The output would look like this: -``` +```text Domain: eppdev.com, Available: 1 Domain: eppdev.net, Available: 1 ``` -You may also choose to store your configuration in something like a toml file: - -```toml -[registry.verisign] -host = 'epp.verisign-grs.com' -port = 700 -username = 'username' -password = 'password' -# service extensions -ext_uris = [] - -[registry.verisign.tls_files] -# the full client certificate chain in PEM format -cert_chain = '/path/to/certificate/chain/pemfile' -# the RSA private key for your certificate -key = '/path/to/private/key/pemfile' -``` - -```rust -use epp_client::config::{EppClientConfig}; - -#[tokio::main] -async fn main() { - // parse EppClientConfig from toml file - let config_path = Path::new("../secrets/epp-client.toml"); - let config: EppClientConfig = - toml::from_str(&fs::read_to_string(config_path).await.unwrap()).unwrap(); -} -``` - ## Request Currently I don't have access to a registry's OT&E account to do extensive diff --git a/src/lib.rs b/src/lib.rs index 6cf31ac..c7e7f7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,6 +55,44 @@ //! //! ## Operation //! +//! ```no_run +//! use std::net::ToSocketAddrs; +//! use std::time::Duration; +//! +//! use epp_client::EppClient; +//! use epp_client::domain::DomainCheck; +//! use epp_client::login::Login; +//! +//! #[tokio::main] +//! async fn main() { +//! // Create an instance of EppClient +//! let host = "example.com"; +//! let addr = (host, 700).to_socket_addrs().unwrap().next().unwrap(); +//! let timeout = Duration::from_secs(5); +//! let mut client = match EppClient::connect("registry_name".to_string(), addr, host, None, timeout).await { +//! Ok(client) => client, +//! Err(e) => panic!("Failed to create EppClient: {}", e) +//! }; +//! +//! let login = Login::new("username", "password", None); +//! client.transact(&login, "transaction-id").await.unwrap(); +//! +//! // Execute an EPP Command against the registry with distinct request and response objects +//! let domain_check = DomainCheck { domains: &["eppdev.com", "eppdev.net"] }; +//! let response = client.transact(&domain_check, "transaction-id").await.unwrap(); +//! +//! response.res_data.unwrap().list +//! .iter() +//! .for_each(|chk| println!("Domain: {}, Available: {}", chk.id, chk.available)); +//! } +//! ``` +//! +//! The output would look similar to the following +//! +//! ```text +//! Domain: eppdev.com, Available: 1 +//! Domain: eppdev.net, Available: 1 +//! ``` pub mod client; pub mod common;