29
29
import com .google .cloud .spanner .spi .v1 .SpannerRpc .Paginated ;
30
30
import com .google .common .base .MoreObjects ;
31
31
import com .google .common .base .Preconditions ;
32
+ import com .google .iam .v1 .GetPolicyOptions ;
32
33
import com .google .longrunning .Operation ;
33
34
import com .google .protobuf .Empty ;
34
35
import com .google .protobuf .FieldMask ;
@@ -290,6 +291,43 @@ public Operation fromProto(Operation proto) {
290
291
return pageFetcher .getNextPage ();
291
292
}
292
293
294
+ @ Override
295
+ public final Page <DatabaseRole > listDatabaseRoles (
296
+ String instanceId , String databaseId , ListOption ... options ) {
297
+ final String databaseName = getDatabaseName (instanceId , databaseId );
298
+ final Options listOptions = Options .fromListOptions (options );
299
+ final int pageSize = listOptions .hasPageSize () ? listOptions .pageSize () : 0 ;
300
+
301
+ PageFetcher <DatabaseRole , com .google .spanner .admin .database .v1 .DatabaseRole > pageFetcher =
302
+ new PageFetcher <DatabaseRole , com .google .spanner .admin .database .v1 .DatabaseRole >() {
303
+ @ Override
304
+ public Paginated <com .google .spanner .admin .database .v1 .DatabaseRole > getNextPage (
305
+ String nextPageToken ) {
306
+ try {
307
+ return rpc .listDatabaseRoles (databaseName , pageSize , nextPageToken );
308
+ } catch (SpannerException e ) {
309
+ throw SpannerExceptionFactory .newSpannerException (
310
+ e .getErrorCode (),
311
+ String .format (
312
+ "Failed to list the databases roles of %s with pageToken %s: %s" ,
313
+ databaseName ,
314
+ MoreObjects .firstNonNull (nextPageToken , "<null>" ),
315
+ e .getMessage ()),
316
+ e );
317
+ }
318
+ }
319
+
320
+ @ Override
321
+ public DatabaseRole fromProto (com .google .spanner .admin .database .v1 .DatabaseRole proto ) {
322
+ return DatabaseRole .fromProto (proto );
323
+ }
324
+ };
325
+ if (listOptions .hasPageToken ()) {
326
+ pageFetcher .setNextPageToken (listOptions .pageToken ());
327
+ }
328
+ return pageFetcher .getNextPage ();
329
+ }
330
+
293
331
@ Override
294
332
public Page <Backup > listBackups (String instanceId , ListOption ... options ) {
295
333
final String instanceName = getInstanceName (instanceId );
@@ -463,9 +501,13 @@ public Operation getOperation(String name) {
463
501
}
464
502
465
503
@ Override
466
- public Policy getDatabaseIAMPolicy (String instanceId , String databaseId ) {
504
+ public Policy getDatabaseIAMPolicy (String instanceId , String databaseId , int version ) {
467
505
final String databaseName = DatabaseId .of (projectId , instanceId , databaseId ).getName ();
468
- return policyMarshaller .fromPb (rpc .getDatabaseAdminIAMPolicy (databaseName ));
506
+ GetPolicyOptions options = null ;
507
+ if (version > 0 ) {
508
+ options = GetPolicyOptions .newBuilder ().setRequestedPolicyVersion (version ).build ();
509
+ }
510
+ return policyMarshaller .fromPb (rpc .getDatabaseAdminIAMPolicy (databaseName , options ));
469
511
}
470
512
471
513
@ Override
@@ -487,7 +529,7 @@ public Iterable<String> testDatabaseIAMPermissions(
487
529
@ Override
488
530
public Policy getBackupIAMPolicy (String instanceId , String backupId ) {
489
531
final String databaseName = BackupId .of (projectId , instanceId , backupId ).getName ();
490
- return policyMarshaller .fromPb (rpc .getDatabaseAdminIAMPolicy (databaseName ));
532
+ return policyMarshaller .fromPb (rpc .getDatabaseAdminIAMPolicy (databaseName , null ));
491
533
}
492
534
493
535
@ Override
0 commit comments