Skip to content

Commit

Permalink
Made it compilable
Browse files Browse the repository at this point in the history
  • Loading branch information
amigin committed Nov 4, 2024
1 parent 7644398 commit 0010713
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
9 changes: 4 additions & 5 deletions my-postgres-core/src/connection/connection_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"))]
Expand Down
5 changes: 1 addition & 4 deletions my-postgres-core/src/ssh/port_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/*
Expand Down
18 changes: 6 additions & 12 deletions my-postgres-core/src/ssh/start_ssh_tunnel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{PostgresConnectionString, POSTGRES_DEFAULT_PORT};
use crate::PostgresConnectionString;

use super::PostgresSshConfig;

Expand All @@ -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()
);

{
Expand All @@ -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;

Expand Down

0 comments on commit 0010713

Please sign in to comment.