diff --git a/conf/integ-config.json b/conf/integ-config.json index f1cf90742..4aa307c35 100644 --- a/conf/integ-config.json +++ b/conf/integ-config.json @@ -14,6 +14,6 @@ "optout_api_token": "test-operator-key", "optout_api_uri": "http://localhost:8081/optout/replicate", "salts_expired_shutdown_hours": 12, - "operator_type": "public" - + "operator_type": "public", + "core_operator_config_path": "http://localhost:8088/operator/config" } \ No newline at end of file diff --git a/scripts/aws/conf/integ-uid2-config.json b/scripts/aws/conf/integ-uid2-config.json index a7272a26a..91b53b1f2 100644 --- a/scripts/aws/conf/integ-uid2-config.json +++ b/scripts/aws/conf/integ-uid2-config.json @@ -11,5 +11,6 @@ "core_attest_url": "https://core-integ.uidapi.com/attest", "optout_api_uri": "https://optout-integ.uidapi.com/optout/replicate", "optout_s3_folder": "uid-optout-integ/", - "allow_legacy_api": false + "allow_legacy_api": false, + "core_operator_config_path": "https://core-integ.uidapi.com/operator/config" } diff --git a/src/main/java/com/uid2/operator/Const.java b/src/main/java/com/uid2/operator/Const.java index 2be8eb38a..b1623f5ee 100644 --- a/src/main/java/com/uid2/operator/Const.java +++ b/src/main/java/com/uid2/operator/Const.java @@ -30,7 +30,7 @@ public class Config extends com.uid2.shared.Const.Config { public static final String MaxInvalidPaths = "logging_limit_max_invalid_paths_per_interval"; public static final String MaxVersionBucketsPerSite = "logging_limit_max_version_buckets_per_site"; - public static final String CoreConfigPath = "core_config_path"; + public static final String CoreConfigPath = "core_operator_config_path"; public static final String ConfigScanPeriodMs = "config_scan_period_ms"; public static final String Config = "config"; public static final String identityV3 = "identity_v3"; diff --git a/src/main/java/com/uid2/operator/Main.java b/src/main/java/com/uid2/operator/Main.java index 6da6f699f..470fafd80 100644 --- a/src/main/java/com/uid2/operator/Main.java +++ b/src/main/java/com/uid2/operator/Main.java @@ -266,12 +266,12 @@ private ICloudStorage wrapCloudStorageForOptOut(ICloudStorage cloudStorage) { } } - private void run() { + private void run() throws Exception { this.createVertxInstancesMetric(); this.createVertxEventLoopsMetric(); ConfigRetrieverFactory configRetrieverFactory = new ConfigRetrieverFactory(); - ConfigRetriever dynamicConfigRetriever = configRetrieverFactory.createHttpRetriever(vertx, config); + ConfigRetriever dynamicConfigRetriever = configRetrieverFactory.createRemoteConfigRetriever(vertx, config, this.createOperatorKeyRetriever().retrieve()); ConfigRetriever staticConfigRetriever = configRetrieverFactory.createJsonRetriever(vertx, config); Future dynamicConfigFuture = ConfigService.create(dynamicConfigRetriever); diff --git a/src/main/java/com/uid2/operator/service/ConfigRetrieverFactory.java b/src/main/java/com/uid2/operator/service/ConfigRetrieverFactory.java index 11957fbe6..488c9d69e 100644 --- a/src/main/java/com/uid2/operator/service/ConfigRetrieverFactory.java +++ b/src/main/java/com/uid2/operator/service/ConfigRetrieverFactory.java @@ -1,26 +1,31 @@ package com.uid2.operator.service; -import com.uid2.operator.Const; import io.vertx.config.ConfigRetriever; import io.vertx.config.ConfigRetrieverOptions; import io.vertx.config.ConfigStoreOptions; import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; +import java.net.URI; +import java.net.URISyntaxException; + import static com.uid2.operator.Const.Config.ConfigScanPeriodMs; import static com.uid2.operator.Const.Config.CoreConfigPath; public class ConfigRetrieverFactory { - public ConfigRetriever createHttpRetriever(Vertx vertx, JsonObject bootstrapConfig) { + public ConfigRetriever createRemoteConfigRetriever(Vertx vertx, JsonObject bootstrapConfig, String operatorKey) throws URISyntaxException { String configPath = bootstrapConfig.getString(CoreConfigPath); + URI uri = new URI(configPath); ConfigStoreOptions httpStore = new ConfigStoreOptions() .setType("http") .setOptional(true) .setConfig(new JsonObject() - .put("host", "127.0.0.1") - .put("port", Const.Port.ServicePortForCore) - .put("path", configPath)); + .put("host", uri.getHost()) + .put("port", uri.getPort()) + .put("path", uri.getPath()) + .put("headers", new JsonObject() + .put("Authorization", "Bearer " + operatorKey))); ConfigRetrieverOptions retrieverOptions = new ConfigRetrieverOptions() .setScanPeriod(bootstrapConfig.getLong(ConfigScanPeriodMs)) diff --git a/src/test/java/com/uid2/operator/ConfigServiceTest.java b/src/test/java/com/uid2/operator/ConfigServiceTest.java index fe943f61e..d7ff8e9e7 100644 --- a/src/test/java/com/uid2/operator/ConfigServiceTest.java +++ b/src/test/java/com/uid2/operator/ConfigServiceTest.java @@ -16,6 +16,8 @@ import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.extension.ExtendWith; +import java.net.URISyntaxException; + import static com.uid2.operator.Const.Config.*; import static com.uid2.operator.service.UIDOperatorService.*; import static org.junit.jupiter.api.Assertions.*; @@ -32,7 +34,7 @@ class ConfigServiceTest { void setUp() { vertx = Vertx.vertx(); bootstrapConfig = new JsonObject() - .put(CoreConfigPath, "/operator/config") + .put(CoreConfigPath, "http://localhost:8088/operator/config") .put(ConfigScanPeriodMs, 300000) .put(IDENTITY_TOKEN_EXPIRES_AFTER_SECONDS, 3600) .put(REFRESH_TOKEN_EXPIRES_AFTER_SECONDS, 7200) @@ -78,8 +80,8 @@ private Future startMockServer(JsonObject config) { } @Test - void testGetConfig(VertxTestContext testContext) { - ConfigRetriever configRetriever = configRetrieverFactory.createHttpRetriever(vertx, bootstrapConfig); + void testGetConfig(VertxTestContext testContext) throws URISyntaxException { + ConfigRetriever configRetriever = configRetrieverFactory.createRemoteConfigRetriever(vertx, bootstrapConfig, ""); JsonObject httpStoreConfig = bootstrapConfig; startMockServer(httpStoreConfig) .compose(v -> ConfigService.create(configRetriever))