refactor!: environment variables validation #224
+225
−120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor environment variable validation rules. Apply consistent patterns to env validation.
The main motivation for this change was as follows:
Make env validation more strict and consistent. Stick to the same validation patterns in different projects.
Provide consistent fallback options for optional variables.
Here are the main changes:
Previously if a user set an empty string as the variable name in the .env file like this:
VARIABLE_NAME=
not all variable initializers assigned a correct default value to the variable in this case. Now it is fixed. For the purpose of this improvement, now all optional variable initializers always have the@Transform
decorator that provides a default value for the variable. Add the two special functions (toNumber
andtoBoolean
) that support this change.Make validation of boolean variables more strict.
CAUTION: This might be a breaking change for users who use values like "yes" to initialize boolean variables.
Now the
ETH_NETWORK
variable is validated not only when the validator source is "Lido". Make validation of this variable more strict.CAUTION: Currently the EVM doesn't officially support testnets other than those listed in the
Network
interface. But this might be a breaking change if some users use EVM for other testnets.Implement the new
toArrayOfUrls()
function to provide a reasonable default value for variables that should have a list of URLs in their values. This function also fixes a bug with default values for such variables. Previously, if a user set an empty string as a value of such variables, the validation worked incorrectly.Now we validate that values in
EL_RPC_URLS
,CL_API_URLS
, andVALIDATOR_REGISTRY_KEYSAPI_SOURCE_URLS
are indeed URLs.The validation engine now removes trailing slashes from URL values.
More consistent validation for the
HTTP_PORT
andDB_PORT
values.Add
@Optional
decorator to all optional variables.Change
@IsNumber
to@IsInt
.Move enums from the
env.validation.ts
toenvironment.interface.ts
.