From 5ac56744f73f4a3ca5b89acdc21ac12d01b40f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Czerpak?= Date: Tue, 10 Dec 2024 12:31:45 +0100 Subject: [PATCH] Revert "* fix: changed name of WTP_LS_ALLOW_REGEX to WTP_LS_ALLOWED_LOCATIONS_REGEX and introduced a new option WTP_LS_ENABLED (#101)" This reverts commit cf52ab28f37e0d4f2635f4e47fc1f9de53b3dcb9. --- config/default.js | 3 +-- wtp/locationSelector.js | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/config/default.js b/config/default.js index 4f89731..bd3ecad 100644 --- a/config/default.js +++ b/config/default.js @@ -37,8 +37,7 @@ const conf = { }, timeout: process.env.WTP_TIMEOUT || 30000, "locationSelector": { - "enabled": process.env.WTP_LS_ENABLED || false, - "allowedLocationsRegex": process.env.WTP_LS_ALLOWED_LOCATIONS_REGEX || '_US_', + "allowRegex": process.env.WTP_LS_ALLOW_REGEX || '_US_', "cacheTtl": process.env.WTP_LS_CACHE_TTL || 10, "updateTimeout": process.env.WTP_LS_UPDATE_TIMEOUT || 20, "defaultLocation": process.env.WTP_LS_DEFAULT_LOCATION || "IAD_US_01" diff --git a/wtp/locationSelector.js b/wtp/locationSelector.js index 0eed3ab..07ec370 100644 --- a/wtp/locationSelector.js +++ b/wtp/locationSelector.js @@ -29,10 +29,9 @@ const locationMetrics = { class LocationSelector { constructor() { if (!LocationSelector.instance) { - this.enabled = config.get('wtp.locationSelector.enabled'); this.cachedAllLocations = []; this.location = config.get('wtp.locationSelector.defaultLocation'); - this.allowedLocationsRegex = new RegExp(config.get('wtp.locationSelector.allowedLocationsRegex')); + this.allowRegex = new RegExp(config.get('wtp.locationSelector.allowRegex')); this.lastUpdated = null; this.mutex = withTimeout(new Mutex(), config.get('wtp.locationSelector.updateTimeout') * 1000); LocationSelector.instance = this; @@ -115,7 +114,7 @@ class LocationSelector { } const filtered = Object.keys(newLocations) - .filter(key => this.allowedLocationsRegex.test(key)) + .filter(key => this.allowRegex.test(key)) .reduce((arr, key) => { return [...arr, newLocations[key]]; }, []); @@ -155,7 +154,7 @@ class LocationSelector { }; async getLocation() { - if (this.enabled && this.isExpired()) { + if (this.isExpired()) { try { await this.mutex.runExclusive(async () => { if (this.isExpired()) {