drogon icon indicating copy to clipboard operation
drogon copied to clipboard

Get env variable from config.json and model.json

Open Assowavesss opened this issue 1 year ago • 2 comments

Here is a good feature to add ! When building microservice architecture, we often need to build images from dockerfiles and use kubernetes to configure the architecture of services. For host server, host clients and database clients(postgres or redis), the configuration often depends on env variable set with kubernetes and passed to containers.

The standard library can access env variable using std::getenv(char* path), if add it to the method loadConfigFile to get all ${ENV_EXAMPLE} by the corresponded value. for example we can have { host: ${HOST_SERVER}, port: ${PORT} } in the config.json and when call loadConfigFlie("config.json"), load ${HOST_SERVER} by std::getenv("HOST_SERVER") and load ${PORT} by std::getenv("PORT"), the config file should not be modified.

Assowavesss avatar Dec 26 '23 04:12 Assowavesss

Thanks for the feature request!

I think this feature would then also need some kind of flag, or we would have to introduce a second config loading mechanism to keep backwards compatibility, but we would definitely need to distinguish between the old, default behavior, and the replacement behavior, introducing another configuration layer.

I just wonder what the use case here is to load environment variables over the configuration file / inject environment variables into the configuration file? Currently I fail to understand in which environments this would be beneficial, or let’s say easier to implement?

rbugajewski avatar Dec 29 '23 08:12 rbugajewski

Thanks for the feature request!

I think this feature would then also need some kind of flag, or we would have to introduce a second config loading mechanism to keep backwards compatibility, but we would definitely need to distinguish between the old, default behavior, and the replacement behavior, introducing another configuration layer.

I just wonder what the use case here is to load environment variables over the configuration file / inject environment variables into the configuration file? Currently I fail to understand in which environments this would be beneficial, or let’s say easier to implement?

The use case is to load env variable from configuration file, it’s a really important features, when working with dockerfiles and kubernetes, we often need to work with env variable (POSTGRES_PASSWORD, POSTGRES_CLIENT, HOST_SERVICE etc.) especially when building micro services architectures. Keep in mind that there is no env variable injection or creation of env variable. The config file still the same after execution, Is just getting env variables from file using std::getenv(VAR).

Assowavesss avatar Jan 03 '24 22:01 Assowavesss