-
-
Notifications
You must be signed in to change notification settings - Fork 122
feat(etl-api, etl-validation): connection validation endpoints #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| use crate::configs::encryption::EncryptionKey; | ||
| use crate::configs::source::{FullApiSourceConfig, StrippedApiSourceConfig}; | ||
| use crate::configs::source::{FullApiSourceConfig, StoredSourceConfig, StrippedApiSourceConfig}; | ||
| use crate::db; | ||
| use crate::db::sources::SourcesDbError; | ||
| use crate::routes::{ErrorMessage, TenantIdError, extract_tenant_id}; | ||
| use crate::routes::{ErrorMessage, TenantIdError, TestConnectionResponse, extract_tenant_id}; | ||
| use actix_web::{ | ||
| HttpRequest, HttpResponse, Responder, ResponseError, delete, get, | ||
| http::{StatusCode, header::ContentType}, | ||
| post, | ||
| web::{Data, Json, Path}, | ||
| }; | ||
| use etl_validation::SourceValidator; | ||
| use serde::{Deserialize, Serialize}; | ||
| use sqlx::PgPool; | ||
| use thiserror::Error; | ||
|
|
@@ -282,3 +283,30 @@ pub async fn read_all_sources( | |
|
|
||
| Ok(Json(response)) | ||
| } | ||
|
|
||
| #[utoipa::path( | ||
| summary = "Test a source connection (pre-creation)", | ||
| description = "Tests a PostgreSQL source connection without creating a resource. Validates connectivity, version, WAL level, permissions, and replication slot availability. Useful for validating credentials before creating a source.", | ||
| request_body = FullApiSourceConfig, | ||
| responses( | ||
| (status = 200, description = "Connection test successful", body = TestConnectionResponse), | ||
| (status = 400, description = "Bad request or connection test failed", body = ErrorMessage), | ||
| (status = 500, description = "Internal server error", body = ErrorMessage), | ||
| ), | ||
| tag = "Sources" | ||
| )] | ||
| #[post("/sources/test-connection")] | ||
| pub async fn test_source_connection( | ||
| config: Json<FullApiSourceConfig>, | ||
| ) -> Result<impl Responder, SourceError> { | ||
| let config = config.into_inner(); | ||
| let stored_config: StoredSourceConfig = config.into(); | ||
| let pg_config = stored_config.into_connection_config(); | ||
|
|
||
| pg_config | ||
| .validate() | ||
| .await | ||
| .map_err(|e| SourcesDbError::Database(sqlx::Error::Configuration(Box::new(e))))?; | ||
|
Comment on lines
+306
to
+309
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Validation failures from Useful? React with 👍 / 👎. |
||
|
|
||
| Ok(Json(TestConnectionResponse { valid: true })) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destination connection validation errors are converted into
DestinationsDbError::Database(sqlx::Error::Configuration(..)), whichDestinationErrorrenders as HTTP 500 with the generic "internal server error" message. The route’s OpenAPI docs include a 400 response for connection test failures, andValidationErrorprovides specific, user‑actionable reasons (e.g., bad BigQuery key, unreachable Iceberg catalog). Currently all such user errors surface as 500s without details, making clients unable to tell misconfiguration from server faults.Useful? React with 👍 / 👎.