Skip to content

Commit

Permalink
Postgres Secure Connection Support (#1117)
Browse files Browse the repository at this point in the history
* init

* rename POSTGRES_SECURE to POSTGRES_SSL

* fix

* fix

* tweaks

---------

Co-authored-by: Deepak Prabhakara <[email protected]>
  • Loading branch information
ukrocks007 and deepakprabhakara authored Nov 9, 2023
1 parent 6c3ac36 commit e3e684f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
POSTGRES_HOST=127.0.0.1
POSTGRES_SSL=
HMAC_SECRET_ADMIN=xxxxxxx
NSQD_HTTP_PORT=4151
SHLVL=1
Expand Down
4 changes: 3 additions & 1 deletion src/_db/commands/up/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ 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}`;
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();
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_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,
Expand Down
1 change: 1 addition & 0 deletions src/persistence/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_SSL || false,
idleTimeoutMillis: Number(config.PUBLISHER_CREATE_EVENT_TIMEOUT) || 2000, // how long a client is allowed to remain idle before being closed
});

Expand Down

0 comments on commit e3e684f

Please sign in to comment.