I cant find how to inject the google Json credential file into an ENV variable for production. The dependency I use is called goth for elixir, and I am supposed to feed it with those credentials on app startup.
For the json, I encoded Google's file with Poison.encode!() and use it as a text in my ENV variables.
in my dev config file : it works
config :goth, json: {:system, "GCP_CREDENTIALS"}
in my prod config file : it doens't work and I keep getting a syntax error at the beginning of the json
config :goth, json: {:system, '${GCP_CREDENTIALS}'}
Any suggestion or anybody who made this working and could share about his experience ?
Looking at the goth README it looks like you have a couple options.
config :goth,
json: "path/to/google/json/creds.json" |> File.read!
config :goth, config_module: MyConfigMod
and then
defmodule MyConfigMod do
use Goth.Config
def init(config) do
{:ok, Keyword.put(config, :json, System.get_env("MY_GCP_JSON_CREDENTIALS"))}
end
end
I could be wrong about the "${GCP_CREDENTIALS}" in the config, but the only place I have seen "${...}" used before is in distillery when you use REPLACE_OS_VARS=true
. If you are indeed using distillery, then you do not need the {:system, "${GCP_CREDENTIALS}"} tuple, you can just put config :goth, json: "${GCP_CREDENTIALS}"
where the GCP_CREDENTIALS
env var contains the contents of the credentials json file.
Source of examples: https://github.com/peburrows/goth#installation
Distillery docs: https://hexdocs.pm/distillery/runtime-configuration.html#vm-args