Skip to content

Commit

Permalink
Try autoConfigEmulator=true;usePlainText with the right conditions
Browse files Browse the repository at this point in the history
This allows the Cloud Spanner Emulator to be used in tests.
  • Loading branch information
odeke-em committed Sep 5, 2023
1 parent 363a860 commit 79dfb48
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,19 @@ public static Connection connectionFromProperties(Map<String, String> properties

String spannerUri =
String.format(
connUriPrefix + "/projects/%s/instances/%s/databases/%s?autoConfigEmulator=%s",
connUriPrefix + "/projects/%s/instances/%s/databases/%s?autoConfigEmulator=%s;usePlainText=%s",
properties.get("projectId"),
properties.get("instanceId"),
properties.get("databaseId"),
emulatorHost != null,
emulatorHost != null);

ConnectionOptions.Builder builder = ConnectionOptions.newBuilder().setUri(spannerUri);
String gcpCredsUrl = properties.get("credentials");
if (gcpCredsUrl != null) {
if (emulatorHost != null) {
builder = builder.setCredentialsUrl(null);
} else if (gcpCredsUrl != null) {
builder = builder.setCredentialsUrl(gcpCredsUrl);
} else if (emulatorHost != null) {
builder = builder.setCredentialsUrl(NoCredentials.getInstance().toString());
}
ConnectionOptions opts = builder.build();
return opts.getConnection();
Expand Down

0 comments on commit 79dfb48

Please sign in to comment.