[Enhancement] :: Allow users to add custom query parameters for postgresql connections (#4912)

* add: custom endpoint for s3 hosts

* add: key-value pair editor for connection options

* add: newkeyvalue Pair button

* fix: reset header key-value pairs
This commit is contained in:
vjaris42 2022-12-22 17:35:11 +05:30 committed by GitHub
parent c5d74c4a27
commit e49ef9777f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 6 deletions

View file

@ -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':

View file

@ -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 }) => {
</span>
</td>
)}
{index === 0 && (
<td>
<button className="btn btn-sm btn-primary" onClick={addNewKeyValuePair}>
Add
</button>
</td>
)}
</tr>
);
})}

View file

@ -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' };

View file

@ -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",

View file

@ -10,6 +10,7 @@ export type SourceOptions = {
client_cert: string;
client_key: string;
root_cert: string;
connection_options: string[][];
};
export type QueryOptions = {
operation: string;