From 76397bf7ce27804101a1622e82f436cac0dcd605 Mon Sep 17 00:00:00 2001 From: Aristide Niyungeko <2230766+aristide-n@users.noreply.github.com> Date: Thu, 26 Aug 2021 12:20:11 -0700 Subject: [PATCH] feat: support overriding the emulator download URL in LocalDatastoreHelper (#492) Fixes #376 --- .../cloud/datastore/testing/LocalDatastoreHelper.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java index 2867d7e30..e586f7e55 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java @@ -63,6 +63,8 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper { private static final String MD5_CHECKSUM = "ec2237a0f0ac54964c6bd95e12c73720"; private static final String BIN_CMD_PORT_FLAG = "--port="; private static final URL EMULATOR_URL; + private static final String EMULATOR_URL_ENV_VAR = "DATASTORE_EMULATOR_URL"; + private static final String ACCESS_TOKEN = System.getenv("DATASTORE_EMULATOR_ACCESS_TOKEN"); // Common settings private static final String CONSISTENCY_FLAG = "--consistency="; @@ -72,7 +74,11 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper { static { try { - EMULATOR_URL = new URL("http://storage.googleapis.com/gcd/tools/" + FILENAME); + if (System.getenv(EMULATOR_URL_ENV_VAR) == null) { + EMULATOR_URL = new URL("http://storage.googleapis.com/gcd/tools/" + FILENAME); + } else { + EMULATOR_URL = new URL(System.getenv(EMULATOR_URL_ENV_VAR)); + } } catch (MalformedURLException ex) { throw new IllegalStateException(ex); } @@ -147,7 +153,7 @@ private LocalDatastoreHelper(Builder builder) { gcloudCommand.add("--data-dir=" + getGcdPath()); } DownloadableEmulatorRunner downloadRunner = - new DownloadableEmulatorRunner(binCommand, EMULATOR_URL, MD5_CHECKSUM); + new DownloadableEmulatorRunner(binCommand, EMULATOR_URL, MD5_CHECKSUM, ACCESS_TOKEN); this.emulatorRunners = ImmutableList.of(gcloudRunner, downloadRunner); }