Skip to content

Commit

Permalink
Small Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amigin committed Nov 12, 2024
1 parent 88ae93f commit bf05c73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 14 additions & 4 deletions my-grpc-extensions/src/grpc_channel/port_forwards_pool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use my_ssh::SshSession;
use rust_extensions::url_utils::HostEndpoint;
use rust_extensions::remote_endpoint::RemoteEndpoint;
use tokio::sync::Mutex;

lazy_static::lazy_static! {
Expand All @@ -23,18 +23,28 @@ impl PortForwardsPool {
&self,
ssh_session: &SshSession,
unix_socket_name: &str,
grpc_service_endpoint: HostEndpoint<'_>,
grpc_service_endpoint: RemoteEndpoint<'_>,
) {
let write_access = self.port_forwards.lock().await;
if write_access.contains_key(unix_socket_name) {
return;
}

let port = grpc_service_endpoint.get_port();

if port.is_none() {
println!(
"Can not start port forward for unix_socket_name: {}. Port is not defined",
unix_socket_name
);
return;
}

let result = ssh_session
.start_port_forward(
unix_socket_name.to_string(),
grpc_service_endpoint.host.to_string(),
grpc_service_endpoint.get_standard_port(),
grpc_service_endpoint.get_host().to_string(),
port.unwrap(),
)
.await;

Expand Down
7 changes: 4 additions & 3 deletions my-grpc-extensions/src/ssh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{env, sync::Arc};

use my_ssh::*;
use rust_extensions::remote_endpoint::RemoteEndpoint;
use tokio::sync::Mutex;
#[derive(Clone)]
pub struct SshTargetInner {
Expand Down Expand Up @@ -56,12 +57,12 @@ impl SshTarget {

pub fn generate_unix_socket_file(
ssh_credentials: &SshCredentials,
remote_host: rust_extensions::url_utils::HostEndpoint,
remote_host: RemoteEndpoint,
) -> String {
let (ssh_host, ssh_port) = ssh_credentials.get_host_port();

let r_host = remote_host.host;
let r_port = match remote_host.port {
let r_host = remote_host.get_host();
let r_port = match remote_host.get_port() {
Some(port) => port.to_string(),
None => "".to_string(),
};
Expand Down

0 comments on commit bf05c73

Please sign in to comment.