diff --git a/frontend/src/_components/DynamicForm.jsx b/frontend/src/_components/DynamicForm.jsx index 504ab83cc2..14294402cf 100644 --- a/frontend/src/_components/DynamicForm.jsx +++ b/frontend/src/_components/DynamicForm.jsx @@ -152,7 +152,7 @@ const DynamicForm = ({ case 'react-component-headers': return { getter: key, - options: options[key]?.value, + options: options?.[key]?.value ?? schema?.defaults?.[key]?.value, optionchanged, }; case 'react-component-oauth-authentication': diff --git a/frontend/src/_ui/HttpHeaders/index.js b/frontend/src/_ui/HttpHeaders/index.js index 534c384437..69d8da7861 100644 --- a/frontend/src/_ui/HttpHeaders/index.js +++ b/frontend/src/_ui/HttpHeaders/index.js @@ -1,6 +1,6 @@ import React from 'react'; -export default ({ getter, options = [], optionchanged }) => { +export default ({ getter, options = [['', '']], optionchanged }) => { function addNewKeyValuePair() { const newPairs = [...options, ['', '']]; optionchanged(getter, newPairs); @@ -68,6 +68,13 @@ export default ({ getter, options = [], optionchanged }) => { )} + {index === 0 && ( + + + + )} ); })} diff --git a/plugins/packages/postgresql/lib/index.ts b/plugins/packages/postgresql/lib/index.ts index 751f763c2e..40d97f086f 100644 --- a/plugins/packages/postgresql/lib/index.ts +++ b/plugins/packages/postgresql/lib/index.ts @@ -9,6 +9,16 @@ import { const { Pool } = require('pg'); import { SourceOptions, QueryOptions } from './types'; +function isEmpty(value: number | null | undefined | string) { + return ( + value === undefined || + value === null || + !isNaN(value as number) || + (typeof value === 'object' && Object.keys(value).length === 0) || + (typeof value === 'string' && value.trim().length === 0) + ); +} + export default class PostgresqlQueryService implements QueryService { private static _instance: PostgresqlQueryService; @@ -21,6 +31,19 @@ export default class PostgresqlQueryService implements QueryService { return PostgresqlQueryService._instance; } + connectionOptions(sourceOptions: SourceOptions) { + const _connectionOptions = (sourceOptions.connection_options || []).filter((o) => { + return o.some((e) => !isEmpty(e)); + }); + + const connectionOptions = Object.fromEntries(_connectionOptions); + Object.keys(connectionOptions).forEach((key) => + connectionOptions[key] === '' ? delete connectionOptions[key] : {} + ); + + return connectionOptions; + } + async run( sourceOptions: SourceOptions, queryOptions: QueryOptions, @@ -69,6 +92,7 @@ export default class PostgresqlQueryService implements QueryService { port: sourceOptions.port, statement_timeout: 10000, connectionTimeoutMillis: 10000, + ...this.connectionOptions(sourceOptions), }; const sslObject = { rejectUnauthorized: (sourceOptions.ssl_certificate ?? 'none') != 'none' }; diff --git a/plugins/packages/postgresql/lib/manifest.json b/plugins/packages/postgresql/lib/manifest.json index 3327641fef..e3a666cf27 100644 --- a/plugins/packages/postgresql/lib/manifest.json +++ b/plugins/packages/postgresql/lib/manifest.json @@ -34,6 +34,9 @@ }, "root_cert": { "encrypted": true + }, + "connection_options": { + "type": "array" } }, "exposedVariables": { @@ -61,7 +64,7 @@ "ssl_enabled": { "value": true }, - "ssl_certificate":{ + "ssl_certificate": { "value": "none" } }, @@ -85,7 +88,7 @@ "name": "None" } ], - "commonFields":{ + "commonFields": { "host": { "label": "Host", "key": "host", @@ -121,10 +124,15 @@ "key": "password", "type": "password", "description": "Enter password" + }, + "connection_options": { + "label": "Connection Options", + "key": "connection_options", + "type": "react-component-headers" } } }, - "ca_certificate":{ + "ca_certificate": { "ca_cert": { "label": "CA Cert", "key": "ca_cert", @@ -133,7 +141,7 @@ "description": "Enter ca certificate" } }, - "self_signed":{ + "self_signed": { "client_key": { "label": "Client Key", "key": "client_key", diff --git a/plugins/packages/postgresql/lib/types.ts b/plugins/packages/postgresql/lib/types.ts index c272167a56..6d96ead3e5 100644 --- a/plugins/packages/postgresql/lib/types.ts +++ b/plugins/packages/postgresql/lib/types.ts @@ -10,6 +10,7 @@ export type SourceOptions = { client_cert: string; client_key: string; root_cert: string; + connection_options: string[][]; }; export type QueryOptions = { operation: string;