Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper handle of boolean envs #479

Merged
merged 4 commits into from
May 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ function getIntEnvValue(env: any, defaultValue: number) {
return isNaN(num) ? defaultValue : num
}

function getBoolEnvValue(envName: string, defaultValue: boolean): boolean {
if (!(envName in process.env)) {
return defaultValue
}
if (
process.env[envName] ||
paulo-ocean marked this conversation as resolved.
Show resolved Hide resolved
process.env[envName] === 'true' ||
process.env[envName] === '1' ||
process.env[envName].toLowerCase() === 'yes'
) {
return true
}
return false
}

function getSupportedChains(): RPCS | null {
const logError = function (): null {
// missing or invalid RPC list
Expand Down Expand Up @@ -444,8 +459,8 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
'/ip4/34.107.3.14/tcp/8000/p2p/16Uiu2HAm4DWmX56ZX2bKjvARJQZPMUZ9xsdtAfrMmd7P8czcN4UT', // maria
'/dnsaddr/ocean-node3.oceanprotocol.io/tcp/8000/p2p/16Uiu2HAm96Sx6o8XCEifPL9MtJiZCSzKqiBQApnZ6JWd7be4zwNK' // bogdan
],
enableIPV4: process.env.P2P_ENABLE_IPV4 !== 'false',
enableIPV6: process.env.P2P_ENABLE_IPV6 !== 'false',
enableIPV4: getBoolEnvValue('P2P_ENABLE_IPV4', true),
enableIPV6: getBoolEnvValue('P2P_ENABLE_IPV6', true),
ipV4BindAddress: getEnvValue(process.env.P2P_ipV4BindAddress, '0.0.0.0'),
ipV4BindTcpPort: getIntEnvValue(process.env.P2P_ipV4BindTcpPort, 0),
ipV4BindWsPort: getIntEnvValue(process.env.P2P_ipV4BindWsPort, 0),
Expand All @@ -468,11 +483,11 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
process.env.P2P_connectionsDialTimeout,
30e3
), // 10 seconds
upnp: process.env.P2P_ENABLE_UPNP !== 'false',
autoNat: process.env.P2P_ENABLE_AUTONAT !== 'false',
enableCircuitRelayServer: process.env.P2P_ENABLE_CIRCUIT_RELAY_SERVER !== 'false',
enableCircuitRelayClient: process.env.P2P_ENABLE_CIRCUIT_RELAY_CLIENT !== 'false',
announcePrivateIp: process.env.P2P_ANNOUNCE_PRIVATE !== 'false'
upnp: getBoolEnvValue('P2P_ENABLE_UPNP', true),
autoNat: getBoolEnvValue('P2P_ENABLE_AUTONAT', true),
enableCircuitRelayServer: getBoolEnvValue('P2P_ENABLE_CIRCUIT_RELAY_SERVER', false),
enableCircuitRelayClient: getBoolEnvValue('P2P_ENABLE_CIRCUIT_RELAY_CLIENT', false),
announcePrivateIp: getBoolEnvValue('P2P_ANNOUNCE_PRIVATE', false)
},
// Only enable provider if we have a DB_URL
hasProvider: !!getEnvValue(process.env.DB_URL, ''),
Expand Down
Loading