Skip to content

Commit 2aa18db

Browse files
committed
skip auth_token for emulator
1 parent e65c555 commit 2aa18db

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,6 @@ public static CloseableExecutorProvider createAsyncExecutorProvider(
740740

741741
protected SpannerOptions(Builder builder) {
742742
super(SpannerFactory.class, SpannerRpcFactory.class, builder, new SpannerDefaults());
743-
if (builder.emulatorHost != null) {
744-
builder.setHost(builder.emulatorHost);
745-
}
746743
numChannels = builder.numChannels == null ? DEFAULT_CHANNELS : builder.numChannels;
747744
Preconditions.checkArgument(
748745
numChannels >= 1 && numChannels <= MAX_CHANNELS,
@@ -814,7 +811,7 @@ protected SpannerOptions(Builder builder) {
814811
enableEndToEndTracing = builder.enableEndToEndTracing;
815812
monitoringHost = builder.monitoringHost;
816813
String externalHostTokenPath = System.getenv("EXTERNAL_HOST_AUTH_TOKEN");
817-
if (builder.isExternalHost && externalHostTokenPath != null) {
814+
if (builder.isExternalHost && builder.emulatorHost == null && externalHostTokenPath != null) {
818815
String token;
819816
try {
820817
token =

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/SpannerPool.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,10 @@ private void initialize() {
363363
@VisibleForTesting
364364
Spanner createSpanner(SpannerPoolKey key, ConnectionOptions options) {
365365
ConnectionSpannerOptions.Builder builder = ConnectionSpannerOptions.newBuilder();
366-
if (options.usesEmulator()) {
367-
builder.setEmulatorHost(key.host);
368-
} else {
369-
builder.setHost(key.host);
370-
}
371366
builder
372367
.setUseVirtualThreads(key.useVirtualGrpcTransportThreads)
373368
.setClientLibToken(MoreObjects.firstNonNull(key.userAgent, CONNECTION_API_CLIENT_LIB_TOKEN))
369+
.setHost(key.host)
374370
.setProjectId(key.projectId)
375371
// Use lazy decoding, so we can use the protobuf values for calculating the checksum that is
376372
// needed for read/write transactions.
@@ -411,6 +407,9 @@ Spanner createSpanner(SpannerPoolKey key, ConnectionOptions options) {
411407
if (options.getConfigurator() != null) {
412408
options.getConfigurator().configure(builder);
413409
}
410+
if (options.usesEmulator()) {
411+
builder.setEmulatorHost(key.host);
412+
}
414413
return builder.build().getService();
415414
}
416415

0 commit comments

Comments
 (0)