Skip to content

Async API to determine project ID #715

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

Merged
merged 2 commits into from
Dec 11, 2019
Merged

Async API to determine project ID #715

merged 2 commits into from
Dec 11, 2019

Conversation

hiranya911
Copy link
Contributor

Currently the SDK uses the following synchronous procedure to determine the project ID:

  1. Get project ID from AppOptions.
  2. Get project ID from the service account credentials.
  3. Get project ID from the environment variables.

New GCP runtimes like Cloud Run no longer expose the project ID as environment variables. Therefore the SDK does not work in these environments if the project ID is not specified via AppOptions or service account credentials (see b/143090254).

admin.initializeApp();
admin.auth().verifyIdToken(token); // does not work in Cloud Run

To support this we need to get the project ID from the local metadata server. This is an async operation, and therefore we need to turn our project ID discovery logic into an async method.

With this PR I'm starting to refactor the SDK so that it can find the project ID via an async method call. I've wrapped the existing util.getProjectId() method into a new util.findProjectId() method that returns a Promise. I'm also updating the ID token verification logic to use the new async method.

I will refactor the rest of the SDK to use the new async method in future PRs. Finally, we will modify the credentials module to discover the project ID by making a call to the local metadata server.

Copy link
Member

@lahirumaramba lahirumaramba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lahirumaramba lahirumaramba removed their assignment Dec 10, 2019
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

Successfully merging this pull request may close these issues.

3 participants