-
Notifications
You must be signed in to change notification settings - Fork 150
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
fix: Set emulator credentials on rest fallback #1812
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -597,6 +597,25 @@ export class Firestore implements firestore.Firestore { | |
// also set the `protocol` option for GAX fallback to force http | ||
if (useFallback) { | ||
settings.protocol = 'http'; | ||
|
||
// If the emulator mode is enabled, we set emulator credentials | ||
// to prevent the gRPC-fallback client from trying to obtain | ||
// service account credentials from the environment. | ||
if (process.env.FIRESTORE_EMULATOR_HOST) { | ||
const emulatorCredentials = { | ||
access_token: 'owner', | ||
}; | ||
const emulatorClient = | ||
// eslint-disable-next-line node/no-extraneous-require | ||
new (require('google-auth-library').OAuth2Client)(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we added 'google-auth-library' to nodejs-firestore dependencies, would that also resolve the issue? Or am I missing some other context? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, adding
|
||
emulatorClient.setCredentials(emulatorCredentials); | ||
emulatorClient.projectId = | ||
settings.projectId ?? process.env.GCLOUD_PROJECT; | ||
const emulatorAuth = new (require('google-gax').GoogleAuth)({ | ||
authClient: emulatorClient, | ||
}); | ||
settings.auth = emulatorAuth; | ||
} | ||
} | ||
|
||
client = new module.exports.v1(settings, gax); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Root cause for failing tests. The emulatorClient (cached credentials) needs to specify the project ID. If not specified here and not specified in the firestore settings, then the project ID will not be available, causing request the Firestore instance to behave incorrectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see! How does the system tests obtain the project id? We can use the firestore settings and
GCLOUD_PROJECT
env var here, if that makes sense.WDYT?