-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgSettings.js
More file actions
81 lines (72 loc) · 2.72 KB
/
pgSettings.js
File metadata and controls
81 lines (72 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
//
// pgSettings.js
// Postgresql configuration settings
//
// VDJServer Community Data Portal
// ADC API for VDJServer
// https://vdjserver.org
//
// Copyright (C) 2024 The University of Texas Southwestern Medical Center
//
// Author: Scott Christley <scott.christley@utsouthwestern.edu>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// local DB, use tapisSettings for Tapis DB
var pgSettings = {
// Postgresql Settings
hostname: process.env.POSTGRES_HOST,
port: process.env.POSTGRES_PORT,
dbname: process.env.POSTGRES_DB,
username: process.env.POSTGRES_USER,
userSecret: process.env.POSTGRES_PASSWORD,
url: null,
query_timeout: 180000,
max_results: 10000
};
module.exports = pgSettings;
pgSettings.set_config = function(config) {
var context = 'postgres';
if (config) {
config.log.info(context, 'pgSettings config object set for app: ' + config.name, true);
pgSettings.config = config;
config.info.query_timeout = pgSettings.query_timeout;
config.info.max_results = pgSettings.max_results;
}
if (!pgSettings.port) pgSettings.port = 5432;
if (pgSettings.username) {
pgSettings.url = 'postgres://'
+ pgSettings.username + ':' + pgSettings.userSecret + '@'
+ pgSettings.hostname + ':' + pgSettings.port + '/' + pgSettings.dbname;
} else {
pgSettings.url = 'postgres://'
+ pgSettings.hostname + ':' + pgSettings.port + '/' + pgSettings.dbname;
}
config.log.info(context, 'Using Postgres host: ' + pgSettings.hostname, true);
config.log.info(context, 'Using Postgres port: ' + pgSettings.port, true);
config.log.info(context, 'Using Postgres DB: ' + pgSettings.dbname, true);
config.log.info(context, 'Using Postgres username: ' + pgSettings.username, true);
return pgSettings;
}
pgSettings.pg_connection = function() {
return {
user: pgSettings.username,
host: pgSettings.hostname,
database: pgSettings.dbname,
password: pgSettings.userSecret,
port: pgSettings.port,
statement_timeout: pgSettings.query_timeout
};
}