Skip to content
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

feat: add support for db roles list #1916

Merged
merged 7 commits into from Aug 22, 2022
Merged

Conversation

rahul2393
Copy link
Contributor

  • Added support of passing databaseRole in cloud-spanner sessions.

Old PR: #1807

@rahul2393 rahul2393 requested review from a team as code owners June 13, 2022 05:12
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/java-spanner API. labels Jun 13, 2022
@generated-files-bot
Copy link

generated-files-bot bot commented Jun 13, 2022

Warning: This pull request is touching the following templated files:

  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClient.java
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminSettings.java
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/gapic_metadata.json
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStub.java
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/DatabaseAdminStubSettings.java
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/admin/database/v1/stub/GrpcDatabaseAdminStub.java
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/DatabaseAdminClientTest.java
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/database/v1/MockDatabaseAdminImpl.java
  • grpc-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/DatabaseAdminGrpc.java
  • proto-google-cloud-spanner-admin-database-v1/src/main/java/com/google/spanner/admin/database/v1/SpannerDatabaseAdminProto.java
  • proto-google-cloud-spanner-admin-database-v1/src/main/proto/google/spanner/admin/database/v1/spanner_database_admin.proto

import com.google.common.base.Preconditions;
import java.util.Objects;

/** Represents a restore operation of a Cloud Spanner backup. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: copy-paste

@@ -830,6 +834,12 @@ public Builder setSessionPoolOption(SessionPoolOptions sessionPoolOptions) {
return this;
}

/** Sets the database role that should be used by this instance. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a more elaborate Javadoc on what this means, as most users won't understand this automatically. I would suggest something like:

Suggested change
/** Sets the database role that should be used by this instance. */
/**
* Sets the database role that should be used for connections that are created by this instance.
* The database role that is used determines the access permissions that a connection has. This
* can for example be used to create connections that are only permitted to access certain tables.
*/

@@ -213,8 +214,8 @@ public String[] getValidValues() {
public static final String LENIENT_PROPERTY_NAME = "lenient";
/** Name of the 'rpcPriority' connection property. */
public static final String RPC_PRIORITY_NAME = "rpcPriority";
/** Dialect to use for a connection. */
private static final String DIALECT_PROPERTY_NAME = "dialect";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should remove this, as it is no longer needed, BUT:

  1. We should consider doing so in a separate PR. It is not related to this change.
  2. We should do it in a non-breaking way. Anyone who currently has dialect=... in their connection string will get an error after this change. We should therefore silently ignore it if we encounter dialect=... in a connection string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the change to remove Dialect, will be done in another PR

@@ -959,6 +969,11 @@ public TransportChannelProvider getChannelProvider() {
}
}

/** The creator role to use for the connection. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think users will understand what 'creator role' means. This seems like an internal name (I (think I) understand that it means the role that is used to create a session, but that is not clear to a user.)

I would suggest: The database role that is used for this connection. Assigning a role to a connection can be used to for example restrict the access of a connection to a specific set of tables.

@@ -50,6 +50,8 @@ public class RemoteSpannerHelper {
private final InstanceId instanceId;
private static final AtomicInteger dbSeq = new AtomicInteger();
private static final int dbPrefix = new Random().nextInt(Integer.MAX_VALUE);
private static int dbRoleSeq;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the probability is low that it goes wrong, it would be better to use an AtomicInteger for this, as our integration tests can run in parallel.

when(spannerOptions.getSessionLabels()).thenReturn(labels);
when(spannerOptions.getDatabaseRole()).thenReturn(databaseRole);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation seems off here

@@ -143,13 +145,16 @@ public void batchCreateAndCloseSessions() {
final String sessionName = dbName + "/sessions/s%d";
final Map<String, String> labels = new HashMap<>();
labels.put("env", "dev");
String databaseRole = new String("role");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation seems to be off here (and also elsewhere in this class). Maybe run code formatter again?

@@ -76,7 +76,7 @@ public void defaultBuilder() {
// id.
SpannerOptions options = SpannerOptions.newBuilder().setProjectId("test-project").build();
if (Strings.isNullOrEmpty(System.getenv("SPANNER_EMULATOR_HOST"))) {
assertThat(options.getHost()).isEqualTo("https://spanner.googleapis.com");
assertThat(options.getHost()).isEqualTo("https://staging-wrenchworks.sandbox.googleapis.com/");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove before merging

@snippet-bot
Copy link

snippet-bot bot commented Jul 19, 2022

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Collaborator

@olavloite olavloite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks generally good to me, except we need some Javadoc for the version argument, as it is not self-explanatory.

@@ -145,7 +145,7 @@ public Page<Operation> listDatabaseOperations() {

/** Returns the IAM {@link Policy} for this database. */
public Policy getIAMPolicy() {
return dbClient.getDatabaseIAMPolicy(instance(), database());
return dbClient.getDatabaseIAMPolicy(instance(), database(), 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the 1 here?

EDIT: Apparently this is a version number. Should we add the version as an argument to the getIAMPolicy method?

@@ -492,7 +495,7 @@ OperationFuture<Void, UpdateDatabaseDdlMetadata> updateDatabaseDdl(
Operation getOperation(String name);

/** Returns the IAM policy for the given database. */
Policy getDatabaseIAMPolicy(String instanceId, String databaseId);
Policy getDatabaseIAMPolicy(String instanceId, String databaseId, int version);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version argument needs some Javadoc. What does it do and when/why should I use it?

@rahul2393 rahul2393 added the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 18, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 18, 2022
@rahul2393 rahul2393 merged commit 8034c67 into googleapis:main Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants