mirror of
https://github.com/BreizhHardware/Jellystat.git
synced 2026-01-18 16:27:20 +01:00
user configurable validation of psql ssl
This commit is contained in:
@@ -5,12 +5,14 @@ const _POSTGRES_PASSWORD = process.env.POSTGRES_PASSWORD;
|
|||||||
const _POSTGRES_IP = process.env.POSTGRES_IP;
|
const _POSTGRES_IP = process.env.POSTGRES_IP;
|
||||||
const _POSTGRES_PORT = process.env.POSTGRES_PORT;
|
const _POSTGRES_PORT = process.env.POSTGRES_PORT;
|
||||||
const _POSTGRES_DATABASE = process.env.POSTGRES_DB || 'jfstat';
|
const _POSTGRES_DATABASE = process.env.POSTGRES_DB || 'jfstat';
|
||||||
|
const _POSTGRES_SSL_REJECT_UNAUTHORIZED = process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === undefined ? true : process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === "true";
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
host: _POSTGRES_IP,
|
host: _POSTGRES_IP,
|
||||||
user: _POSTGRES_USER,
|
user: _POSTGRES_USER,
|
||||||
password: _POSTGRES_PASSWORD,
|
password: _POSTGRES_PASSWORD,
|
||||||
port: _POSTGRES_PORT,
|
port: _POSTGRES_PORT,
|
||||||
|
ssl: { rejectUnauthorized: _POSTGRES_SSL_REJECT_UNAUTHORIZED }
|
||||||
});
|
});
|
||||||
|
|
||||||
const createDatabase = async () => {
|
const createDatabase = async () => {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const _POSTGRES_PASSWORD = process.env.POSTGRES_PASSWORD;
|
|||||||
const _POSTGRES_IP = process.env.POSTGRES_IP;
|
const _POSTGRES_IP = process.env.POSTGRES_IP;
|
||||||
const _POSTGRES_PORT = process.env.POSTGRES_PORT;
|
const _POSTGRES_PORT = process.env.POSTGRES_PORT;
|
||||||
const _POSTGRES_DATABASE = process.env.POSTGRES_DB || "jfstat";
|
const _POSTGRES_DATABASE = process.env.POSTGRES_DB || "jfstat";
|
||||||
|
const _POSTGRES_SSL_REJECT_UNAUTHORIZED = process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === undefined ? true : process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === "true";
|
||||||
|
|
||||||
if ([_POSTGRES_USER, _POSTGRES_PASSWORD, _POSTGRES_IP, _POSTGRES_PORT].includes(undefined)) {
|
if ([_POSTGRES_USER, _POSTGRES_PASSWORD, _POSTGRES_IP, _POSTGRES_PORT].includes(undefined)) {
|
||||||
console.log("Error: Postgres details not defined");
|
console.log("Error: Postgres details not defined");
|
||||||
@@ -22,6 +23,7 @@ const pool = new Pool({
|
|||||||
max: 20, // Maximum number of connections in the pool
|
max: 20, // Maximum number of connections in the pool
|
||||||
idleTimeoutMillis: 30000, // Close idle clients after 30 seconds
|
idleTimeoutMillis: 30000, // Close idle clients after 30 seconds
|
||||||
connectionTimeoutMillis: 2000, // Return an error after 2 seconds if connection could not be established
|
connectionTimeoutMillis: 2000, // Return an error after 2 seconds if connection could not be established
|
||||||
|
ssl: { rejectUnauthorized: _POSTGRES_SSL_REJECT_UNAUTHORIZED } // Enable SSL without strict cert validation
|
||||||
});
|
});
|
||||||
|
|
||||||
pool.on("error", (err, client) => {
|
pool.on("error", (err, client) => {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ module.exports = {
|
|||||||
port:process.env.POSTGRES_PORT,
|
port:process.env.POSTGRES_PORT,
|
||||||
database: process.env.POSTGRES_DB || 'jfstat',
|
database: process.env.POSTGRES_DB || 'jfstat',
|
||||||
createDatabase: true,
|
createDatabase: true,
|
||||||
|
ssl: { rejectUnauthorized: process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === undefined ? true : process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === "true" }
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: __dirname + '/migrations',
|
directory: __dirname + '/migrations',
|
||||||
@@ -39,6 +40,7 @@ module.exports = {
|
|||||||
port:process.env.POSTGRES_PORT,
|
port:process.env.POSTGRES_PORT,
|
||||||
database: process.env.POSTGRES_DB || 'jfstat',
|
database: process.env.POSTGRES_DB || 'jfstat',
|
||||||
createDatabase: true,
|
createDatabase: true,
|
||||||
|
ssl: { rejectUnauthorized: process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === undefined ? true : process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === "true" }
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: __dirname + '/migrations',
|
directory: __dirname + '/migrations',
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ const postgresPassword = process.env.POSTGRES_PASSWORD;
|
|||||||
const postgresIp = process.env.POSTGRES_IP;
|
const postgresIp = process.env.POSTGRES_IP;
|
||||||
const postgresPort = process.env.POSTGRES_PORT;
|
const postgresPort = process.env.POSTGRES_PORT;
|
||||||
const postgresDatabase = process.env.POSTGRES_DB || "jfstat";
|
const postgresDatabase = process.env.POSTGRES_DB || "jfstat";
|
||||||
|
const postgresSslRejectUnauthorized = process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === undefined ? true : process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED === "true";
|
||||||
|
|
||||||
const backupfolder = "backup-data";
|
const backupfolder = "backup-data";
|
||||||
|
|
||||||
// Restore function
|
// Restore function
|
||||||
@@ -52,6 +54,7 @@ async function restore(file, refLog) {
|
|||||||
host: postgresIp,
|
host: postgresIp,
|
||||||
port: postgresPort,
|
port: postgresPort,
|
||||||
database: postgresDatabase,
|
database: postgresDatabase,
|
||||||
|
ssl: { rejectUnauthorized: postgresSslRejectUnauthorized },
|
||||||
});
|
});
|
||||||
|
|
||||||
const backupPath = file;
|
const backupPath = file;
|
||||||
|
|||||||
Reference in New Issue
Block a user