Make connection setup a part of EppConnection interface
This commit is contained in:
parent
6695a20a18
commit
4f111fa8fe
|
@ -49,7 +49,7 @@ use crate::common::NoExtension;
|
||||||
use crate::config::EppClientConfig;
|
use crate::config::EppClientConfig;
|
||||||
use crate::error;
|
use crate::error;
|
||||||
use crate::hello::{Greeting, GreetingDocument, HelloDocument};
|
use crate::hello::{Greeting, GreetingDocument, HelloDocument};
|
||||||
use crate::registry::{epp_connect, EppConnection};
|
use crate::registry::EppConnection;
|
||||||
use crate::request::{Command, Extension, Transaction};
|
use crate::request::{Command, Extension, Transaction};
|
||||||
use crate::response::Response;
|
use crate::response::Response;
|
||||||
use crate::xml::EppXml;
|
use crate::xml::EppXml;
|
||||||
|
@ -73,10 +73,9 @@ impl EppClient {
|
||||||
None => return Err(format!("missing credentials for {}", registry).into()),
|
None => return Err(format!("missing credentials for {}", registry).into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let stream = epp_connect(registry_creds).await?;
|
Ok(EppClient {
|
||||||
let connection = EppConnection::new(registry.to_string(), stream).await?;
|
connection: EppConnection::connect(registry.to_string(), registry_creds).await?,
|
||||||
|
})
|
||||||
Ok(EppClient { connection })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes an EPP Hello call and returns the response as an `Greeting`
|
/// Executes an EPP Hello call and returns the response as an `Greeting`
|
||||||
|
|
|
@ -26,10 +26,12 @@ pub struct EppConnection {
|
||||||
|
|
||||||
impl EppConnection {
|
impl EppConnection {
|
||||||
/// Create an EppConnection instance with the stream to the registry
|
/// Create an EppConnection instance with the stream to the registry
|
||||||
pub async fn new(
|
pub async fn connect(
|
||||||
registry: String,
|
registry: String,
|
||||||
mut stream: TlsStream<TcpStream>,
|
config: &RegistryConfig,
|
||||||
) -> Result<EppConnection, Box<dyn Error>> {
|
) -> Result<EppConnection, Box<dyn Error>> {
|
||||||
|
let mut stream = epp_connect(config).await?;
|
||||||
|
|
||||||
let mut buf = vec![0u8; 4096];
|
let mut buf = vec![0u8; 4096];
|
||||||
stream.read(&mut buf).await?;
|
stream.read(&mut buf).await?;
|
||||||
let greeting = str::from_utf8(&buf[4..])?.to_string();
|
let greeting = str::from_utf8(&buf[4..])?.to_string();
|
||||||
|
@ -118,7 +120,7 @@ impl EppConnection {
|
||||||
|
|
||||||
/// Establishes a TLS connection to a registry and returns a ConnectionStream instance containing the
|
/// Establishes a TLS connection to a registry and returns a ConnectionStream instance containing the
|
||||||
/// socket stream to read/write to the connection
|
/// socket stream to read/write to the connection
|
||||||
pub async fn epp_connect(
|
async fn epp_connect(
|
||||||
registry_creds: &RegistryConfig,
|
registry_creds: &RegistryConfig,
|
||||||
) -> Result<TlsStream<TcpStream>, error::Error> {
|
) -> Result<TlsStream<TcpStream>, error::Error> {
|
||||||
info!(
|
info!(
|
||||||
|
|
Loading…
Reference in New Issue