Skip to content

Async API to determine project ID#715

Merged
hiranya911 merged 2 commits intomasterfrom
hkj-async-projectid
Dec 11, 2019
Merged

Async API to determine project ID#715
hiranya911 merged 2 commits intomasterfrom
hkj-async-projectid

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

Comments