mirror of
https://github.com/Canner/WrenAI.git
synced 2026-10-16 06:57:43 +08:00
fix(wren-ui): setup rejectUnauthorized for ssl connection & add sslmode to jdbc url (#302)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user