What is your suggestion for dynamic config when application is running

Hi, I have an umbrella project which has many configs, hence I want to bind some of them with user help.
I created a setting database in my project and user can change some of them like: google reCAPTCHA client ID or change twitter auth secret code.
I need to change my app’s config when application is running without restarting project and this should be revalued by the user and the database.

For now, I have config like this:

config :ueberauth, Ueberauth.Strategy.Github.OAuth,
   client_id: System.get_env("GITHUB_CLIENT_ID"),
   client_secret: System.get_env("GITHUB_CLIENT_SECRET")

config :ueberauth, Ueberauth.Strategy.Google.OAuth,
   client_id: System.get_env("GOOGLE_CLIENT_ID"),
   client_secret: System.get_env("GOOGLE_CLIENT_SECRET"),
   redirect_uri: System.get_env("GOOGLE_REDIRECT_URI")

Thank you

Ueberauth is a library application. In other word, there is no long running process. The config will be reevaluated anytime it is used. So you will be fine.

I mean, how do we revalue something in config file when a site admin change something in his/her dashboard without changing config files and restarting application?

You need to put the env when you save to the db, and when you load your db at startup.

https://hexdocs.pm/elixir/Application.html#put_env/4

1 Like

I thought this should be used just in testing!!

I wonder, when we must use libraries like GitHub - elixir-toniq/vapor: Runtime configuration system for Elixir?

I am not familiar with this library vapor.

1 Like