Skip to content

Commit

Permalink
Update binding for ssl options
Browse files Browse the repository at this point in the history
  • Loading branch information
JonoPrest committed Jun 14, 2024
1 parent 730456a commit ba2a452
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"postgres": "3.4.1",
"prom-client": "15.0.0",
"react": "18.2.0",
"rescript-envsafe": "3.1.0",
"rescript-envsafe": "4.0.0",
"rescript-express": "0.4.1",
"rescript-schema": "6.4.0",
"viem": "1.16.6",
Expand Down
14 changes: 6 additions & 8 deletions codegenerator/cli/templates/static/codegen/src/Env.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
S.literal(#uinfo),
S.literal(#uwarn),
S.literal(#uerror),
S.literal("")->S.variant((. _) => default),
S.literal(None)->S.variant((. _) => default),
]),
~fallback=default
)
)
// resets the timestampCaughtUpToHeadOrEndblock after a restart when true
let updateSyncTimeOnRestart = envSafe->EnvSafe.get(. "UPDATE_SYNC_TIME_ON_RESTART", S.bool, ~fallback=true)
let updateSyncTimeOnRestart =
envSafe->EnvSafe.get(. "UPDATE_SYNC_TIME_ON_RESTART", S.bool, ~fallback=true)
let maxEventFetchedQueueSize = envSafe->EnvSafe.get(. "MAX_QUEUE_SIZE", S.int, ~fallback=100_000)
let maxProcessBatchSize = envSafe->EnvSafe.get(. "MAX_BATCH_SIZE", S.int, ~fallback=5_000)

Expand Down Expand Up @@ -51,10 +51,8 @@ let logStrategy = envSafe->EnvSafe.get(.
S.literal(ConsoleRaw),
S.literal(ConsolePretty),
S.literal(Both),
// The default value to pretty print to the console only.
S.literal("")->S.variant((. _) => ConsolePretty),
S.literal(None)->S.variant((. _) => ConsolePretty),
]),
~fallback=ConsolePretty,
)

module Db = {
Expand All @@ -65,10 +63,10 @@ module Db = {
let database = envSafe->EnvSafe.get(. "ENVIO_PG_DATABASE", S.string, ~devFallback="envio-dev")
let ssl = envSafe->EnvSafe.get(.
"ENVIO_PG_SSL_MODE",
S.bool,
Postgres.sslOptionsSchema,
//this is a dev fallback option for local deployments, shouldn't run in the prod env
//the SSL modes should be provided as string otherwise as 'require' | 'allow' | 'prefer' | 'verify-full'
~devFallback=false,
~devFallback=Bool(false),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,54 @@ type connectionConfig = {
applicationName?: string, // Default application_name (default: 'postgres.js')
// Other connection parameters, see https://www.postgresql.org/docs/current/runtime-config-client.html
}
type streamDuplex
type buffer
type secureContext

type onread = {
buffer: Js.Nullable.t<array<int>> => array<int>,
callback: (int, array<int>) => unit,
}

type tlsConnectOptions = {
enableTrace?: bool,
host?: string /* Default: "localhost" */,
port?: int,
path?: string,
socket?: streamDuplex,
allowHalfOpen?: bool /* Default: false */,
rejectUnauthorized?: bool /* Default: true */,
pskCallback?: unit => unit,
@as("ALPNProtocols") alpnProtocols?: array<string>, //| array<Buffer> | array<typedArray> | array<DataView> | Buffer | typedArray | DataView,
servername?: string,
checkServerIdentity?: 'a. (string, 'a) => option<Js.Exn.t>,
session?: buffer,
minDHSize?: int /* Default: 1024 */,
highWaterMark?: int /* Default: 16 * 1024 */,
secureContext?: secureContext,
onread?: onread,
/* Additional properties from tls.createSecureContext() and socket.connect() */
// [key: string]: Js.Json.t,
}

@unboxed
type sslOptions =
| Bool(bool)
| TLSConnectOptions(tlsConnectOptions)
| @as("require") Require
| @as("allow") Allow
| @as("prefer") Prefer
| @as("verify-full") VerifyFull

let sslOptionsSchema: S.schema<sslOptions> = S.union([
S.literal(Bool(true)),
S.literal(Bool(false)),
S.literal(Require),
S.literal(Allow),
S.literal(Prefer),
S.literal(VerifyFull),
//No schema created for tlsConnectOptions obj
])

type poolConfig = {
host?: string, // Postgres ip address[es] or domain name[s] (default: '')
Expand All @@ -21,7 +69,7 @@ type poolConfig = {
database?: string, // Name of database to connect to (default: '')
username?: string, // Username of database user (default: '')
password?: string, // Password of database user (default: '')
ssl?: bool, // true, prefer, require, tls.connect options (default: false)
ssl?: sslOptions, // true, prefer, require, tls.connect options (default: false)
max?: int, // Max number of connections (default: 10)
maxLifetime?: option<int>, // Max lifetime in seconds (more info below) (default: null)
idleTimeout?: int, // Idle connection timeout in seconds (default: 0)
Expand Down

0 comments on commit ba2a452

Please sign in to comment.