-
Notifications
You must be signed in to change notification settings - Fork 76
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
Allow changing environment variable per field #368
Comments
I now see why things are the way they are. I still think this would be great, but I doubt it's feasible |
Can you give me an example of what you mean? |
I have a simple configuration object like this: data class Config(val someDuration: Duration) In order to load that config value from the env var someDuration: ${DURATION} I know this is a bit of a constructed example, but imagine more complex config object with many nested objects. what I'd like to do what be something like: data class Config(@FromEnv("DURATION") val someDuration: Duration) Having the config file for this seems redundant, because I'm only ever using it as a proxy for the env values. I guess my use-case is not really a good fit for hoplite. |
Theres an EnvPropertySource you can register that provides values directly from env vars like you want. There's no need then to have the file mappings. |
Yes, but with that I don't have control over the specific environment variables to be used. |
So what about an EnvVarMappedPropertySource that allows you to specify a mapping between env names and config names ? |
Yes, that sounds like what I'm looking for.
I've seen that, but that only renames a local property name, right? So if I have: data class SomeOptions(@ConfigAlias("ENV_VAL") val string: String)
data class Config(val options: SomeOptions) that the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The stale bot might be the most annoying thing on github... |
If you are migrating from Spring,then #414 should solve your problem automatically. |
@rocketraman nope, we haven't used spring's automatic env names at all, all our environment variables are custom named. |
@pschichtel Ok yeah I understand now -- the problem is that hoplite does not have at the moment any notion of a "global" config value accessible at any level in the configuration node tree. @sksamuel what do you think about nodes having a reference back to the root node? That way the |
I'm not sure how that would look like in practice |
From the documentation it seems the the ENV property source only supports loading values from variables that encode the path of the property in its object tree.
I have an existing application that uses a lot of environment variables and I want to migrate to hoplite (from spring) and I'd prefer not to change all of the variables.
One workaround I see would be to use a preprocessor to replace ENV vars in properties that are defined in a yaml file.
The text was updated successfully, but these errors were encountered: