fix(wren-ui): setup rejectUnauthorized for ssl connection & add sslmode to jdbc url (#302)

This commit is contained in:
Shimin
2024-05-22 18:41:59 +08:00
committed by GitHub
parent e724bd8ad0
commit cfc83b464e
2 changed files with 10 additions and 3 deletions
@@ -5,6 +5,7 @@ import { WrenEngineColumnType } from './types';
import * as Errors from '@server/utils/error';
import pg from 'pg';
import { ConnectionOptions } from 'tls';
const { Client } = pg;
const logger = getLogger('PostgresConnector');
@@ -16,7 +17,7 @@ export interface PostgresConnectionConfig {
host: string;
database: string;
port: number;
ssl?: boolean;
ssl?: boolean | ConnectionOptions;
}
export interface PostgresColumnResponse {
@@ -269,6 +270,11 @@ export class PostgresConnector
return;
}
// bypass server certificate validation
if (this.config.ssl) {
this.config.ssl = { rejectUnauthorized: false };
}
this.client = new Client(this.config);
await this.client.connect();
}
@@ -260,9 +260,10 @@ export class PostgresStrategy implements IDataSourceStrategy {
}
private async patchConfigToWrenEngine(properties: any) {
const { host, port, database, user, password } = properties;
const { host, port, database, user, password, ssl } = properties;
const sslMode = ssl ? '?sslmode=require' : '';
// update wren-engine config
const jdbcUrl = `jdbc:postgresql://${host}:${port}/${database}`;
const jdbcUrl = `jdbc:postgresql://${host}:${port}/${database}${sslMode}`;
const config = {
'wren.datasource.type': 'postgres',
'postgres.jdbc.url': jdbcUrl,