Skip to content

Commit 8041d21

Browse files
committed
Merge branch 'googleapis:main' into cmmr-samples
2 parents b699b55 + cef4e0a commit 8041d21

File tree

20 files changed

+102
-11
lines changed

20 files changed

+102
-11
lines changed

.github/.OwlBot.lock.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest
16-
digest: sha256:6566dc8226f20993af18e5a4e7a2b1ba85a292b02dedb6a1634cf10e1b418fa5
16+
digest: sha256:f14e3fefe8e361e85752bd9890c8e56f2fe25f1e89cbb9597e4e3c7a429203a3
17+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If you are using Maven without BOM, add this to your dependencies:
4141
<dependency>
4242
<groupId>com.google.cloud</groupId>
4343
<artifactId>google-cloud-spanner</artifactId>
44-
<version>6.30.1</version>
44+
<version>6.30.2</version>
4545
</dependency>
4646

4747
```

google-cloud-spanner/clirr-ignored-differences.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,14 @@
192192
<className>com/google/cloud/spanner/StructReader</className>
193193
<method>java.util.List getPgJsonbList(java.lang.String)</method>
194194
</difference>
195+
<difference>
196+
<differenceType>7012</differenceType>
197+
<className>com/google/cloud/spanner/BatchClient</className>
198+
<method>java.lang.String getDatabaseRole()</method>
199+
</difference>
200+
<difference>
201+
<differenceType>7012</differenceType>
202+
<className>com/google/cloud/spanner/DatabaseClient</className>
203+
<method>java.lang.String getDatabaseRole()</method>
204+
</difference>
195205
</differences>

google-cloud-spanner/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@
359359
<dependency>
360360
<groupId>org.json</groupId>
361361
<artifactId>json</artifactId>
362-
<version>20220320</version>
362+
<version>20220924</version>
363363
<scope>test</scope>
364364
</dependency>
365365
<dependency>

google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,13 @@ public interface BatchClient {
5959
* successive read/query.
6060
*/
6161
BatchReadOnlyTransaction batchReadOnlyTransaction(BatchTransactionId batchTransactionId);
62+
63+
/**
64+
* Returns the {@link DatabaseRole} used by the client connection. The database role that is used
65+
* determines the access permissions that a connection has. This can for example be used to create
66+
* connections that are only permitted to access certain tables.
67+
*/
68+
default String getDatabaseRole() {
69+
throw new UnsupportedOperationException("method should be overwritten");
70+
};
6271
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.opencensus.trace.Tracing;
3434
import java.util.List;
3535
import java.util.Map;
36+
import javax.annotation.Nullable;
3637

3738
/** Default implementation for Batch Client interface. */
3839
public class BatchClientImpl implements BatchClient {
@@ -42,6 +43,12 @@ public class BatchClientImpl implements BatchClient {
4243
this.sessionClient = checkNotNull(sessionClient);
4344
}
4445

46+
@Override
47+
@Nullable
48+
public String getDatabaseRole() {
49+
return this.sessionClient.getSpanner().getOptions().getDatabaseRole();
50+
}
51+
4552
@Override
4653
public BatchReadOnlyTransaction batchReadOnlyTransaction(TimestampBound bound) {
4754
SessionImpl session = sessionClient.createSession();

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ default Dialect getDialect() {
3636
throw new UnsupportedOperationException("method should be overwritten");
3737
}
3838

39+
/**
40+
* Returns the {@link DatabaseRole} used by the client connection. The database role that is used
41+
* determines the access permissions that a connection has. This can for example be used to create
42+
* connections that are only permitted to access certain tables.
43+
*
44+
* @return the {@link DatabaseRole} used by the client connection.
45+
*/
46+
default String getDatabaseRole() {
47+
throw new UnsupportedOperationException("method should be overwritten");
48+
}
49+
3950
/**
4051
* Writes the given mutations atomically to the database.
4152
*

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClientImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.opencensus.trace.Span;
2929
import io.opencensus.trace.Tracer;
3030
import io.opencensus.trace.Tracing;
31+
import javax.annotation.Nullable;
3132

3233
class DatabaseClientImpl implements DatabaseClient {
3334
private static final String READ_WRITE_TRANSACTION = "CloudSpanner.ReadWriteTransaction";
@@ -58,6 +59,12 @@ public Dialect getDialect() {
5859
return pool.getDialect();
5960
}
6061

62+
@Override
63+
@Nullable
64+
public String getDatabaseRole() {
65+
return pool.getDatabaseRole();
66+
}
67+
6168
@Override
6269
public Timestamp write(final Iterable<Mutation> mutations) throws SpannerException {
6370
return writeWithOptions(mutations).getCommitTimestamp();

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,7 @@ private enum Position {
17841784

17851785
private final SessionPoolOptions options;
17861786
private final SettableFuture<Dialect> dialect = SettableFuture.create();
1787+
private final String databaseRole;
17871788
private final SessionClient sessionClient;
17881789
private final ScheduledExecutorService executor;
17891790
private final ExecutorFactory<ScheduledExecutorService> executorFactory;
@@ -1858,6 +1859,7 @@ static SessionPool createPool(
18581859
SpannerOptions spannerOptions, SessionClient sessionClient, List<LabelValue> labelValues) {
18591860
return createPool(
18601861
spannerOptions.getSessionPoolOptions(),
1862+
spannerOptions.getDatabaseRole(),
18611863
((GrpcTransportOptions) spannerOptions.getTransportOptions()).getExecutorFactory(),
18621864
sessionClient,
18631865
new Clock(),
@@ -1879,6 +1881,7 @@ static SessionPool createPool(
18791881
Clock clock) {
18801882
return createPool(
18811883
poolOptions,
1884+
null,
18821885
executorFactory,
18831886
sessionClient,
18841887
clock,
@@ -1888,6 +1891,7 @@ static SessionPool createPool(
18881891

18891892
static SessionPool createPool(
18901893
SessionPoolOptions poolOptions,
1894+
String databaseRole,
18911895
ExecutorFactory<ScheduledExecutorService> executorFactory,
18921896
SessionClient sessionClient,
18931897
Clock clock,
@@ -1896,6 +1900,7 @@ static SessionPool createPool(
18961900
SessionPool pool =
18971901
new SessionPool(
18981902
poolOptions,
1903+
databaseRole,
18991904
executorFactory,
19001905
executorFactory.get(),
19011906
sessionClient,
@@ -1908,13 +1913,15 @@ static SessionPool createPool(
19081913

19091914
private SessionPool(
19101915
SessionPoolOptions options,
1916+
String databaseRole,
19111917
ExecutorFactory<ScheduledExecutorService> executorFactory,
19121918
ScheduledExecutorService executor,
19131919
SessionClient sessionClient,
19141920
Clock clock,
19151921
MetricRegistry metricRegistry,
19161922
List<LabelValue> labelValues) {
19171923
this.options = options;
1924+
this.databaseRole = databaseRole;
19181925
this.executorFactory = executorFactory;
19191926
this.executor = executor;
19201927
this.sessionClient = sessionClient;
@@ -1956,6 +1963,11 @@ Dialect getDialect() {
19561963
}
19571964
}
19581965

1966+
@Nullable
1967+
public String getDatabaseRole() {
1968+
return databaseRole;
1969+
}
1970+
19591971
@VisibleForTesting
19601972
int getNumberOfSessionsInUse() {
19611973
synchronized (lock) {

google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchClientImplTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.spanner;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20+
import static org.junit.Assert.assertEquals;
2021
import static org.mockito.ArgumentMatchers.anyString;
2122
import static org.mockito.Mockito.anyMap;
2223
import static org.mockito.Mockito.eq;
@@ -115,4 +116,9 @@ public void testBatchReadOnlyTxnWithTxnId() {
115116
assertThat(batchTxn.getReadTimestamp())
116117
.isEqualTo(batchTxn.getBatchTransactionId().getTimestamp());
117118
}
119+
120+
@Test
121+
public void testGetDatabaseRole() {
122+
assertEquals(client.getDatabaseRole(), "role");
123+
}
118124
}

0 commit comments

Comments
 (0)