OPDATA-6579: Add support for variable env vars#757
Merged
Conversation
Contributor
NPM Publishing labels 🏷️🟢 This PR has valid version labels and will cause a |
35ee221 to
d214819
Compare
There was a problem hiding this comment.
Pull request overview
Adds first-class framework support for “variable” environment variables (e.g., ETHEREUM_RPC_URL, BASE_RPC_URL) via a variablePlaceholder setting definition field and a runtime getter object, so secrets can be censored and settings can be enumerated consistently.
Changes:
- Introduces
Getter/EnvGetterand extends config typing to represent variable settings asGetter<T>. - Updates config initialization/validation and censor list generation to handle variable settings.
- Expands debug/status settings listing to include expanded variable env var instances and adds unit/type tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/config.types.test.ts | Extends compile-time type assertions for variable settings to be typed as Getter<…>. |
| test/config.test.ts | Adds runtime tests for getting/validating variable env vars, prefix handling, and censoring. |
| src/util/settings.ts | Expands settings list output to include variable env var entries (for debug/status). |
| src/config/index.ts | Core implementation: variablePlaceholder, Getter/EnvGetter, env parsing extraction, validation/censor list expansion, and updated settings typings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+540
to
+545
| // If the setting name is 'NETWORK_RPC_URL' and `variablePlaceholder` is | ||
| // 'NETWORK', then `namePattern` will be /([A-Z0-9_]+)_RPC_URL/ to match | ||
| // all relevant environment variables and extract the variable part. | ||
| const namePattern = new RegExp( | ||
| `^${getEnvName(name, prefix).replace(settingsDefinition.variablePlaceholder, '([A-Z0-9_]+)')}$`, | ||
| ) |
mxiao-cll
approved these changes
May 5, 2026
Contributor
|
🚀 Successfully created version bump PR: #763 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
OPDATA-6579
Context
There are many EAs that rely on environment variables that depend on input parameters.
For example, there might be a
networkinput parameter and if its value is"ethereum"the EA will check environment variableETHEREUM_RPC_URLbut if its value is"base", the EA will check environment variableBASE_RPC_URL.This is done by checking
process.envdirectly because this is not supported by the framework.This means that if these variables contain secrets, the framework will not censor them. And the README generation in the EA repo also can't generate documentation for these variables. And in general there is just a lot of duplicate custom code to support these settings.
This PR adds this support in the framework.
It works by adding an extra
variablePlaceholderfield to a setting definition. For example:Then you can replace the placeholder with anything, such as
ETHEREUMto getETHEREUM_RPC_URLand get that value in the EA code withChanges
Getterand implementationEnvGetterwhich can now be values in the settingsRecord.variablePlaceholderfield to theSettingDefinitiontype.getis called, find the value in the map or return a default or throw an error depending on configuration.Testing