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

google: Provide method to retrieve project ID configured on gcloud #241

Open
ahmetb opened this issue Jul 25, 2017 · 6 comments
Open

google: Provide method to retrieve project ID configured on gcloud #241

ahmetb opened this issue Jul 25, 2017 · 6 comments

Comments

@ahmetb
Copy link
Contributor

ahmetb commented Jul 25, 2017

(moved from googleapis/google-cloud-go#707)

It looks like Go client libraries do not provide a method do to this. I've been shelling out to gcloud myself but not sure what's the way guaranteed to work. It would be great if this library can provide a method that will keep working.

On a side note, when I use the FindCredentials() method on my dev machine, which has ADC enabled with gcloud auth application-default login, the ProjectID field of DefaultCredentials comes as empty string.

Looks like other Google Cloud libraries are using the following commands:

  • gcloud config config-helper --format json
  • gcloud -q config list core/project --format=json

Examples:

@rakyll
Copy link
Contributor

rakyll commented Jul 25, 2017

/cc @zombiezen

@vsimon
Copy link

vsimon commented Dec 15, 2018

Friendly bump, also seeing when we use FindDefaultCredentials() method on a local dev machine, the ProjectID field of DefaultCredentials comes as empty string.

@zombiezen
Copy link
Contributor

The behavior of FindDefaultCredentials is working as intended here: the ProjectID field of Credentials is the project ID of the role. User-level credentials do not have an associated project.

Shelling out to gcloud in the manner described above doesn't seem unreasonable to ask someone to do to obtain the project ID information from gcloud. Typically project ID is passed along to an application via environment variable or command-line flag, not obtained from the gcloud CLI.

/cc @deKlerk

@Sytten
Copy link

Sytten commented Oct 14, 2020

Bump, I also think there should be a way to retrieve the project ID in local like you can with other languages. This is quite annoying for some instances like secrets that require the project ID to be set.

@pwen
Copy link

pwen commented Jan 26, 2021

Bump as well.

@arikkfir
Copy link

I think it's not unreasonable to ask that "Application Default Credentials" would include a project ID. Almost every GCP API requires (and almost every resource is associated with) a project, so having a default project seems to fit the bill here.

Once we agree on that, I think it becomes a no-brainer that the application default credentials Go SDK API would provide that project ID as well.

I think it's also self-evident that the FindDefaultCredentials method returns a Credentials object, which includes a ProjectID - sounds like this was in someone's mind all along anyway, and even if not - sounds to me (and I'm sure to almost every other GCP developer out there) to be a reasonable choice.

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

No branches or pull requests

7 participants