Async API to determine project ID #715
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the SDK uses the following synchronous procedure to determine the project ID:
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).
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 newutil.findProjectId()
method that returns aPromise
. 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.