Skip to content

Commit

Permalink
Make SSL option configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickEvers committed Mar 6, 2024
1 parent 034e302 commit 4c886bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/infrastructure/databasePromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -25,13 +27,15 @@ const resolveDBCredentials = () => {
host: db_host,
port: db_port,
database: db_database,
ssl: db_ssl,
};
} else {
db = {
user: db_username,
host: db_host,
port: db_port,
database: db_database,
ssl: db_ssl,
};
}
} else {
Expand All @@ -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) {
Expand Down

0 comments on commit 4c886bc

Please sign in to comment.