@@ -68,32 +68,31 @@ const configure = () => {
6868 const envPostgresName = process . env . DB_POSTGRES_NAME || null ;
6969 const envPostgresSslMode = process . env . DB_POSTGRES_SSL_MODE || null ;
7070 if ( envPostgresHost && envPostgresUser && envPostgresName ) {
71- // we have enough postgres creds to go with postgres
72- 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 } `
71+ // we have enough postgres creds to go with postgres
72+ logger . info ( "Using Postgres configuration" ) ;
73+ sslconfig = {
74+ rejectUnauthorized : false
75+ }
7976 if ( envPostgresSslMode ) {
80- connectionString = connectionString + `?ssl=true&sslmode= ${ envPostgresSslMode } `
77+ sslconfig . sslmode = envPostgresSslMode
8178 }
82- instance = {
83- database : {
84- connectionString : connectionString ,
85- engine : postgresEngine ,
86- host : envPostgresHost ,
87- port : port ,
88- user : envPostgresUser ,
89- password : process . env . DB_POSTGRES_PASSWORD ,
90- name : envPostgresName ,
91- ssl : envPostgresSslMode ? { rejectUnauthorized : false } : false
92- } ,
93- keys : getKeys ( ) ,
94- } ;
95- return ;
96- }
79+ if ( envPostgresSslMode === "verify-full" ) {
80+ sslconfig . rejectUnauthorized = true
81+ }
82+ instance = {
83+ database : {
84+ engine : postgresEngine ,
85+ host : envPostgresHost ,
86+ port : port ,
87+ user : envPostgresUser ,
88+ password : process . env . DB_POSTGRES_PASSWORD ,
89+ name : envPostgresName ,
90+ ssl : envPostgresSslMode ? sslconfig : false
91+ } ,
92+ keys : getKeys ( ) ,
93+ } ;
94+ return ;
95+ }
9796
9897 const envSqliteFile = process . env . DB_SQLITE_FILE || "/data/database.sqlite" ;
9998 logger . info ( `Using Sqlite: ${ envSqliteFile } ` ) ;
0 commit comments