From 9e40c9283ddda829afbb4f2b426aec2f6850fdb1 Mon Sep 17 00:00:00 2001 From: ukrocks007 Date: Thu, 9 Nov 2023 19:43:21 +0530 Subject: [PATCH 1/5] init --- .env | 1 + src/_db/commands/up/pg.ts | 7 ++++++- src/config.ts | 1 + src/persistence/pg.ts | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 39be639d..be3f4e63 100644 --- a/.env +++ b/.env @@ -3,6 +3,7 @@ HMAC_SECRET_ADMIN=xxxxxxx NSQD_HTTP_PORT=4151 SHLVL=1 POSTGRES_USER=retraced +POSTGRES_SECURE= EXPORT_PAGE_SIZE_INTERNAL=2 POSTGRES_PASSWORD=password POSTGRES_POOL_SIZE=10 diff --git a/src/_db/commands/up/pg.ts b/src/_db/commands/up/pg.ts index 1a7a659e..e8228192 100644 --- a/src/_db/commands/up/pg.ts +++ b/src/_db/commands/up/pg.ts @@ -37,7 +37,12 @@ export const handler = async (argv) => { try { const postgrator = (await import("postgrator")).default; logger.child({ up: "pg", schemaPath: argv.schemaPath }).info("beginning handler"); - const cs = `tcp://${argv.postgresUser}:${argv.postgresPassword}@${argv.postgresHost}:${argv.postgresPort}/${argv.postgresDatabase}`; + let cs; + if (argv.postgresSecure) { + cs = `tcp://${argv.postgresUser}:${argv.postgresPassword}@${argv.postgresHost}:${argv.postgresPort}/${argv.postgresDatabase}?sslmode=require`; + } else { + cs = `tcp://${argv.postgresUser}:${argv.postgresPassword}@${argv.postgresHost}:${argv.postgresPort}/${argv.postgresDatabase}`; + } const client = new pg.Client(cs); // Establish a database connection await client.connect(); diff --git a/src/config.ts b/src/config.ts index 49ecd6e8..434557c8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -10,6 +10,7 @@ export default { EXPORT_PAGE_SIZE_INTERNAL: process.env.EXPORT_PAGE_SIZE_INTERNAL || env.EXPORT_PAGE_SIZE_INTERNAL || 10000, POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD || env.POSTGRES_PASSWORD, POSTGRES_POOL_SIZE: process.env.POSTGRES_POOL_SIZE || env.POSTGRES_POOL_SIZE || 20, + POSTGRES_SECURE: process.env.POSTGRES_SECURE || env.POSTGRES_SECURE || true, HMAC_SECRET_VIEWER: process.env.HMAC_SECRET_VIEWER || env.HMAC_SECRET_VIEWER, POSTGRES_PORT: process.env.POSTGRES_PORT || env.POSTGRES_PORT, API_BASE_URL_PATH: process.env.API_BASE_URL_PATH || env.API_BASE_URL_PATH, diff --git a/src/persistence/pg.ts b/src/persistence/pg.ts index 1b3c7125..a102c320 100644 --- a/src/persistence/pg.ts +++ b/src/persistence/pg.ts @@ -15,6 +15,7 @@ export default function getPgPool(): pg.Pool { host: config.POSTGRES_HOST, port: Number(config.POSTGRES_PORT), max: Number(config.POSTGRES_POOL_SIZE) || 20, + ssl: config.POSTGRES_SECURE || false, idleTimeoutMillis: Number(config.PUBLISHER_CREATE_EVENT_TIMEOUT) || 2000, // how long a client is allowed to remain idle before being closed }); From 970efc3751f2d066248e0a3b194042566d872fe5 Mon Sep 17 00:00:00 2001 From: ukrocks007 Date: Thu, 9 Nov 2023 20:14:41 +0530 Subject: [PATCH 2/5] rename POSTGRES_SECURE to POSTGRES_SSL --- src/_db/commands/up/pg.ts | 2 +- src/config.ts | 2 +- src/persistence/pg.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_db/commands/up/pg.ts b/src/_db/commands/up/pg.ts index e8228192..1b77b396 100644 --- a/src/_db/commands/up/pg.ts +++ b/src/_db/commands/up/pg.ts @@ -38,7 +38,7 @@ export const handler = async (argv) => { const postgrator = (await import("postgrator")).default; logger.child({ up: "pg", schemaPath: argv.schemaPath }).info("beginning handler"); let cs; - if (argv.postgresSecure) { + if (argv.postgresSsl) { cs = `tcp://${argv.postgresUser}:${argv.postgresPassword}@${argv.postgresHost}:${argv.postgresPort}/${argv.postgresDatabase}?sslmode=require`; } else { cs = `tcp://${argv.postgresUser}:${argv.postgresPassword}@${argv.postgresHost}:${argv.postgresPort}/${argv.postgresDatabase}`; diff --git a/src/config.ts b/src/config.ts index 434557c8..8944f02d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -10,7 +10,7 @@ export default { EXPORT_PAGE_SIZE_INTERNAL: process.env.EXPORT_PAGE_SIZE_INTERNAL || env.EXPORT_PAGE_SIZE_INTERNAL || 10000, POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD || env.POSTGRES_PASSWORD, POSTGRES_POOL_SIZE: process.env.POSTGRES_POOL_SIZE || env.POSTGRES_POOL_SIZE || 20, - POSTGRES_SECURE: process.env.POSTGRES_SECURE || env.POSTGRES_SECURE || true, + POSTGRES_SSL: process.env.POSTGRES_SSL || env.POSTGRES_SSL || true, HMAC_SECRET_VIEWER: process.env.HMAC_SECRET_VIEWER || env.HMAC_SECRET_VIEWER, POSTGRES_PORT: process.env.POSTGRES_PORT || env.POSTGRES_PORT, API_BASE_URL_PATH: process.env.API_BASE_URL_PATH || env.API_BASE_URL_PATH, diff --git a/src/persistence/pg.ts b/src/persistence/pg.ts index a102c320..f791c9c8 100644 --- a/src/persistence/pg.ts +++ b/src/persistence/pg.ts @@ -15,7 +15,7 @@ export default function getPgPool(): pg.Pool { host: config.POSTGRES_HOST, port: Number(config.POSTGRES_PORT), max: Number(config.POSTGRES_POOL_SIZE) || 20, - ssl: config.POSTGRES_SECURE || false, + ssl: config.POSTGRES_SSL || false, idleTimeoutMillis: Number(config.PUBLISHER_CREATE_EVENT_TIMEOUT) || 2000, // how long a client is allowed to remain idle before being closed }); From 57233dda112413b4773f285a38cd79673c22370e Mon Sep 17 00:00:00 2001 From: ukrocks007 Date: Thu, 9 Nov 2023 20:15:29 +0530 Subject: [PATCH 3/5] fix --- .env | 1 + 1 file changed, 1 insertion(+) diff --git a/.env b/.env index be3f4e63..b1b1a2e4 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ POSTGRES_HOST=127.0.0.1 +POSTGRES_SSL= HMAC_SECRET_ADMIN=xxxxxxx NSQD_HTTP_PORT=4151 SHLVL=1 From adff688f5d0f5e2cf600684d8d28e354e38ee8a7 Mon Sep 17 00:00:00 2001 From: ukrocks007 Date: Thu, 9 Nov 2023 20:16:30 +0530 Subject: [PATCH 4/5] fix --- .env | 1 - 1 file changed, 1 deletion(-) diff --git a/.env b/.env index b1b1a2e4..f6e7f89a 100644 --- a/.env +++ b/.env @@ -4,7 +4,6 @@ HMAC_SECRET_ADMIN=xxxxxxx NSQD_HTTP_PORT=4151 SHLVL=1 POSTGRES_USER=retraced -POSTGRES_SECURE= EXPORT_PAGE_SIZE_INTERNAL=2 POSTGRES_PASSWORD=password POSTGRES_POOL_SIZE=10 From e1ba16be07ec67dddcf1b596a72fe27d3e4104cc Mon Sep 17 00:00:00 2001 From: Deepak Prabhakara Date: Thu, 9 Nov 2023 23:12:19 +0100 Subject: [PATCH 5/5] tweaks --- src/_db/commands/up/pg.ts | 9 +++------ src/config.ts | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/_db/commands/up/pg.ts b/src/_db/commands/up/pg.ts index 1b77b396..c39ba85a 100644 --- a/src/_db/commands/up/pg.ts +++ b/src/_db/commands/up/pg.ts @@ -37,12 +37,9 @@ export const handler = async (argv) => { try { const postgrator = (await import("postgrator")).default; logger.child({ up: "pg", schemaPath: argv.schemaPath }).info("beginning handler"); - let cs; - if (argv.postgresSsl) { - cs = `tcp://${argv.postgresUser}:${argv.postgresPassword}@${argv.postgresHost}:${argv.postgresPort}/${argv.postgresDatabase}?sslmode=require`; - } else { - cs = `tcp://${argv.postgresUser}:${argv.postgresPassword}@${argv.postgresHost}:${argv.postgresPort}/${argv.postgresDatabase}`; - } + const cs = `tcp://${argv.postgresUser}:${argv.postgresPassword}@${argv.postgresHost}:${ + argv.postgresPort + }/${argv.postgresDatabase}${argv.postgresSsl ? "?sslmode=require" : ""}`; const client = new pg.Client(cs); // Establish a database connection await client.connect(); diff --git a/src/config.ts b/src/config.ts index 8944f02d..14694073 100644 --- a/src/config.ts +++ b/src/config.ts @@ -10,7 +10,7 @@ export default { EXPORT_PAGE_SIZE_INTERNAL: process.env.EXPORT_PAGE_SIZE_INTERNAL || env.EXPORT_PAGE_SIZE_INTERNAL || 10000, POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD || env.POSTGRES_PASSWORD, POSTGRES_POOL_SIZE: process.env.POSTGRES_POOL_SIZE || env.POSTGRES_POOL_SIZE || 20, - POSTGRES_SSL: process.env.POSTGRES_SSL || env.POSTGRES_SSL || true, + POSTGRES_SSL: process.env.POSTGRES_SSL || env.POSTGRES_SSL, HMAC_SECRET_VIEWER: process.env.HMAC_SECRET_VIEWER || env.HMAC_SECRET_VIEWER, POSTGRES_PORT: process.env.POSTGRES_PORT || env.POSTGRES_PORT, API_BASE_URL_PATH: process.env.API_BASE_URL_PATH || env.API_BASE_URL_PATH,