Skip to content

OPDATA-6579: Add support for variable env vars#757

Merged
dskloetc merged 4 commits intomainfrom
kloet/variable-placeholder
May 5, 2026
Merged

OPDATA-6579: Add support for variable env vars#757
dskloetc merged 4 commits intomainfrom
kloet/variable-placeholder

Conversation

@dskloetc
Copy link
Copy Markdown
Contributor

@dskloetc dskloetc commented Apr 30, 2026

OPDATA-6579

Context

There are many EAs that rely on environment variables that depend on input parameters.
For example, there might be a network input parameter and if its value is "ethereum" the EA will check environment variable ETHEREUM_RPC_URL but if its value is "base", the EA will check environment variable BASE_RPC_URL.

This is done by checking process.env directly 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 variablePlaceholder field to a setting definition. For example:

export const config = new AdapterConfig({
  NETWORK_RPC_URL: {
    description: 'The URL of the JSON RPC interface of a node of the specified network',
    type: 'string',
    required: true,
    variablePlaceholder: 'NETWORK',
  },
  ...

Then you can replace the placeholder with anything, such as ETHEREUM to get ETHEREUM_RPC_URL and get that value in the EA code with

settings.NETWORK_RPC_URL.get('ethereum')

Changes

  1. Add a new interface Getter and implementation EnvGetter which can now be values in the settings Record.
  2. Add the variablePlaceholder field to the SettingDefinition type.
  3. Change the generic types to support this.
  4. At initialization, find all environment variables matching the definition and store them in a map.
  5. When get is called, find the value in the map or return a default or throw an error depending on configuration.
  6. Reuse the same validation as for fixed settings.
  7. Expand the settings when building the censor list or settings list.

Testing

  1. Many unit tests added.
  2. Used in Demonstrate variable env vars in proof-of-reserves-v2 external-adapters-js#4918
  3. I used these instruction to test these changes with every existing EA. There were no additional compilation errors.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

NPM Publishing labels 🏷️

🟢 This PR has valid version labels and will cause a minor bump.

@dskloetc dskloetc force-pushed the kloet/variable-placeholder branch from 35ee221 to d214819 Compare April 30, 2026 20:43
@dskloetc dskloetc added the minor label Apr 30, 2026
@dskloetc dskloetc marked this pull request as ready for review April 30, 2026 20:52
@dskloetc dskloetc requested a review from a team as a code owner April 30, 2026 20:52
@danwilliams-cll danwilliams-cll requested a review from Copilot May 1, 2026 12:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/EnvGetter and extends config typing to represent variable settings as Getter<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 thread src/config/index.ts Outdated
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_]+)')}$`,
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/config/index.ts
Comment thread src/config/index.ts
@dskloetc dskloetc changed the title Add support for variable env vars OPDATA-6579: Add support for variable env vars May 1, 2026
@dskloetc dskloetc enabled auto-merge (squash) May 5, 2026 14:13
@dskloetc dskloetc merged commit e5d467c into main May 5, 2026
15 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🚀 Successfully created version bump PR: #763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants