Add allowUnauthorizedCerts to Postgres-Node

This commit is contained in:
Jan Oberhauser 2020-08-25 17:02:01 +02:00
parent 2c9e589c72
commit 88b0147292
2 changed files with 24 additions and 3 deletions

View file

@ -36,10 +36,24 @@ export class Postgres implements ICredentialType {
}, },
default: '', default: '',
}, },
{
displayName: 'Ignore SSL Issues',
name: 'allowUnauthorizedCerts',
type: 'boolean',
default: false,
description: 'Connect even if SSL certificate validation is not possible.',
},
{ {
displayName: 'SSL', displayName: 'SSL',
name: 'ssl', name: 'ssl',
type: 'options' as NodePropertyTypes, type: 'options' as NodePropertyTypes,
displayOptions: {
show: {
allowUnauthorizedCerts: [
false,
],
},
},
options: [ options: [
{ {
name: 'disable', name: 'disable',

View file

@ -189,16 +189,23 @@ export class Postgres implements INodeType {
const pgp = pgPromise(); const pgp = pgPromise();
const config = { const config: IDataObject = {
host: credentials.host as string, host: credentials.host as string,
port: credentials.port as number, port: credentials.port as number,
database: credentials.database as string, database: credentials.database as string,
user: credentials.user as string, user: credentials.user as string,
password: credentials.password as string, password: credentials.password as string,
ssl: !['disable', undefined].includes(credentials.ssl as string | undefined),
sslmode: (credentials.ssl as string) || 'disable',
}; };
if (credentials.allowUnauthorizedCerts === true) {
config.ssl = {
rejectUnauthorized: false,
};
} else {
config.ssl = !['disable', undefined].includes(credentials.ssl as string | undefined);
config.sslmode = (credentials.ssl as string) || 'disable';
}
const db = pgp(config); const db = pgp(config);
let returnItems = []; let returnItems = [];