Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix: support HTTPS and self-signed certs for Elasticsearch connections

t8y2321ebc263612
diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rs
index d8be2197f9..5f39e49e19 100644
--- a/crates/dbx-core/src/connection.rs
+++ b/crates/dbx-core/src/connection.rs
@@ -204,8 +204,13 @@ impl AppState {
PoolKind::SqlServer(Arc::new(tokio::sync::Mutex::new(client)))
}
DatabaseType::Elasticsearch => {
- let client =
- db::elasticsearch_driver::EsClient::new(&url, Some(&db_config.username), Some(&db_config.password));
+ let accept_invalid_certs = db_config.ssl;
+ let client = db::elasticsearch_driver::EsClient::new(
+ &url,
+ Some(&db_config.username),
+ Some(&db_config.password),
+ accept_invalid_certs,
+ );
db::elasticsearch_driver::test_connection(&client).await?;
PoolKind::Elasticsearch(client)
}
diff --git a/crates/dbx-core/src/db/elasticsearch_driver.rs b/crates/dbx-core/src/db/elasticsearch_driver.rs
index 1b7cf47485..3a7ccaa827 100644
--- a/crates/dbx-core/src/db/elasticsearch_driver.rs
+++ b/crates/dbx-core/src/db/elasticsearch_driver.rs
@@ -11,13 +11,16 @@ pub struct EsClient {
}
impl EsClient {
- pub fn new(url: &str, username: Option<&str>, password: Option<&str>) -> Self {
+ pub fn new(url: &str, username: Option<&str>, password: Option<&str>, accept_invalid_certs: bool) -> Self {
let auth = match (username, password) {
(Some(u), Some(p)) if !u.is_empty() => Some((u.to_string(), p.to_string())),
_ => None,
};
- let http =
- HttpClient::builder().connect_timeout(connection_timeout()).build().unwrap_or_else(|_| HttpClient::new());
+ let http = HttpClient::builder()
+ .connect_timeout(connection_timeout())
+ .danger_accept_invalid_certs(accept_invalid_certs)
+ .build()
+ .unwrap_or_else(|_| HttpClient::new());
Self { http, base_url: url.trim_end_matches('/').to_string(), auth }
}
diff --git a/crates/dbx-core/src/models/connection.rs b/crates/dbx-core/src/models/connection.rs
index ab5efb08a0..479e1e01c1 100644
--- a/crates/dbx-core/src/models/connection.rs
+++ b/crates/dbx-core/src/models/connection.rs
@@ -225,7 +225,10 @@ impl ConnectionConfig {
format!("mongodb://{host}:{port}{db_part}{suffix}")
}
DatabaseType::Oracle => format!("oracle://{host}:{port}{db_part}"),
- DatabaseType::Elasticsearch => format!("http://{host}:{port}"),
+ DatabaseType::Elasticsearch => {
+ let scheme = if self.ssl { "https" } else { "http" };
+ format!("{scheme}://{host}:{port}")
+ }
DatabaseType::Dameng => format!("dm://{host}:{port}{db_part}"),
DatabaseType::Kingbase => format!("kingbase://{host}:{port}{db_part}"),
DatabaseType::Vastbase => format!("vastbase://{host}:{port}{db_part}"),
@@ -306,7 +309,10 @@ impl ConnectionConfig {
DatabaseType::Oracle => {
format!("oracle://{}:{}@{host}:{port}{db_part}", username, password)
}
- DatabaseType::Elasticsearch => format!("http://{host}:{port}"),
+ DatabaseType::Elasticsearch => {
+ let scheme = if self.ssl { "https" } else { "http" };
+ format!("{scheme}://{host}:{port}")
+ }
DatabaseType::Dameng => {
format!("dm://{}:{}@{host}:{port}{db_part}", username, password)
}
diff --git a/src-tauri/src/commands/connection.rs b/src-tauri/src/commands/connection.rs
index d4766ef133..7d70efbc93 100644
--- a/src-tauri/src/commands/connection.rs
+++ b/src-tauri/src/commands/connection.rs
@@ -98,8 +98,12 @@ pub async fn test_connection(state: State<'_, Arc<AppState>>, config: Connection
.map(|_| "Connection successful".to_string())
}
DatabaseType::Elasticsearch => {
- let client =
- db::elasticsearch_driver::EsClient::new(&url, Some(&config.username), Some(&config.password));
+ let client = db::elasticsearch_driver::EsClient::new(
+ &url,
+ Some(&config.username),
+ Some(&config.password),
+ config.ssl,
+ );
db::elasticsearch_driver::test_connection(&client).await.map(|_| "Connection successful".to_string())
}
DatabaseType::Dameng
@@ -208,8 +212,12 @@ pub async fn connect_db(state: State<'_, Arc<AppState>>, config: ConnectionConfi
PoolKind::SqlServer(std::sync::Arc::new(tokio::sync::Mutex::new(client)))
}
DatabaseType::Elasticsearch => {
- let client =
- db::elasticsearch_driver::EsClient::new(&url, Some(&db_config.username), Some(&db_config.password));
+ let client = db::elasticsearch_driver::EsClient::new(
+ &url,
+ Some(&db_config.username),
+ Some(&db_config.password),
+ db_config.ssl,
+ );
db::elasticsearch_driver::test_connection(&client).await?;
PoolKind::Elasticsearch(client)
}