File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -66,17 +66,29 @@ const configure = () => {
6666 const envPostgresHost = process . env . DB_POSTGRES_HOST || null ;
6767 const envPostgresUser = process . env . DB_POSTGRES_USER || null ;
6868 const envPostgresName = process . env . DB_POSTGRES_NAME || null ;
69+ const envPostgresSslMode = process . env . DB_POSTGRES_SSL_MODE || null ;
6970 if ( envPostgresHost && envPostgresUser && envPostgresName ) {
7071 // we have enough postgres creds to go with postgres
7172 logger . info ( "Using Postgres configuration" ) ;
73+
74+ // knex does not handle ssl enablement other than in the connectionString, so let's use it
75+ // this prevents the serivce from starting on databases with self signed certificates
76+ // cf https://knexjs.org/guide/#configuration-options
77+ port = process . env . DB_POSTGRES_PORT || 5432
78+ connectionString = `postgresql://${ envPostgresUser } :${ process . env . DB_POSTGRES_PASSWORD } @${ port } /${ envPostgresName } `
79+ if ( envPostgresSslMode ) {
80+ connectionString = connectionString + `?ssl=true&sslmode=${ envPostgresSslMode } `
81+ }
7282 instance = {
7383 database : {
84+ connectionString : connectionString ,
7485 engine : postgresEngine ,
7586 host : envPostgresHost ,
76- port : process . env . DB_POSTGRES_PORT || 5432 ,
87+ port : port ,
7788 user : envPostgresUser ,
7889 password : process . env . DB_POSTGRES_PASSWORD ,
7990 name : envPostgresName ,
91+ ssl : envPostgresSslMode ? { rejectUnauthorized : false } : false
8092 } ,
8193 keys : getKeys ( ) ,
8294 } ;
You can’t perform that action at this time.
0 commit comments