From 0872f3e3d743a16533ac4fad4cd83b103047808c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABns=20Usovs?= Date: Fri, 3 Mar 2023 21:01:18 +0100 Subject: [PATCH] Allow streaming to connect to postgress with self-signed certs (#21431) --- package.json | 1 + streaming/index.js | 38 +------------------------------------- yarn.lock | 5 +++++ 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 1ab297d041..15bf30925c 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "object.values": "^1.1.6", "path-complete-extname": "^1.0.0", "pg": "^8.5.0", + "pg-connection-string": "^2.5.0", "postcss": "^8.4.21", "postcss-loader": "^3.0.0", "promise.prototype.finally": "^3.1.4", diff --git a/streaming/index.js b/streaming/index.js index 32e3babaa4..ba7cfea191 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -7,6 +7,7 @@ const express = require('express'); const http = require('http'); const redis = require('redis'); const pg = require('pg'); +const dbUrlToConfig = require('pg-connection-string').parse; const log = require('npmlog'); const url = require('url'); const uuid = require('uuid'); @@ -23,43 +24,6 @@ dotenv.config({ log.level = process.env.LOG_LEVEL || 'verbose'; -/** - * @param {string} dbUrl - * @return {Object.} - */ -const dbUrlToConfig = (dbUrl) => { - if (!dbUrl) { - return {}; - } - - const params = url.parse(dbUrl, true); - const config = {}; - - if (params.auth) { - [config.user, config.password] = params.auth.split(':'); - } - - if (params.hostname) { - config.host = params.hostname; - } - - if (params.port) { - config.port = params.port; - } - - if (params.pathname) { - config.database = params.pathname.split('/')[1]; - } - - const ssl = params.query && params.query.ssl; - - if (ssl && ssl === 'true' || ssl === '1') { - config.ssl = true; - } - - return config; -}; - /** * @param {Object.} defaultConfig * @param {string} redisUrl diff --git a/yarn.lock b/yarn.lock index a856cf91dd..68cef79651 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8322,6 +8322,11 @@ pg-connection-string@^2.4.0: resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.4.0.tgz#c979922eb47832999a204da5dbe1ebf2341b6a10" integrity sha512-3iBXuv7XKvxeMrIgym7njT+HlZkwZqqGX4Bu9cci8xHZNT+Um1gWKqCsAzcC0d95rcKMU5WBg6YRUcHyV0HZKQ== +pg-connection-string@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34" + integrity sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ== + pg-int8@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"