Skip to content

Commit

Permalink
Add authorisation header to config retriever
Browse files Browse the repository at this point in the history
  • Loading branch information
BehnamMozafari committed Jan 15, 2025
1 parent 68530b4 commit 1dfdea3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions conf/integ-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion scripts/aws/conf/integ-uid2-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/operator/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/uid2/operator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigService> dynamicConfigFuture = ConfigService.create(dynamicConfigRetriever);
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/com/uid2/operator/ConfigServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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)
Expand Down Expand Up @@ -78,8 +80,8 @@ private Future<Void> 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))
Expand Down

0 comments on commit 1dfdea3

Please sign in to comment.