diff --git a/pom.xml b/pom.xml index 99c48a083..ff7f61849 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.uid2 uid2-operator - 5.42.7-alpha-139-SNAPSHOT + 6.0.0 UTF-8 @@ -22,7 +22,7 @@ 2.1.0 2.1.0 2.1.0 - 8.0.13-alpha-175-SNAPSHOT + 8.0.14-alpha-176-SNAPSHOT ${project.version} 21 21 diff --git a/src/main/java/com/uid2/operator/Main.java b/src/main/java/com/uid2/operator/Main.java index 19cf7bd1f..04643d21e 100644 --- a/src/main/java/com/uid2/operator/Main.java +++ b/src/main/java/com/uid2/operator/Main.java @@ -147,7 +147,7 @@ public Main(Vertx vertx, JsonObject config) throws Exception { String keysetMdPath = this.config.getString(Const.Config.KeysetsMetadataPathProp); this.keysetProvider = new RotatingKeysetProvider(fsStores, new GlobalScope(new CloudPath(keysetMdPath)), cloudEncryptionKeyProvider); String saltsMdPath = this.config.getString(Const.Config.SaltsMetadataPathProp); - this.saltProvider = new EncryptedRotatingSaltProvider(fsStores, saltsMdPath, cloudEncryptionKeyProvider); + this.saltProvider = new EncryptedRotatingSaltProvider(fsStores, cloudEncryptionKeyProvider, new GlobalScope(new CloudPath(saltsMdPath))); this.optOutStore = new CloudSyncOptOutStore(vertx, fsLocal, this.config, operatorKey, Clock.systemUTC()); if (this.validateServiceLinks) { diff --git a/src/main/java/com/uid2/operator/reader/ApiStoreReader.java b/src/main/java/com/uid2/operator/reader/ApiStoreReader.java index 78937e16c..fda4c4e6a 100644 --- a/src/main/java/com/uid2/operator/reader/ApiStoreReader.java +++ b/src/main/java/com/uid2/operator/reader/ApiStoreReader.java @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -21,13 +22,19 @@ public ApiStoreReader(DownloadCloudStorage fileStreamProvider, StoreScope scope, super(fileStreamProvider, scope, parser, dataTypeName); } + public long loadContent(JsonObject contents) throws Exception { + return loadContent(contents, dataTypeName); + } + + @Override + public long loadContent(JsonObject contents, String dataType) throws IOException { if (contents == null) { - throw new IllegalArgumentException(String.format("No contents provided for loading data type %s, cannot load content", dataTypeName)); + throw new IllegalArgumentException(String.format("No contents provided for loading data type %s, cannot load content", dataType)); } try { - JsonArray dataArray = contents.getJsonArray(dataTypeName); + JsonArray dataArray = contents.getJsonArray(dataType); if (dataArray == null) { throw new IllegalArgumentException("No array found in the contents"); } @@ -40,10 +47,10 @@ public long loadContent(JsonObject contents) throws Exception { final int count = parsed.getCount(); latestEntryCount.set(count); - LOGGER.info(String.format("Loaded %d %s", count, dataTypeName)); + LOGGER.info(String.format("Loaded %d %s", count, dataType)); return count; } catch (Exception e) { - LOGGER.error(String.format("Unable to load %s", dataTypeName)); + LOGGER.error(String.format("Unable to load %s", dataType)); throw e; } } diff --git a/src/main/java/com/uid2/operator/reader/RotatingCloudEncryptionKeyApiProvider.java b/src/main/java/com/uid2/operator/reader/RotatingCloudEncryptionKeyApiProvider.java index 4c91ea9dc..45aff8e9a 100644 --- a/src/main/java/com/uid2/operator/reader/RotatingCloudEncryptionKeyApiProvider.java +++ b/src/main/java/com/uid2/operator/reader/RotatingCloudEncryptionKeyApiProvider.java @@ -16,41 +16,19 @@ public class RotatingCloudEncryptionKeyApiProvider extends RotatingCloudEncryptionKeyProvider { private static final Logger LOGGER = LoggerFactory.getLogger(RotatingCloudEncryptionKeyApiProvider.class); - public ApiStoreReader> apiStoreReader; - public RotatingCloudEncryptionKeyApiProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope) { super(fileStreamProvider, scope); - this.apiStoreReader = new ApiStoreReader<>(fileStreamProvider, scope, new CloudEncryptionKeyParser(), "cloud_encryption_keys"); - } - - @Override - public JsonObject getMetadata() throws Exception { - return apiStoreReader.getMetadata(); + this.reader = new ApiStoreReader<>(fileStreamProvider, scope, new CloudEncryptionKeyParser(), "cloud_encryption_keys"); } - @Override - public CloudPath getMetadataPath() { - return apiStoreReader.getMetadataPath(); + public RotatingCloudEncryptionKeyApiProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope, ApiStoreReader> reader) { + super(fileStreamProvider, scope); + this.reader = reader; } - @Override - public long loadContent(JsonObject metadata) throws Exception { - return apiStoreReader.loadContent(metadata); - } @Override public long getVersion(JsonObject metadata) { return Instant.now().getEpochSecond(); } - - @Override - public Map getAll() { - Map keys = apiStoreReader.getSnapshot(); - return keys != null ? keys : new HashMap<>(); - } - - @Override - public void loadContent() throws Exception { - this.loadContent(this.getMetadata()); - } } diff --git a/src/test/java/com/uid2/operator/RotatingCloudEncryptionKeyApiProviderTest.java b/src/test/java/com/uid2/operator/RotatingCloudEncryptionKeyApiProviderTest.java index 04f1ad0aa..254276658 100644 --- a/src/test/java/com/uid2/operator/RotatingCloudEncryptionKeyApiProviderTest.java +++ b/src/test/java/com/uid2/operator/RotatingCloudEncryptionKeyApiProviderTest.java @@ -34,8 +34,7 @@ class RotatingCloudEncryptionKeyApiProviderTest { @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); - rotatingCloudEncryptionKeyApiProvider = new RotatingCloudEncryptionKeyApiProvider(mockFileStreamProvider, mockScope); - rotatingCloudEncryptionKeyApiProvider.apiStoreReader = mockApiStoreReader; + rotatingCloudEncryptionKeyApiProvider = new RotatingCloudEncryptionKeyApiProvider(mockFileStreamProvider, mockScope, mockApiStoreReader); } @Test @@ -61,11 +60,11 @@ void testGetMetadataPath() { @Test void testLoadContentWithMetadata() throws Exception { JsonObject metadata = new JsonObject(); - when(mockApiStoreReader.loadContent(metadata)).thenReturn(1L); + when(mockApiStoreReader.loadContent(metadata, "cloud_encryption_keys")).thenReturn(1L); long version = rotatingCloudEncryptionKeyApiProvider.loadContent(metadata); assertEquals(1L, version); - verify(mockApiStoreReader).loadContent(metadata); + verify(mockApiStoreReader).loadContent(metadata, "cloud_encryption_keys"); } @Test @@ -94,10 +93,10 @@ void testGetAllWithNullSnapshot() { void testLoadContent() throws Exception { JsonObject metadata = new JsonObject().put("version", 1L); when(mockApiStoreReader.getMetadata()).thenReturn(metadata); - when(mockApiStoreReader.loadContent(metadata)).thenReturn(1L); + when(mockApiStoreReader.loadContent(metadata, "cloud_encryption_keys")).thenReturn(1L); rotatingCloudEncryptionKeyApiProvider.loadContent(); verify(mockApiStoreReader).getMetadata(); - verify(mockApiStoreReader).loadContent(metadata); + verify(mockApiStoreReader).loadContent(metadata, "cloud_encryption_keys"); } } \ No newline at end of file