Skip to content

Commit

Permalink
Added Ability to connect using ssh string and SshCertCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
amigin committed Aug 1, 2024
1 parent 928bd0f commit 60d3392
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 14 additions & 8 deletions my-no-sql-data-writer/src/my_no_sql_data_writer/fl_url_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use flurl::FlUrl;

#[cfg(feature = "with-ssh")]
use flurl::my_ssh::{SshCredentials, SshSessionsPool};
use flurl::my_ssh::SshSessionsPool;

use rust_extensions::UnsafeValue;

Expand All @@ -14,9 +14,9 @@ pub struct FlUrlFactory {
settings: Arc<dyn MyNoSqlWriterSettings + Send + Sync + 'static>,
auto_create_table_params: Option<Arc<CreateTableParams>>,
#[cfg(feature = "with-ssh")]
pub ssh_credentials: Option<Arc<SshCredentials>>,
#[cfg(feature = "with-ssh")]
pub ssh_sessions_pool: Option<Arc<SshSessionsPool>>,
pub ssh_cert_credentials:
Option<std::collections::HashMap<String, flurl::my_ssh::SshCredentialsSettingsModel>>,
create_table_is_called: Arc<UnsafeValue<bool>>,
table_name: &'static str,
}
Expand All @@ -30,23 +30,29 @@ impl FlUrlFactory {
Self {
auto_create_table_params,
#[cfg(feature = "with-ssh")]
ssh_credentials: None,
#[cfg(feature = "with-ssh")]
ssh_sessions_pool: None,
create_table_is_called: UnsafeValue::new(false).into(),
settings,
table_name,
ssh_cert_credentials: None,
}
}

#[cfg(not(feature = "with-ssh"))]
async fn create_fl_url(&self, url: &str) -> FlUrl {
let mut fl_url = flurl::FlUrl::new(url);

#[cfg(feature = "with-ssh")]
if let Some(ssh_credentials) = &self.ssh_credentials {
fl_url = fl_url.set_ssh_credentials(ssh_credentials.clone());
if let Some(ssh_sessions_pool) = &self.ssh_sessions_pool {
fl_url = fl_url.set_ssh_sessions_pool(ssh_sessions_pool.clone());
}

fl_url
}
#[cfg(feature = "with-ssh")]
async fn create_fl_url(&self, url: &str) -> FlUrl {
let mut fl_url =
flurl::FlUrl::new_with_maybe_ssh(url, self.ssh_cert_credentials.as_ref()).await;

#[cfg(feature = "with-ssh")]
if let Some(ssh_sessions_pool) = &self.ssh_sessions_pool {
fl_url = fl_url.set_ssh_sessions_pool(ssh_sessions_pool.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ impl<TEntity: MyNoSqlEntity + MyNoSqlEntitySerializer + Sync + Send> MyNoSqlData
}

#[cfg(feature = "with-ssh")]
pub async fn set_ssh_credentials(&mut self, ssh_credentials: Arc<SshCredentials>) {
self.fl_url_factory.ssh_credentials = Some(ssh_credentials);
pub async fn set_ssh_cert_credentials(
&mut self,
cert_credentials: std::collections::HashMap<
String,
flurl::my_ssh::SshCredentialsSettingsModel,
>,
) {
self.fl_url_factory.ssh_cert_credentials = Some(cert_credentials);
}

#[cfg(feature = "with-ssh")]
Expand Down

0 comments on commit 60d3392

Please sign in to comment.