1
+ import crypto from 'crypto'
2
+ import { PoolConfig } from 'pg'
1
3
import { getSecret } from '../lib/secrets.js'
2
4
3
5
export 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'
10
12
const PG_META_DB_PORT = process . env . PG_META_DB_PORT || '5432'
11
13
const PG_META_DB_PASSWORD = ( await getSecret ( 'PG_META_DB_PASSWORD' ) ) || 'postgres'
12
14
const 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
14
15
15
16
const PG_CONN_TIMEOUT_SECS = Number ( process . env . PG_CONN_TIMEOUT_SECS || 15 )
16
17
@@ -23,17 +24,24 @@ if (!PG_CONNECTION) {
23
24
pgConn . password = PG_META_DB_PASSWORD
24
25
pgConn . pathname = encodeURIComponent ( PG_META_DB_NAME )
25
26
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
- }
29
27
PG_CONNECTION = `${ pgConn } `
30
28
}
31
29
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
+
32
36
export const EXPORT_DOCS = process . argv [ 2 ] === 'docs' && process . argv [ 3 ] === 'export'
33
37
export const GENERATE_TYPES =
34
38
process . argv [ 2 ] === 'gen' && process . argv [ 3 ] === 'types' ? process . argv [ 4 ] : undefined
35
39
export const GENERATE_TYPES_INCLUDED_SCHEMAS =
36
40
GENERATE_TYPES && process . argv [ 5 ] === '--include-schemas' ? process . argv [ 6 ] ?. split ( ',' ) ?? [ ] : [ ]
37
41
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
+
39
47
export const PG_META_REQ_HEADER = process . env . PG_META_REQ_HEADER || 'request-id'
0 commit comments