fix: set projectId to a default value in emulator case#1345
fix: set projectId to a default value in emulator case#1345dmivankov wants to merge 5 commits intogoogleapis:masterfrom
Conversation
Spanner client wants to have a projectId option set, by default it also tries to pick it up from [lots of places](https://github.com/googleapis/java-core/blob/375983090b3700b3fb6a1953626db7efca49cc51/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java#L372) For emulator case none of those may be present as it could be that neither gcloud nor default application credentials are configured, but emulator is accessible nevertheless. Set default project id in SpannerOptions, value doesn't matter so much as emulator would be happy with any value it seems. Note that alternatively it could be improved in base ServiceOptions, but not sure about assumptions there.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java
Outdated
Show resolved
Hide resolved
…annerOptions.java
There was a problem hiding this comment.
Hi @dmivankov Thanks for your contribution. I think this is a good idea. I've left a couple of textual suggestions.
Also, there seems to be a compile error. Would you mind take a look at that?
Also, would you be able to add a test that verifies that it will actually use this, and that it does not fail before it gets this far? If not, then that's OK as well. I can take a look at a later moment. It might be quite tricky as such a test would depend on a lot of different environment variables.
@thiagotnunes Do you have any additional comments on this?
google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Knut Olav Løite <koloite@gmail.com>
Co-authored-by: Knut Olav Løite <koloite@gmail.com>
google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java
Outdated
Show resolved
Hide resolved
…annerOptions.java
| this.setCredentials(NoCredentials.getInstance()); | ||
| // Default project id resolution might fail, but the emulator accepts any | ||
| // project id, so we can safely use a dummy id. | ||
| if (this.getProjectId() == null) { |
There was a problem hiding this comment.
oops, may need more work as there's no such getter in ServiceOptions builder and the field is private https://github.com/googleapis/java-core/blob/375983090b3700b3fb6a1953626db7efca49cc51/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java#L127
Use a dummy emulator-project when no default project is set for the environment and the SPANNER_EMULATOR_HOST environment variable has been set. Replaces #1345
|
@dmivankov I've created a new PR that uses a slightly different approach to achieve the same goal: #1363 |
Use a dummy emulator-project when no default project is set for the environment and the SPANNER_EMULATOR_HOST environment variable has been set. Replaces #1345
|
Closed in favour of #1363 |
🤖 I have created a release \*beep\* \*boop\* --- ## [6.12.0](https://www.github.com/googleapis/java-spanner/compare/v6.11.1...v6.12.0) (2021-08-24) ### Features * add support for JSON data type ([#872](https://www.github.com/googleapis/java-spanner/issues/872)) ([d7ff940](https://www.github.com/googleapis/java-spanner/commit/d7ff9409e974602dc9b18f82d6dbd11d96c956bf)) * use dummy emulator-project when no project is set ([#1363](https://www.github.com/googleapis/java-spanner/issues/1363)) ([673855e](https://www.github.com/googleapis/java-spanner/commit/673855eea8c244457ad4c8ac5abe3ad3a0a0cdde)), closes [#1345](https://www.github.com/googleapis/java-spanner/issues/1345) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Spanner client wants to have a projectId option set, by default it also tries to pick it up from lots of places
For emulator case none of those may be present as it could be that neither gcloud nor default application credentials are configured, but emulator is accessible nevertheless.
Set default project id in SpannerOptions, value doesn't matter so much as emulator would be happy with any value it seems.
Note that alternatively it could be improved in base ServiceOptions, but not sure about assumptions there.
failure example in case where emulatorHost is set without projectId
Note that in non-emulator case one usually doesn't need to set projectId as it could be extracted from credentials
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> ☕️