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

Dynamic config definitions and getter #788

Conversation

Assem-Hafez
Copy link
Contributor

@Assem-Hafez Assem-Hafez commented Jan 14, 2025

Summary

Creating the definition language for the app dynamic configurations.

Details

Dynamic config definition

It supports multiple ways of defining the source of the configuration value. The value source can be:

  • Environment variable with a default value
  • sync resolver, which is a way to compute the configuration from custom sources.
  • Async resolver, which helps fetching the configuration value from remote sources.
    We can change the value source without affecting the way the value is consumed through the code.

Loading configurations

On the server start (using instrumentation hooks) configurations values/resolvers are transformed with getTransformedConfigs and loaded into memory into a global ref

Consuming values

getConfigValue can be used to access the configurations securely on server and it doesn't leak any sensitive data if used by mistake on client.

Global Configs ref

To secure the configuration values, configurations are loaded and shared within the server memory. This is done to break the imports flow between the loaders of the config and the consumers of it. With that all definitions & resolvers stays at the server while allowing to use the module safely on modules that works both on server/client.

server only module

Use server only to make sure definitions and resolvers are never imported to client code

COMPUTED: ConfigSyncResolverDefinition<[string], [string]>;
DYNAMIC: ConfigAsyncResolverDefinition<undefined, number>;
} = {
CADENCE_WEB_PORT: {
Copy link
Member

Choose a reason for hiding this comment

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

Are we going to update the files in src/config to use these config values? Or will those continue to use the env variables directly

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly, any information that can be set dynamic will be removed from config and added to dynamic config. Anything that is static will remain as is for better typescript support

@Assem-Uber Assem-Uber merged commit 3c02ca8 into cadence-workflow:release/4.0.0 Jan 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants