From 0010713c66fb49d1e70e3e78589c529dd0cf7ef9 Mon Sep 17 00:00:00 2001 From: amigin Date: Mon, 4 Nov 2024 11:27:32 +0200 Subject: [PATCH] Made it compilable --- .../src/connection/connection_loop.rs | 9 ++++----- my-postgres-core/src/ssh/port_allocator.rs | 5 +---- my-postgres-core/src/ssh/start_ssh_tunnel.rs | 18 ++++++------------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/my-postgres-core/src/connection/connection_loop.rs b/my-postgres-core/src/connection/connection_loop.rs index 71d7dc5..46373d1 100644 --- a/my-postgres-core/src/connection/connection_loop.rs +++ b/my-postgres-core/src/connection/connection_loop.rs @@ -32,8 +32,6 @@ pub async fn start_connection_loop( #[cfg(feature = "with-ssh")] let postgres_host = if let Some(ssh_config) = &ssh_config { - let postgres_host = conn_string.get_host_endpoint(); - let ssh_cred_type = match ssh_config.credentials.as_ref() { my_ssh::SshCredentials::SshAgent { .. } => "SshAgent", my_ssh::SshCredentials::UserNameAndPassword { .. } => "UserNameAndPassword", @@ -42,14 +40,15 @@ pub async fn start_connection_loop( let (ssh_host, ssh_port) = ssh_config.credentials.get_host_port(); format!( - "[{}]ssh:{}:{}->{}", + "[{}]ssh:{}:{}->{}:{}", ssh_cred_type, ssh_host, ssh_port, - postgres_host.get_host_port().as_str() + conn_string.get_host(), + conn_string.get_port() ) } else { - format!("{:?}", conn_string.get_host_endpoint()) + format!("{}:{}", conn_string.get_host(), conn_string.get_port()) }; #[cfg(not(feature = "with-ssh"))] diff --git a/my-postgres-core/src/ssh/port_allocator.rs b/my-postgres-core/src/ssh/port_allocator.rs index d153ae1..656224b 100644 --- a/my-postgres-core/src/ssh/port_allocator.rs +++ b/my-postgres-core/src/ssh/port_allocator.rs @@ -35,10 +35,7 @@ lazy_static::lazy_static! { pub static ref PORT_ALLOCATOR: PortAllocator = PortAllocator::new(33000, 34000); } -pub fn generate_unix_socket_file( - _ssh_credentials: &SshCredentials, - _remote_host: rust_extensions::url_utils::HostEndpoint, -) -> (&'static str, u16) { +pub fn generate_unix_socket_file(_ssh_credentials: &SshCredentials) -> (&'static str, u16) { let port = PORT_ALLOCATOR.get_next_port(); return ("127.0.0.1", port); /* diff --git a/my-postgres-core/src/ssh/start_ssh_tunnel.rs b/my-postgres-core/src/ssh/start_ssh_tunnel.rs index a81b46a..cc3f12c 100644 --- a/my-postgres-core/src/ssh/start_ssh_tunnel.rs +++ b/my-postgres-core/src/ssh/start_ssh_tunnel.rs @@ -1,4 +1,4 @@ -use crate::{PostgresConnectionString, POSTGRES_DEFAULT_PORT}; +use crate::PostgresConnectionString; use super::PostgresSshConfig; @@ -8,14 +8,12 @@ pub async fn start_ssh_tunnel_and_get_connection_string( ) { let (host, port) = ssh_config.credentials.get_host_port(); - let postgres_endpoint = connection_string.get_host_endpoint(); - let ssh_tunnel_key = format!( "{}:{}->{}:{}", host, port, - postgres_endpoint.host, - postgres_endpoint.port.unwrap_or(POSTGRES_DEFAULT_PORT) + connection_string.get_host(), + connection_string.get_port() ); { @@ -30,18 +28,14 @@ pub async fn start_ssh_tunnel_and_get_connection_string( let ssh_session = ssh_config.get_ssh_session().await; - let get_host_endpoint = connection_string.get_host_endpoint(); - let (listen_host, listen_port) = - crate::ssh::generate_unix_socket_file(ssh_config.credentials.as_ref(), get_host_endpoint); + crate::ssh::generate_unix_socket_file(ssh_config.credentials.as_ref()); let result = ssh_session .start_port_forward( format!("{}:{}", listen_host, listen_port), - get_host_endpoint.host.to_string(), - get_host_endpoint - .port - .unwrap_or(crate::POSTGRES_DEFAULT_PORT), + connection_string.get_host().to_string(), + connection_string.get_port(), ) .await;