From 4c886bca8e64a3402bef0efb89c79c32413a32fd Mon Sep 17 00:00:00 2001 From: Yannick Evers Date: Wed, 6 Mar 2024 16:25:08 +0000 Subject: [PATCH] Make SSL option configurable --- src/config.js | 1 + src/infrastructure/databasePromise.js | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config.js b/src/config.js index a4c9c9e..3ab9200 100644 --- a/src/config.js +++ b/src/config.js @@ -14,6 +14,7 @@ exports.DB_DATABASE = process.env.DB_DATABASE; exports.DB_USERNAME = process.env.DB_USERNAME; exports.DB_PASSWORD = process.env.DB_PASSWORD; exports.DB_PORT = process.env.DB_PORT || 5432; +exports.DB_SSL = process.env.DB_SSL || false; exports.CONNECTION_POOL_SIZE = process.env.CONNECTION_POOL_SIZE || 10; exports.DB_IDLE_TIMEOUT_MILLIS = process.env.DB_IDLE_TIMEOUT_MILLIS; exports.DB_MAX_USES = process.env.DB_MAX_USES; diff --git a/src/infrastructure/databasePromise.js b/src/infrastructure/databasePromise.js index 7e81683..cd869e5 100644 --- a/src/infrastructure/databasePromise.js +++ b/src/infrastructure/databasePromise.js @@ -9,12 +9,14 @@ const resolveDBCredentials = () => { const db_host = config.DB_HOST; const db_port = config.DB_PORT; const db_database = config.DB_DATABASE; + const db_ssl = config.DB_SSL; if (!db_username || (config.NODE_ENV === 'production' && !db_password) || !db_host || !db_port || - !db_database) { + !db_database || + !db_ssl) { throw new Error('expected database credentials but incomplete specified'); } @@ -25,6 +27,7 @@ const resolveDBCredentials = () => { host: db_host, port: db_port, database: db_database, + ssl: db_ssl, }; } else { db = { @@ -32,6 +35,7 @@ const resolveDBCredentials = () => { host: db_host, port: db_port, database: db_database, + ssl: db_ssl, }; } } else { @@ -41,12 +45,12 @@ const resolveDBCredentials = () => { host: 'localhost', port: 5432, database: 'schulcloud_calendar', + ssl: false, //default }; } // https://github.com/vitaly-t/pg-promise/wiki/Connection-Syntax#configuration-object // https://www.npmjs.com/package/pg-pool // https://docs.hpi-schul-cloud.org/display/CARCH/Open+Issues+Scalability+and+Stabilization - db.ssl = true; // db.connectionTimeoutMillis = 1000; // db.min = config.CONNECTION_POOL_SIZE_MIN; // validate if it is exist if (config.DB_IDLE_TIMEOUT_MILLIS) {