mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
[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:
parent
c5d74c4a27
commit
e49ef9777f
5 changed files with 46 additions and 6 deletions
|
|
@ -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':
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
})}
|
||||
|
|
|
|||
|
|
@ -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' };
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export type SourceOptions = {
|
|||
client_cert: string;
|
||||
client_key: string;
|
||||
root_cert: string;
|
||||
connection_options: string[][];
|
||||
};
|
||||
export type QueryOptions = {
|
||||
operation: string;
|
||||
|
|
|
|||
Loading…
Reference in a new issue