Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for ADC credentials at ~/.config/gcloud/application_default_credentials.json #77

Closed
eamontaaffe opened this issue Oct 26, 2020 · 7 comments

Comments

@eamontaaffe
Copy link

eamontaaffe commented Oct 26, 2020

When you run the command gcloud auth application-default-credentials login the credentials are deposited at ~/.config/gcloud/application_default_credentials.json.

This behavior doesn't seem to be documented in the Application Default Credentials documentation. However, many of the google supported libraries seem to identify credentials at this location (such as the python api).

It would be great if this library would also support his credentials location as part of the ADC lookup procedure.

@eamontaaffe
Copy link
Author

goth/lib/goth/config.ex

Lines 131 to 136 in 7eb2068

defp from_creds_file(_config) do
case System.get_env("GOOGLE_APPLICATION_CREDENTIALS") do
nil -> nil
filename -> filename |> File.read!() |> decode_json()
end
end

It looks like we could just update this function slightly.

@eamontaaffe eamontaaffe changed the title Look for ADC credentials at $HOME/.config/gcloud/application_default_credentials.json Look for ADC credentials at ~/.config/gcloud/application_default_credentials.json Oct 26, 2020
@eamontaaffe
Copy link
Author

eamontaaffe commented Oct 26, 2020

Maybe like this. Ill wrap this up into a PR later today.

 defp fetch_creds_filename do
   default_path = Path.expand("~/.config/gcloud/application_default_credentials.json")
   case {System.fetch_env("GOOGLE_APPLICATION_CREDENTIALS"), File.regular?(default_path)} do
     {{:ok, filename}, _} -> {:ok, filename}     
     {_, true} -> {:ok, default_path}
   end 
 end

 defp from_creds_file(_config) do 
   case fetch_creds_filename do
     {:ok, filename} -> filename |> File.read!() |> decode_json()
     {:error, _} -> nil
   end 
 end 

@wojtekmach
Copy link
Collaborator

See #79 (comment).

@bbhoss
Copy link

bbhoss commented Mar 16, 2021

All of the Google auth clients support ADC, is there no way to get Goth to without a full redesign?

@wojtekmach
Copy link
Collaborator

We hope the redesigned API is more flexible so adding ADC support will hopefully not require a 'full redesign'. Feel free to send a PR with ADC support, it could even be the default :source.

@bbhoss
Copy link

bbhoss commented Mar 17, 2021

Apologies, it wasn't clear that the redesign you write about above was already done as and released as an RC. I will give adding ADC support a shot!

@wojtekmach
Copy link
Collaborator

No worries, thanks for looking into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants