peburrows / goth

Elixir package for Oauth authentication via Google Cloud APIs
http://hexdocs.pm/goth
MIT License
284 stars 108 forks source link

Jason cannot decode json file #67

Closed ghost closed 3 years ago

ghost commented 4 years ago

I have an issue regarding decoding my json file.

config :goth, json: "config/gcs.json" |> Path.expand() |> File.read!()

Screen Shot 2019-11-25 at 8 03 23 PM

is it possible to use Jason.encode_to_iodata() for the the keys to be decoded properly?

peburrows commented 4 years ago

I'm confused. Is your credentials file valid json?

glennr commented 4 years ago

I was also tripped up by this error.

I think it is a misunderstanding of this configuration option

config :goth,
  json: {:system, "GCP_CREDENTIALS"}

Where I specified GCP_CREDENTIALS as a filename, and not a JSON string.

So either you need to get your full JSON into the environment var e.g.

export GCP_CREDENTIALS=`cat ~/.gcp/my-creds.json`

Or if like me you prefer to use a filename, change your config to something like:

config :goth,
  json: System.get_env("GCP_CREDENTIALS_FILE") |> File.read!
peburrows commented 4 years ago

Or if like me you prefer to use a filename, change your config to something like:

config :goth, json: System.get_env("GCP_CREDENTIALS_FILE") |> File.read!

One thing I would caution against related to this particular option is that this config is evaluated at compile time, not runtime, so reading an ENV var within the config file itself will read the var at compile time (which may not actually be what you'd want).

wojtekmach commented 3 years ago

In #83 we're introducing a new API where you'd explicitly pass the configuration: if you already have a map, you pass it as is; if you have a filename, you need to read it and decode it; etc. I believe we can close this then.