-
Notifications
You must be signed in to change notification settings - Fork 138
feat: Secure Parameters support for the Java Client #4316
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @aseering, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Java Spanner client library by adding robust support for Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces support for ClientContext in the Spanner Java client, enabling the use of secure parameters. The changes add a clientContext option at both the global SpannerOptions level and the per-request Options level, with logic to merge them. My review identifies a potential issue where the default ClientContext is not being applied to CommitRequests, which is inconsistent with other request types. I've also included a couple of suggestions to refactor duplicated and verbose code for better maintainability.
I am having trouble creating individual review comments. Click here to see my feedback.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java (467-470)
The RequestOptions for the CommitRequest are built from per-transaction options but do not appear to merge with the default ClientContext that can be configured on SpannerOptions. This is inconsistent with how BeginTransactionRequest and ExecuteSqlRequest are handled in this PR. This could lead to the ClientContext being unexpectedly missing from commit requests when a default is expected to be applied.
Consider applying the same merge logic used in SessionImpl.beginTransactionAsync here to ensure consistent behavior.
RequestOptions requestOptions = options.toRequestOptionsProto(true);
RequestOptions.ClientContext defaultClientContext =
session.getSpanner().getOptions().getClientContext();
if (defaultClientContext != null) {
RequestOptions.ClientContext.Builder clientContextBuilder =
defaultClientContext.toBuilder();
if (requestOptions.hasClientContext()) {
clientContextBuilder.mergeFrom(requestOptions.getClientContext());
}
requestOptions =
requestOptions.toBuilder().setClientContext(clientContextBuilder.build()).build();
}
if (!requestOptions.equals(RequestOptions.getDefaultInstance())) {
requestBuilder.setRequestOptions(requestOptions);
}google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java (488-497)
The logic for merging the default ClientContext from SpannerOptions with the request-specific ClientContext is also present in AbstractReadContext.buildRequestOptions. To improve maintainability and reduce code duplication, consider extracting this logic into a shared helper method.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java (2091-2098)
The logic for appending the clientContext as an UpdateOption is a bit verbose. For consistency with mergeQueryRequestOptions, which uses an appendQueryOption helper, consider creating and using a similar helper method like appendUpdateOption.
if (clientContext != null) {
options = appendUpdateOption(options, Options.clientContext(clientContext));
}6081b9e to
dccce56
Compare
This change adds support for ClientContext in Options and ensures it is propagated to ExecuteSql, Read, Commit, and BeginTransaction requests. It aligns with go/spanner-client-scoped-session-state design. - Added RequestOptions.ClientContext to Options. - Refactored request option building to Options.toRequestOptionsProto. - Updated AbstractReadContext, TransactionRunnerImpl, and SessionImpl to use the shared logic. - Added tests.
4652157 to
160e1db
Compare
This change adds support for setting and propagating ClientContext in the Spanner Connection API. ClientContext allows propagating client-scoped session state (e.g., secure parameters) to Spanner RPCs. - Added setClientContext/getClientContext to Connection interface and implementation. - Implemented state propagation from Connection to UnitOfWork and its implementations (ReadWriteTransaction, SingleUseTransaction). - Fixed accidental import removal in OptionsTest.java. - Fixed TransactionRunnerImplTest to correctly verify ClientContext propagation. - Added ClientContextMockServerTest for end-to-end verification.
160e1db to
4556e81
Compare
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> ☕️
If you write sample code, please follow the samples format.