mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
Autofill encoding in postgres (#15617)
* autofill encoding * link * index file changed * ssl * form priotized --------- Co-authored-by: gsmithun4 <gsmithun4@gmail.com>
This commit is contained in:
parent
641c7df8d7
commit
1f9e4e5eac
3 changed files with 36 additions and 17 deletions
|
|
@ -29,6 +29,17 @@ export const validatePostgresConnectionString = (connectionString) => {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (url.username) decodeURIComponent(url.username);
|
||||
if (url.password) decodeURIComponent(url.password);
|
||||
if (url.pathname) decodeURIComponent(url.pathname.replace(/^\//, ''));
|
||||
} catch {
|
||||
return {
|
||||
valid: false,
|
||||
error: 'Invalid URL encoding in connection string credentials',
|
||||
};
|
||||
}
|
||||
|
||||
return { valid: true, error: '' };
|
||||
} catch {
|
||||
return { valid: false, error: 'Malformed PostgreSQL connection string' };
|
||||
|
|
@ -52,17 +63,28 @@ export const parsePostgresConnectionString = (connectionString) => {
|
|||
sslmode === 'verify-ca' ||
|
||||
sslmode === 'prefer' ||
|
||||
sslmode === 'allow' ||
|
||||
sslmode === 'on' ||
|
||||
sslmode === 'yes' ||
|
||||
ssl === 'true' ||
|
||||
ssl === 'on' ||
|
||||
ssl === 'yes' ||
|
||||
ssl === '1';
|
||||
|
||||
const isSslOff = sslmode === 'disable' || ssl === 'false' || ssl === '0';
|
||||
const isSslOff =
|
||||
sslmode === 'disable' ||
|
||||
sslmode === 'off' ||
|
||||
sslmode === 'no' ||
|
||||
ssl === 'false' ||
|
||||
ssl === 'off' ||
|
||||
ssl === 'no' ||
|
||||
ssl === '0';
|
||||
|
||||
return {
|
||||
host: url.hostname || '',
|
||||
port: url.port || '5432',
|
||||
username: decodeURIComponent(url.username || ''),
|
||||
password: decodeURIComponent(url.password || ''),
|
||||
database: url.pathname.replace(/^\//, '') || '',
|
||||
database: decodeURIComponent(url.pathname.replace(/^\//, '') || ''),
|
||||
ssl_enabled: isSslOn ? true : isSslOff ? false : undefined,
|
||||
query_params: url.search || '',
|
||||
protocol: url.protocol.replace(':', ''),
|
||||
|
|
|
|||
|
|
@ -752,7 +752,7 @@ export default class PostgresqlQueryService implements QueryService {
|
|||
const connPass = decodeURIComponent(parsedUrl.password || '');
|
||||
const connHost = parsedUrl.hostname || '';
|
||||
const connPort: number = parsedUrl.port ? Number(parsedUrl.port) : 5432;
|
||||
const connDb = parsedUrl.pathname ? parsedUrl.pathname.replace('/', '') : '';
|
||||
const connDb =decodeURIComponent( parsedUrl.pathname ? parsedUrl.pathname.replace('/', '') : '');
|
||||
const sslmode = parsedUrl.searchParams.get('sslmode') || parsedUrl.searchParams.get('ssl') || '';
|
||||
|
||||
let connSslEnabled: boolean | undefined;
|
||||
|
|
@ -763,19 +763,15 @@ export default class PostgresqlQueryService implements QueryService {
|
|||
connSslEnabled = false;
|
||||
}
|
||||
// Explicit UI values override connection string values
|
||||
resolvedUser = sourceOptions.username || connUser;
|
||||
resolvedPass = sourceOptions.password || connPass;
|
||||
resolvedUser = sourceOptions.username;
|
||||
resolvedPass = sourceOptions.password;
|
||||
// Only override if user explicitly changed away from the default
|
||||
resolvedHost = sourceOptions.host && sourceOptions.host !== 'localhost' ? sourceOptions.host : connHost;
|
||||
resolvedHost = sourceOptions.host;
|
||||
|
||||
resolvedPort = sourceOptions.port && Number(sourceOptions.port) !== 5432 ? Number(sourceOptions.port) : connPort;
|
||||
resolvedPort = Number(sourceOptions.port);
|
||||
|
||||
resolvedDb = sourceOptions.database || connDb;
|
||||
resolvedDb = sourceOptions.database;
|
||||
|
||||
// SSL Autofill
|
||||
if (!sourceOptions.ssl_enabled && connSslEnabled) {
|
||||
sourceOptions.ssl_enabled = connSslEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
// --- SSL config ---
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
},
|
||||
"connection_string": {
|
||||
"type": "string",
|
||||
"title": "Connection string",
|
||||
"title": "Connection string (encoded)",
|
||||
"description": "postgres://username:password@hostname:port/database?sslmode=require"
|
||||
},
|
||||
"ca_cert": {
|
||||
|
|
@ -211,7 +211,7 @@
|
|||
"widget": "dropdown-component-flip",
|
||||
"list": [
|
||||
{ "name": "Manual connection", "value": "manual" },
|
||||
{ "name": "Connection string", "value": "string" }
|
||||
{ "name": "Connection string (encoded)", "value": "string" }
|
||||
]
|
||||
},
|
||||
"manual": {
|
||||
|
|
@ -422,11 +422,12 @@
|
|||
"order": 2,
|
||||
"$ref": "#/properties/connection_string",
|
||||
"key": "connection_string",
|
||||
"label": "Connection string",
|
||||
"label": "Connection string (encoded)",
|
||||
"description": "postgres://username:password@hostname:port/database?sslmode=require",
|
||||
"widget": "password-v3-textarea",
|
||||
"required": true
|
||||
},
|
||||
"required": true,
|
||||
"help_text":"e.g., postgresql://admin:p%40ssword@localhost:5432/my%23db. Encode special characters using a <a href=\"https://meyerweb.com/eric/tools/dencoder/\" target=\"_blank\">URL encoder</a>."
|
||||
},
|
||||
"host": {
|
||||
"order": 10,
|
||||
"$ref": "#/properties/host",
|
||||
|
|
|
|||
Loading…
Reference in a new issue