call to epp logout made explicit and Drop impl removed

This commit is contained in:
Ritesh Chitlangi 2021-11-11 23:56:01 +08:00 committed by masalachai
parent d0c553cebb
commit e07eba2de2
25 changed files with 59 additions and 15 deletions

View File

@ -95,6 +95,8 @@ async fn main() {
response.data.res_data.unwrap().check_data.domain_list
.iter()
.for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available));
client.close().await.unwrap();
}
```

View File

@ -50,8 +50,8 @@ use std::{fs, io};
/// Paths to the client certificate and client key PEM files
#[derive(Serialize, Deserialize, Debug)]
pub struct EppClientTlsFiles {
cert_chain: String,
key: String,
pub cert_chain: String,
pub key: String,
}
/// Connection details to connect to and authenticate with a registry

View File

@ -46,7 +46,6 @@
//! }
//! ```
use futures::executor::block_on;
use std::time::SystemTime;
use std::{error::Error, fmt::Debug};
@ -187,10 +186,10 @@ impl EppClient {
self.transact::<_, EppLogoutResponse>(&epp_logout).await
}
}
impl Drop for EppClient {
fn drop(&mut self) {
let _ = block_on(self.logout());
pub async fn close(&mut self) -> Result<(), error::Error> {
self.logout().await?;
Ok(self.connection.close().await?)
}
}

View File

@ -1,7 +1,6 @@
//! Manages registry connections and reading/writing to them
use bytes::BytesMut;
use futures::executor::block_on;
use rustls::{OwnedTrustAnchor, RootCertStore};
use std::convert::TryInto;
use std::sync::Arc;
@ -129,7 +128,7 @@ impl EppConnection {
}
/// Closes the socket
async fn close(&mut self) -> Result<(), Box<dyn Error>> {
pub async fn close(&mut self) -> Result<(), Box<dyn Error>> {
info!("{}: Closing connection", self.registry);
self.stream.writer.shutdown().await?;
@ -137,12 +136,6 @@ impl EppConnection {
}
}
impl Drop for EppConnection {
fn drop(&mut self) {
let _ = block_on(self.close());
}
}
/// Establishes a TLS connection to a registry and returns a ConnectionStream instance containing the
/// socket stream to read/write to the connection
pub async fn epp_connect(

View File

@ -51,6 +51,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppContactCheckResponse>(&contact_check).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppContactCheck = EppObject<Command<ContactCheck>>;

View File

@ -68,6 +68,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppContactCreateResponse>(&contact_create).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppContactCreate = EppObject<Command<ContactCreate>>;

View File

@ -52,6 +52,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppContactDeleteResponse>(&contact_delete).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppContactDelete = EppObject<Command<ContactDelete>>;

View File

@ -54,6 +54,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppContactInfoResponse>(&contact_info).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppContactInfo = EppObject<Command<ContactInfo>>;

View File

@ -64,6 +64,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppContactUpdateResponse>(&contact_update).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppContactUpdate = EppObject<Command<ContactUpdate>>;

View File

@ -52,6 +52,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainCheckResponse>(&domain_check).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainCheck = EppObject<Command<DomainCheck>>;

View File

@ -72,6 +72,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainCreateResponse>(&domain_create).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainCreate = EppObject<Command<DomainCreate>>;

View File

@ -49,6 +49,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainDeleteResponse>(&domain_delete).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainDelete = EppObject<Command<DomainDelete>>;

View File

@ -49,6 +49,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainInfoResponse>(&domain_info).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainInfo = EppObject<Command<DomainInfo>>;

View File

@ -56,6 +56,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainRenewResponse>(&domain_renew).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainRenew = EppObject<Command<DomainRenew>>;

View File

@ -79,6 +79,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainRgpRestoreReportResponse>(&domain_restore_report).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainRgpRestoreReport =

View File

@ -56,6 +56,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainRgpRestoreRequestResponse>(&domain_restore_req).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainRgpRestoreRequest =

View File

@ -52,6 +52,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainTransferRequestResponse>(&domain_transfer_request).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainTransferRequest = EppObject<Command<DomainTransfer>>;
@ -100,6 +102,8 @@ pub type EppDomainTransferRequest = EppObject<Command<DomainTransfer>>;
/// let response = client.transact::<_, EppDomainTransferApproveResponse>(&domain_transfer_approve).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainTransferApprove = EppObject<Command<DomainTransfer>>;
@ -148,6 +152,8 @@ pub type EppDomainTransferApprove = EppObject<Command<DomainTransfer>>;
/// let response = client.transact::<_, EppDomainTransferRejectResponse>(&domain_transfer_reject).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainTransferReject = EppObject<Command<DomainTransfer>>;
@ -196,6 +202,8 @@ pub type EppDomainTransferReject = EppObject<Command<DomainTransfer>>;
/// let response = client.transact::<_, EppDomainTransferCancelResponse>(&domain_transfer_cancel).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainTransferCancel = EppObject<Command<DomainTransfer>>;
@ -244,6 +252,8 @@ pub type EppDomainTransferCancel = EppObject<Command<DomainTransfer>>;
/// let response = client.transact::<_, EppDomainTransferQueryResponse>(&domain_transfer_query).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainTransferQuery = EppObject<Command<DomainTransfer>>;

View File

@ -76,6 +76,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppDomainUpdateResponse>(&domain_update).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppDomainUpdate = EppObject<Command<DomainUpdate<HostObjList>>>;

View File

@ -52,6 +52,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppHostCheckResponse>(&host_check).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppHostCheck = EppObject<Command<HostCheck>>;

View File

@ -57,6 +57,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppHostCreateResponse>(&host_create).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppHostCreate = EppObject<Command<HostCreate>>;

View File

@ -49,6 +49,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppHostDeleteResponse>(&host_delete).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppHostDelete = EppObject<Command<HostDelete>>;

View File

@ -49,6 +49,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppHostInfoResponse>(&host_info).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppHostInfo = EppObject<Command<HostInfo>>;

View File

@ -73,6 +73,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppHostUpdateResponse>(&host_update).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppHostUpdate = EppObject<Command<HostUpdate>>;

View File

@ -47,6 +47,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppMessageAckResponse>(&message_ack).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppMessageAck = EppObject<Command<MessageAck>>;

View File

@ -48,6 +48,8 @@ use serde::{Deserialize, Serialize};
/// let response = client.transact::<_, EppMessagePollResponse>(&message_poll).await.unwrap();
///
/// println!("{:?}", response);
///
/// client.close().await.unwrap();
/// }
/// ```
pub type EppMessagePoll = EppObject<Command<MessagePoll>>;