hashgraph / hedera-json-rpc-relay

Implementation of Ethereum JSON-RPC APIs for Hedera
Apache License 2.0
48 stars 62 forks source link

feat: environment variables validation #3047

Open natanasow opened 1 day ago

natanasow commented 1 day ago

Description:

When updating CI we noticed with the configuration updates, that if an environment variable such as OPERATOR_ID was defined with not value, it would override the values in the .env file. This caused tests to fail when the relay tried to submit a transaction. Ideally, the relay to fail fast, during bootstrap if required environment variables are not set.

Solution:

Consolidate environment variable loading to the start of the relay. Fail to start if any required environment variables are not set. Better to fail fast.

All environment variables should be handled in one class that can also validate them, list their usage in a --help option, and exit appropriately if a validation fails.

We should also replace environment variables with a yml settings file.

Needed validations:

Implementation Steps

There are several solid proposals by @AlfredoG87 that we should take into account as well. Described here https://github.com/hashgraph/hedera-json-rpc-relay/pull/2956#pullrequestreview-2338214042.

cc: @ebadiere

Related issue(s):

Fixes #3023

Notes for reviewer:

Checklist

codecov[bot] commented 1 day ago

Codecov Report

Attention: Patch coverage is 96.34146% with 3 lines in your changes missing coverage. Please review.

Project coverage is 84.82%. Comparing base (ab8d06e) to head (2b4efba).

Files with missing lines Patch % Lines
...kages/config-service/src/services/loggerService.ts 57.14% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## 2686-capture-env-variables-into-constants #3047 +/- ## ============================================================================= - Coverage 85.01% 84.82% -0.20% ============================================================================= Files 59 46 -13 Lines 3943 3307 -636 Branches 786 650 -136 ============================================================================= - Hits 3352 2805 -547 + Misses 350 298 -52 + Partials 241 204 -37 ``` | [Flag](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | Coverage Δ | | |---|---|---| | [config-service](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | `94.79% <96.34%> (+8.12%)` | :arrow_up: | | [relay](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | `84.52% <ø> (-0.69%)` | :arrow_down: | | [server](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | `?` | | | [ws-server](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | `?` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph) | Coverage Δ | | |---|---|---| | [packages/config-service/src/services/index.ts](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047?src=pr&el=tree&filepath=packages%2Fconfig-service%2Fsrc%2Fservices%2Findex.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph#diff-cGFja2FnZXMvY29uZmlnLXNlcnZpY2Uvc3JjL3NlcnZpY2VzL2luZGV4LnRz) | `90.00% <100.00%> (+3.33%)` | :arrow_up: | | [...ckages/config-service/src/services/relayConfigs.ts](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047?src=pr&el=tree&filepath=packages%2Fconfig-service%2Fsrc%2Fservices%2FrelayConfigs.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph#diff-cGFja2FnZXMvY29uZmlnLXNlcnZpY2Uvc3JjL3NlcnZpY2VzL3JlbGF5Q29uZmlncy50cw==) | `100.00% <100.00%> (ø)` | | | [...s/config-service/src/services/validationService.ts](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047?src=pr&el=tree&filepath=packages%2Fconfig-service%2Fsrc%2Fservices%2FvalidationService.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph#diff-cGFja2FnZXMvY29uZmlnLXNlcnZpY2Uvc3JjL3NlcnZpY2VzL3ZhbGlkYXRpb25TZXJ2aWNlLnRz) | `100.00% <100.00%> (ø)` | | | [...kages/config-service/src/services/loggerService.ts](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047?src=pr&el=tree&filepath=packages%2Fconfig-service%2Fsrc%2Fservices%2FloggerService.ts&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph#diff-cGFja2FnZXMvY29uZmlnLXNlcnZpY2Uvc3JjL3NlcnZpY2VzL2xvZ2dlclNlcnZpY2UudHM=) | `57.14% <57.14%> (ø)` | | ... and [20 files with indirect coverage changes](https://app.codecov.io/gh/hashgraph/hedera-json-rpc-relay/pull/3047/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hashgraph)
github-actions[bot] commented 1 day ago

Acceptance Tests

0 tests   0 :heavy_check_mark:  0s :stopwatch: 0 suites  0 :zzz: 0 files    0 :x:

Results for commit 2b4efba7.

natanasow commented 1 day ago

@AlfredoG87 @ebadiere please read the TODOs as well.

sonarcloud[bot] commented 13 hours ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud