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

override configuration keys with environment variables #663

Merged
merged 3 commits into from
Sep 27, 2024
Merged

Conversation

arner
Copy link
Contributor

@arner arner commented Sep 3, 2024

This PR enables the user to override any configuration key with an environment variable. Technically we were supposed to already have this feature (via viper's AutomaticEnv), but it was flaky and unpredictable:

  • Didn't work structs that we got via UnmarshalKey
  • Removed higher level sibling keys when you overrode a low level value!

With this change you can for instance share a 'default' core.yaml, but override node specific data like the database connectionString or the node id. To prevent confusion the environment variables for logging and the vault config have been removed so that they can only be accessed via the same path as other configurations.

The commit also upgrades viper to the latest stable version. That means that if we merge this and upgrade Token SDK, we have to make sure it deals with lowercase map keys properly (like we already do with for instance the P2P field in FSC).

Copy link
Contributor

@adecaro adecaro left a comment

Choose a reason for hiding this comment

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

LGTM, Arne could you document the variables that can be set from the environment?

@arner arner force-pushed the f-env-config branch 2 times, most recently from 86d004b to 1e42187 Compare September 23, 2024 06:55
}

root := p.v.GetStringMap(keys[0])
setDeepValue(root, keys, val)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it makes more sense to pass keys[1:], because keys[0] is not in the map. Just for consistency in your method inputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree that it would be more logical in some sense, but somehow it wasn't easy to change so I left it.

Copy link
Contributor

@alexandrosfilios alexandrosfilios left a comment

Choose a reason for hiding this comment

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

LGTM

@arner arner merged commit 55e2fe5 into main Sep 27, 2024
20 checks passed
@arner arner deleted the f-env-config branch September 27, 2024 09:59
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