Skip to content

Commit

Permalink
feat: add sslmode to external table config
Browse files Browse the repository at this point in the history
  • Loading branch information
jetjinser committed Mar 19, 2024
1 parent 5545276 commit eb60978
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/connector/src/source/cdc/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod mock_external_table;
mod postgres;

use std::collections::HashMap;
use std::fmt;

use anyhow::Context;
use futures::stream::BoxStream;
Expand Down Expand Up @@ -245,6 +246,32 @@ pub struct ExternalTableConfig {
pub schema: String,
#[serde(rename = "table.name")]
pub table: String,
#[serde(rename = "ssl.name", default = "Default::default")]
pub sslmode: SslMode,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SslMode {
Disable,
Prefer,
Require,
}

impl Default for SslMode {
fn default() -> Self {
Self::Disable
}
}

impl fmt::Display for SslMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
SslMode::Disable => "disable",
SslMode::Prefer => "prefer",
SslMode::Require => "require",
})
}
}

impl ExternalTableReader for MySqlExternalTableReader {
Expand Down
9 changes: 7 additions & 2 deletions src/connector/src/source/cdc/external/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ impl PostgresExternalTableReader {
.context("failed to extract postgres connector properties")?;

let database_url = format!(
"postgresql://{}:{}@{}:{}/{}",
config.username, config.password, config.host, config.port, config.database
"postgresql://{}:{}@{}:{}/{}?sslmode={}",
config.username,
config.password,
config.host,
config.port,
config.database,
dbg!(&config.sslmode)
);

let (client, connection) = tokio_postgres::connect(&database_url, NoTls).await?;
Expand Down

0 comments on commit eb60978

Please sign in to comment.