Skip to content

Commit 798940a

Browse files
committed
Merge branch 'main' into PR #3928 to update
2 parents 76a56f7 + 0ca9541 commit 798940a

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected com.google.iam.v1.Policy toPb(Policy policy) {
5353
}
5454

5555
private static final PathTemplate PROJECT_NAME_TEMPLATE =
56-
PathTemplate.create("projects/{project}");
56+
PathTemplate.createWithoutUrlEncoding("projects/{project}");
5757
private final DatabaseAdminClient dbClient;
5858
private final String projectId;
5959
private final SpannerRpc rpc;

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,12 @@ public GapicSpannerRpc(final SpannerOptions options) {
368368
boolean isEnableDirectAccess = options.isEnableDirectAccess();
369369
if (isEnableDirectAccess) {
370370
defaultChannelProviderBuilder.setAttemptDirectPath(true);
371-
// This will let the credentials try to fetch a hard-bound access token if the runtime
372-
// environment supports it.
373-
defaultChannelProviderBuilder.setAllowHardBoundTokenTypes(
374-
Collections.singletonList(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS));
371+
if (isEnableDirectPathBoundToken()) {
372+
// This will let the credentials try to fetch a hard-bound access token if the runtime
373+
// environment supports it.
374+
defaultChannelProviderBuilder.setAllowHardBoundTokenTypes(
375+
Collections.singletonList(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS));
376+
}
375377
defaultChannelProviderBuilder.setAttemptDirectPathXds();
376378
}
377379

@@ -687,6 +689,10 @@ public static boolean isEnableDirectPathXdsEnv() {
687689
return Boolean.parseBoolean(System.getenv("GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"));
688690
}
689691

692+
public static boolean isEnableDirectPathBoundToken() {
693+
return !Boolean.parseBoolean(System.getenv("GOOGLE_SPANNER_DISABLE_DIRECT_ACCESS_BOUND_TOKEN"));
694+
}
695+
690696
private static final RetrySettings ADMIN_REQUESTS_LIMIT_EXCEEDED_RETRY_SETTINGS =
691697
RetrySettings.newBuilder()
692698
.setInitialRetryDelayDuration(Duration.ofSeconds(5L))

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,39 @@ public void createInstance() throws Exception {
296296
assertThat(op.get().getId().getName()).isEqualTo(INSTANCE_NAME);
297297
}
298298

299+
@Test
300+
public void createInstanceWithOrgNameInProjectId() throws Exception {
301+
String projectIdWithOrg = "my-org:my-project";
302+
String instanceNameWithOrg = "projects/my-org:my-project/instances/my-instance";
303+
String configNameWithOrg = "projects/my-org:my-project/instanceConfigs/my-config";
304+
305+
InstanceAdminClient universeClient =
306+
new InstanceAdminClientImpl(projectIdWithOrg, rpc, dbClient);
307+
com.google.spanner.admin.instance.v1.Instance instance =
308+
com.google.spanner.admin.instance.v1.Instance.newBuilder()
309+
.setConfig(configNameWithOrg)
310+
.setName(instanceNameWithOrg)
311+
.setNodeCount(1)
312+
.setProcessingUnits(0)
313+
.setEdition(com.google.spanner.admin.instance.v1.Instance.Edition.ENTERPRISE_PLUS)
314+
.build();
315+
OperationFuture<com.google.spanner.admin.instance.v1.Instance, CreateInstanceMetadata>
316+
rawOperationFuture =
317+
OperationFutureUtil.immediateOperationFuture(
318+
"createInstance", instance, CreateInstanceMetadata.getDefaultInstance());
319+
when(rpc.createInstance("projects/" + projectIdWithOrg, INSTANCE_ID, instance))
320+
.thenReturn(rawOperationFuture);
321+
OperationFuture<Instance, CreateInstanceMetadata> op =
322+
universeClient.createInstance(
323+
InstanceInfo.newBuilder(InstanceId.of(projectIdWithOrg, INSTANCE_ID))
324+
.setInstanceConfigId(InstanceConfigId.of(projectIdWithOrg, CONFIG_ID))
325+
.setEdition(com.google.spanner.admin.instance.v1.Instance.Edition.ENTERPRISE_PLUS)
326+
.setNodeCount(1)
327+
.build());
328+
assertThat(op.isDone()).isTrue();
329+
assertThat(op.get().getId().getName()).isEqualTo(instanceNameWithOrg);
330+
}
331+
299332
@Test
300333
public void testCreateInstanceWithProcessingUnits() throws Exception {
301334
OperationFuture<com.google.spanner.admin.instance.v1.Instance, CreateInstanceMetadata>

0 commit comments

Comments
 (0)