Max
Max

Reputation: 179

Configure system variables in phoenixweb-framework

How do I use System.get_env("ACCESS_KEY_ID")

I have create an config/application.yml file with the content

dev:
  access_key_id: ABCDEFGHIJKLMN

I have tried to use figaro_elixir and it works as perfect when I test it from the terminal

When I run

$ MIX_ENV=dev iex -S mix
iex(1)> System.get_env("ACCESS_KEY_ID")
"ABCDEFGHIJKLMN"
iex(2)>

but in my config/dev.exc

I got nothing

IO.puts System.get_env("ACCESS_KEY_ID") 

Any suggestions? I would like not to expose all my secret credentials.

Upvotes: 2

Views: 1073

Answers (2)

Max
Max

Reputation: 179

I finaly got it System.get_env("ACCESS_KEY_ID") is a part of my system i.e. my computer. I have to put there myself. for someone on #slack pointed me to

https://github.com/avdi/dotenv_elixir

Upvotes: 0

José Valim
José Valim

Reputation: 51369

There is no need for figaro_elixir. Just directly access the environment in your configuration files:

# config/dev.exs
config :my_app, :access_key_id, System.get_env("SUPER_SECRET")

And then in your application code: Application.get_env(:my_app, :access_key_id). You can also define the configuration above to be simply a string in development and use the environment variable only in config/prod.exs.

Another alternative is to explicitly put all secrets in the config/prod.secrets.exs file and ensure it is not in your version control but only in your deployment machines.

EDIT: There is no need for a .yml based configuration system in Elixir. It is unnecessary complexity. You can do everything and more by using Elixir's configuration system.

Upvotes: 5

Related Questions