Skip to content

Conversation

@vi3k6i5
Copy link
Contributor

@vi3k6i5 vi3k6i5 commented Apr 6, 2022

feat: Add support for db roles list.

@vi3k6i5 vi3k6i5 added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 6, 2022
@vi3k6i5 vi3k6i5 requested review from a team as code owners April 6, 2022 07:17
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Apr 6, 2022
@generated-files-bot
Copy link

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
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/v1/SpannerClientTest.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
  • proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/Session.java
  • proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/SessionOrBuilder.java
  • proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/SpannerProto.java
  • proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/spanner.proto

@vi3k6i5 vi3k6i5 marked this pull request as draft April 6, 2022 07:42
@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Apr 19, 2022
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.

This looks generally good to me, with a couple of small nits. The biggest issue here might be the documentation / explanation of what this is and how customers should use it. We are calling it something like defaultCreatorRole, but I don't think that makes it clear to customers what it does and why they should use it.

final String databaseName = getDatabaseName(instanceId, databaseId);
final Options listOptions = Options.fromListOptions(options);
Preconditions.checkArgument(
!listOptions.hasFilter(), "Filter option is not supported by listDatabasesRoles");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume that this is a backend limitation (albeit one that I find a little strange...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, As per the discussions with the team they wont be providing a filter option, I will remove it from the code.

if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I would prefer equals over !=, even when we know that the default implementation of equals just uses ==

Suggested change
if (o == null || getClass() != o.getClass()) {
if (o == null || !getClass().equals(o.getClass())) {

"Sets the priority for all RPC invocations from this connection (HIGH/MEDIUM/LOW). The default is HIGH."),
ConnectionProperty.createStringProperty(
DIALECT_PROPERTY_NAME, "Sets the dialect to use for this connection."))));
DIALECT_PROPERTY_NAME, "Sets the dialect to use for this connection."),
Copy link
Collaborator

Choose a reason for hiding this comment

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

(Not related to this PR, but more a general note): We should remove this property as we don't need it and don't use it.

DIALECT_PROPERTY_NAME, "Sets the dialect to use for this connection."),
ConnectionProperty.createStringProperty(
CREATOR_ROLE_PROPERTY_NAME,
"Sets the default creator role to use for this 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 anyone is going to understand what 'the default creator role` is. We need a better description of what this property is and why anyone might want to use this.

private final String name;

public Builder(String name) {
this.name = name;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We seem to assume that the name will always be non-null and not empty, so we should check for that here.

Suggested change
this.name = name;
this.name = Preconditions.checkNotNullOrEmpty(name);

try (ResultSet rs =
dbClient.singleUse().executeQuery(Statement.of("SELECT COUNT(*) as cnt FROM T"))) {
rs.next();
fail("Missing expected permission denied to dbRoleParent Exception");
Copy link
Collaborator

Choose a reason for hiding this comment

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

use assertThrows(...) instead of fail(..).

try (ResultSet rs =
dbClient.singleUse().executeQuery(Statement.of("SELECT COUNT(*) as cnt FROM T"))) {
rs.next();
fail("Missing expected permission denied to dbRoleOrphan Exception");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here also: use assertThrows(SpannerException.class, rs::next)

instanceId, databaseId, ImmutableList.of(createTableT, createRoleOrphan))
.get(5, TimeUnit.MINUTES);

// Connect to db with dbRoleParent.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
// Connect to db with dbRoleParent.
// Connect to db with dbRoleOrphan.

}

@Test
public void orphanRolePermissions() throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What exactly is this test case testing? That a role that has not received any specific permissions has no permissions? I think it would be good to add a comment to explain what it is that we are verifying here.


// Required. The database whose roles should be listed.
// Values are of the form
// `projects/<project>/instances/<instance>/databases/<database>/databaseRoles`.
Copy link

Choose a reason for hiding this comment

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

Should there really be a "/databaseRoles" suffix there?

@rahul2393
Copy link
Contributor

Rebase to #1916

@rahul2393 rahul2393 closed this Jun 13, 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. do not merge Indicates a pull request not ready for merge, due to either quality or timing. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants