@@ -28,6 +28,7 @@ const SensitiveString = require('./sensitive_string');
28
28
const time_utils = require ( './time_utils' ) ;
29
29
const config = require ( '../../config' ) ;
30
30
const ssl_utils = require ( './ssl_utils' ) ;
31
+ const fs_utils = require ( './fs_utils' ) ;
31
32
32
33
const DB_CONNECT_ERROR_MESSAGE = 'Could not acquire client from DB connection pool' ;
33
34
mongodb . Binary . prototype [ util . inspect . custom ] = function custom_inspect_binary ( ) {
@@ -703,20 +704,20 @@ class PostgresTable {
703
704
return _do_query ( client || this . get_pool ( ) , q , 0 ) ;
704
705
}
705
706
706
- /**
707
+ /**
707
708
* executeSQL takes a raw SQL query and params and runs it against
708
709
* the database. If `query_name` is passed then it prepares a
709
710
* statement on the first execution while the further executions
710
711
* will re-utilize the prepared statement (pre-parsed).
711
- *
712
+ *
712
713
* @template T
713
- *
714
- * @param {string } query
715
- * @param {Array<any> } params
714
+ *
715
+ * @param {string } query
716
+ * @param {Array<any> } params
716
717
* @param {{
717
718
* query_name?: string,
718
719
* }} [options = { }]
719
- *
720
+ *
720
721
* @returns {Promise<import('pg').QueryResult<T>> }
721
722
*/
722
723
async executeSQL ( query , params , options = { } ) {
@@ -1496,22 +1497,27 @@ class PostgresClient extends EventEmitter {
1496
1497
}
1497
1498
} ;
1498
1499
1499
- const postgres_port = parseInt ( process . env . POSTGRES_PORT || '5432' , 10 ) ;
1500
1500
1501
- if ( process . env . POSTGRES_CONNECTION_STRING ) {
1501
+ if ( process . env . POSTGRES_CONNECTION_STRING_PATH ) {
1502
1502
/** @type {import('pg').PoolConfig } */
1503
1503
this . new_pool_params = {
1504
- connectionString : process . env . POSTGRES_CONNECTION_STRING ,
1504
+ connectionString : fs . readFileSync ( process . env . POSTGRES_CONNECTION_STRING_PATH , "utf8" ) ,
1505
1505
...params ,
1506
1506
} ;
1507
1507
} else {
1508
+ // get the connection configuration. first from env, then from file, then default
1509
+ const host = process . env . POSTGRES_HOST || fs_utils . try_read_file_sync ( process . env . POSTGRES_HOST_PATH ) || '127.0.0.1' ;
1510
+ const user = process . env . POSTGRES_USER || fs_utils . try_read_file_sync ( process . env . POSTGRES_USER_PATH ) || 'postgres' ;
1511
+ const password = process . env . POSTGRES_PASSWORD || fs_utils . try_read_file_sync ( process . env . POSTGRES_PASSWORD_PATH ) || 'noobaa' ;
1512
+ const database = process . env . POSTGRES_DBNAME || fs_utils . try_read_file_sync ( process . env . POSTGRES_DBNAME_PATH ) || 'nbcore' ;
1513
+ const port = parseInt ( process . env . POSTGRES_PORT || fs_utils . try_read_file_sync ( process . env . POSTGRES_PORT_PATH ) || '5432' , 10 ) ;
1508
1514
// TODO: This need to move to another function
1509
1515
this . new_pool_params = {
1510
- host : process . env . POSTGRES_HOST || '127.0.0.1' ,
1511
- user : process . env . POSTGRES_USER || 'postgres' ,
1512
- password : process . env . POSTGRES_PASSWORD || 'noobaa' ,
1513
- database : process . env . POSTGRES_DBNAME || 'nbcore' ,
1514
- port : postgres_port ,
1516
+ host,
1517
+ user,
1518
+ password,
1519
+ database,
1520
+ port,
1515
1521
...params ,
1516
1522
} ;
1517
1523
}
0 commit comments