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

ES 8.x enables HTTPS with self-signed certs by default. When SSL is
toggled on, use https:// scheme and accept invalid certificates.

Closes #234
This commit is contained in:
t8y2
2026-05-13 14:07:01 +08:00
parent 4dc3a1b3c0
commit 321ebc2636
4 changed files with 33 additions and 11 deletions
+12 -4
View File
@@ -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)
}