1+ import crypto from 'crypto'
2+ import { PoolConfig } from 'pg'
13import { getSecret } from '../lib/secrets.js'
24
35export const PG_META_HOST = process . env . PG_META_HOST || '0.0.0.0'
@@ -10,7 +12,6 @@ const PG_META_DB_USER = process.env.PG_META_DB_USER || 'postgres'
1012const PG_META_DB_PORT = process . env . PG_META_DB_PORT || '5432'
1113const PG_META_DB_PASSWORD = ( await getSecret ( 'PG_META_DB_PASSWORD' ) ) || 'postgres'
1214const PG_META_DB_SSL_MODE = process . env . PG_META_DB_SSL_MODE || 'disable'
13- const PG_META_DB_SSL_ROOT_CERT_PATH = process . env . PG_META_DB_SSL_ROOT_CERT_PATH
1415
1516const PG_CONN_TIMEOUT_SECS = Number ( process . env . PG_CONN_TIMEOUT_SECS || 15 )
1617
@@ -23,17 +24,24 @@ if (!PG_CONNECTION) {
2324 pgConn . password = PG_META_DB_PASSWORD
2425 pgConn . pathname = encodeURIComponent ( PG_META_DB_NAME )
2526 pgConn . searchParams . set ( 'sslmode' , PG_META_DB_SSL_MODE )
26- if ( PG_META_DB_SSL_ROOT_CERT_PATH ) {
27- pgConn . searchParams . set ( 'sslrootcert' , PG_META_DB_SSL_ROOT_CERT_PATH )
28- }
2927 PG_CONNECTION = `${ pgConn } `
3028}
3129
30+ export const PG_META_DB_SSL_ROOT_CERT = process . env . PG_META_DB_SSL_ROOT_CERT
31+ if ( PG_META_DB_SSL_ROOT_CERT ) {
32+ // validate cert
33+ new crypto . X509Certificate ( PG_META_DB_SSL_ROOT_CERT )
34+ }
35+
3236export const EXPORT_DOCS = process . argv [ 2 ] === 'docs' && process . argv [ 3 ] === 'export'
3337export const GENERATE_TYPES =
3438 process . argv [ 2 ] === 'gen' && process . argv [ 3 ] === 'types' ? process . argv [ 4 ] : undefined
3539export const GENERATE_TYPES_INCLUDED_SCHEMAS =
3640 GENERATE_TYPES && process . argv [ 5 ] === '--include-schemas' ? process . argv [ 6 ] ?. split ( ',' ) ?? [ ] : [ ]
3741
38- export const DEFAULT_POOL_CONFIG = { max : 1 , connectionTimeoutMillis : PG_CONN_TIMEOUT_SECS * 1000 }
42+ export const DEFAULT_POOL_CONFIG : PoolConfig = {
43+ max : 1 ,
44+ connectionTimeoutMillis : PG_CONN_TIMEOUT_SECS * 1000 ,
45+ }
46+
3947export const PG_META_REQ_HEADER = process . env . PG_META_REQ_HEADER || 'request-id'
0 commit comments