diff --git a/docs/config-app.md b/docs/config-app.md index 72a81b840f8..041c1774830 100644 --- a/docs/config-app.md +++ b/docs/config-app.md @@ -268,9 +268,9 @@ See [metrics documentation](metrics.md) for complete list of metrics submitted a - `cache.scheme` - set the external Cache Service protocol: `http`, `https`, etc. - `cache.host` - set the external Cache Service destination in format `host:port`. - `cache.path` - set the external Cache Service path, for example `/cache`. -- `cache.module.enabled` - If set to true, this will allow storing modules’ data in third-party storage. -- `cache.module.path` - set the external Cache Service path for module caching, for example `/module/cache`. -- `cache.api.key` - set the external Cache Service api key for secured calls. +- `storage.pbc.enabled` - If set to true, this will allow storing modules’ data in third-party storage. +- `storage.pbc.path` - set the external Cache Service path for module caching, for example `/pbc-storage`. +- `pbc.api.key` - set the external Cache Service api key for secured calls. - `cache.query` - appends to the cache path as query string params (used for legacy Auction requests). - `cache.banner-ttl-seconds` - how long (in seconds) banner will be available via the external Cache Service. - `cache.video-ttl-seconds` - how long (in seconds) video creative will be available via the external Cache Service. diff --git a/src/main/java/org/prebid/server/cache/BasicModuleCacheService.java b/src/main/java/org/prebid/server/cache/BasicPbcStorageService.java similarity index 86% rename from src/main/java/org/prebid/server/cache/BasicModuleCacheService.java rename to src/main/java/org/prebid/server/cache/BasicPbcStorageService.java index ccd23391aba..6db93819349 100644 --- a/src/main/java/org/prebid/server/cache/BasicModuleCacheService.java +++ b/src/main/java/org/prebid/server/cache/BasicPbcStorageService.java @@ -5,7 +5,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.prebid.server.cache.proto.request.module.ModuleCacheRequest; -import org.prebid.server.cache.proto.request.module.ModuleCacheType; +import org.prebid.server.cache.proto.request.module.StorageDataType; import org.prebid.server.cache.proto.response.module.ModuleCacheResponse; import org.prebid.server.cache.utils.CacheServiceUtil; import org.prebid.server.exception.PreBidException; @@ -17,7 +17,7 @@ import java.net.URL; import java.util.Objects; -public class BasicModuleCacheService implements ModuleCacheService { +public class BasicPbcStorageService implements PbcStorageService { public static final String MODULE_KEY_PREFIX = "module"; public static final String MODULE_KEY_DELIMETER = "."; @@ -28,11 +28,11 @@ public class BasicModuleCacheService implements ModuleCacheService { private final int callTimeoutMs; private final JacksonMapper mapper; - public BasicModuleCacheService(HttpClient httpClient, - URL endpointUrl, - String apiKey, - int callTimeoutMs, - JacksonMapper mapper) { + public BasicPbcStorageService(HttpClient httpClient, + URL endpointUrl, + String apiKey, + int callTimeoutMs, + JacksonMapper mapper) { this.httpClient = Objects.requireNonNull(httpClient); this.endpointUrl = Objects.requireNonNull(endpointUrl); @@ -42,12 +42,12 @@ public BasicModuleCacheService(HttpClient httpClient, } @Override - public Future storeModuleEntry(String key, - String value, - ModuleCacheType type, - Integer ttlseconds, - String application, - String moduleCode) { + public Future storeEntry(String key, + String value, + StorageDataType type, + Integer ttlseconds, + String application, + String moduleCode) { try { validateStoreData(key, value, application, type, moduleCode); @@ -75,7 +75,7 @@ public Future storeModuleEntry(String key, private static void validateStoreData(String key, String value, String application, - ModuleCacheType type, + StorageDataType type, String moduleCode) { if (StringUtils.isBlank(key)) { @@ -99,8 +99,8 @@ private static void validateStoreData(String key, } } - private static String prepareValueForStoring(String value, ModuleCacheType type) { - return type == ModuleCacheType.TEXT + private static String prepareValueForStoring(String value, StorageDataType type) { + return type == StorageDataType.TEXT ? new String(Base64.encodeBase64(value.getBytes())) : value; } @@ -186,8 +186,8 @@ private ModuleCacheResponse toModuleCacheResponse(int statusCode, String respons : ModuleCacheResponse.of(moduleCacheResponse.getKey(), moduleCacheResponse.getType(), processedValue); } - private static String prepareValueAfterRetrieve(String value, ModuleCacheType type) { - return type == ModuleCacheType.TEXT + private static String prepareValueAfterRetrieve(String value, StorageDataType type) { + return type == StorageDataType.TEXT ? new String(Base64.decodeBase64(value.getBytes())) : value; } diff --git a/src/main/java/org/prebid/server/cache/ModuleCacheService.java b/src/main/java/org/prebid/server/cache/ModuleCacheService.java deleted file mode 100644 index 4e5e3cf850b..00000000000 --- a/src/main/java/org/prebid/server/cache/ModuleCacheService.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.prebid.server.cache; - -import io.vertx.core.Future; -import org.prebid.server.cache.proto.request.module.ModuleCacheType; -import org.prebid.server.cache.proto.response.module.ModuleCacheResponse; - -public interface ModuleCacheService { - - Future storeModuleEntry(String key, - String value, - ModuleCacheType type, - Integer ttlseconds, - String application, - String moduleCode); - - Future retrieveModuleEntry(String key, String moduleCode, String application); - - static ModuleCacheService.NoOpModuleCacheService noOp() { - return new ModuleCacheService.NoOpModuleCacheService(); - } - - class NoOpModuleCacheService implements ModuleCacheService { - - @Override - public Future storeModuleEntry(String key, - String value, - ModuleCacheType type, - Integer ttlseconds, - String application, - String moduleCode) { - - return Future.succeededFuture(); - } - - @Override - public Future retrieveModuleEntry(String key, String moduleCode, String application) { - return Future.succeededFuture(ModuleCacheResponse.empty()); - } - } -} diff --git a/src/main/java/org/prebid/server/cache/PbcStorageService.java b/src/main/java/org/prebid/server/cache/PbcStorageService.java new file mode 100644 index 00000000000..4e8d432a158 --- /dev/null +++ b/src/main/java/org/prebid/server/cache/PbcStorageService.java @@ -0,0 +1,40 @@ +package org.prebid.server.cache; + +import io.vertx.core.Future; +import org.prebid.server.cache.proto.request.module.StorageDataType; +import org.prebid.server.cache.proto.response.module.ModuleCacheResponse; + +public interface PbcStorageService { + + Future storeEntry(String key, + String value, + StorageDataType type, + Integer ttlseconds, + String application, + String moduleCode); + + Future retrieveModuleEntry(String key, String moduleCode, String application); + + static NoOpPbcStorageService noOp() { + return new NoOpPbcStorageService(); + } + + class NoOpPbcStorageService implements PbcStorageService { + + @Override + public Future storeEntry(String key, + String value, + StorageDataType type, + Integer ttlseconds, + String application, + String moduleCode) { + + return Future.succeededFuture(); + } + + @Override + public Future retrieveModuleEntry(String key, String moduleCode, String application) { + return Future.succeededFuture(ModuleCacheResponse.empty()); + } + } +} diff --git a/src/main/java/org/prebid/server/cache/proto/request/module/ModuleCacheRequest.java b/src/main/java/org/prebid/server/cache/proto/request/module/ModuleCacheRequest.java index 4f4e28d982b..25c7a08309a 100644 --- a/src/main/java/org/prebid/server/cache/proto/request/module/ModuleCacheRequest.java +++ b/src/main/java/org/prebid/server/cache/proto/request/module/ModuleCacheRequest.java @@ -7,7 +7,7 @@ public class ModuleCacheRequest { String key; - ModuleCacheType type; + StorageDataType type; String value; diff --git a/src/main/java/org/prebid/server/cache/proto/request/module/ModuleCacheType.java b/src/main/java/org/prebid/server/cache/proto/request/module/StorageDataType.java similarity index 78% rename from src/main/java/org/prebid/server/cache/proto/request/module/ModuleCacheType.java rename to src/main/java/org/prebid/server/cache/proto/request/module/StorageDataType.java index c1a22fa6d8e..7636d1c75ea 100644 --- a/src/main/java/org/prebid/server/cache/proto/request/module/ModuleCacheType.java +++ b/src/main/java/org/prebid/server/cache/proto/request/module/StorageDataType.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonValue; -public enum ModuleCacheType { +public enum StorageDataType { JSON("json"), XML("xml"), @@ -11,7 +11,7 @@ public enum ModuleCacheType { @JsonValue private final String text; - ModuleCacheType(String text) { + StorageDataType(String text) { this.text = text; } } diff --git a/src/main/java/org/prebid/server/cache/proto/response/module/ModuleCacheResponse.java b/src/main/java/org/prebid/server/cache/proto/response/module/ModuleCacheResponse.java index 92b928e1750..494acdab836 100644 --- a/src/main/java/org/prebid/server/cache/proto/response/module/ModuleCacheResponse.java +++ b/src/main/java/org/prebid/server/cache/proto/response/module/ModuleCacheResponse.java @@ -1,14 +1,14 @@ package org.prebid.server.cache.proto.response.module; import lombok.Value; -import org.prebid.server.cache.proto.request.module.ModuleCacheType; +import org.prebid.server.cache.proto.request.module.StorageDataType; @Value(staticConstructor = "of") public class ModuleCacheResponse { String key; - ModuleCacheType type; + StorageDataType type; String value; diff --git a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java index 39968a6d5cc..97b60e92b49 100644 --- a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java @@ -70,9 +70,9 @@ import org.prebid.server.bidder.BidderRequestCompletionTrackerFactory; import org.prebid.server.bidder.HttpBidderRequestEnricher; import org.prebid.server.bidder.HttpBidderRequester; -import org.prebid.server.cache.BasicModuleCacheService; +import org.prebid.server.cache.BasicPbcStorageService; import org.prebid.server.cache.CoreCacheService; -import org.prebid.server.cache.ModuleCacheService; +import org.prebid.server.cache.PbcStorageService; import org.prebid.server.cache.model.CacheTtl; import org.prebid.server.cache.utils.CacheServiceUtil; import org.prebid.server.cookie.CookieDeprecationService; @@ -183,22 +183,22 @@ CoreCacheService cacheService( @Bean @ConditionalOnProperty(prefix = "cache.module", name = "enabled", havingValue = "false", matchIfMissing = true) - ModuleCacheService noOpModuleCacheService() { - return ModuleCacheService.noOp(); + PbcStorageService noOpModuleCacheService() { + return PbcStorageService.noOp(); } @Bean @ConditionalOnProperty(prefix = "cache.module", name = "enabled", havingValue = "true") - ModuleCacheService basicModuleCacheService( + PbcStorageService basicModuleCacheService( @Value("${cache.scheme}") String scheme, @Value("${cache.host}") String host, - @Value("${cache.module.path}") String path, - @Value("${cache.module.call-timeout-ms}") int callTimeoutMs, - @Value("${cache.api.key}") String apiKey, + @Value("${storage.pbc.path}") String path, + @Value("${storage.pbc.call-timeout-ms}") int callTimeoutMs, + @Value("${pbc.api.key}") String apiKey, HttpClient httpClient, JacksonMapper mapper) { - return new BasicModuleCacheService( + return new BasicPbcStorageService( httpClient, CacheServiceUtil.getCacheEndpointUrl(scheme, host, path), apiKey, diff --git a/src/test/java/org/prebid/server/cache/BasicModuleCacheServiceTest.java b/src/test/java/org/prebid/server/cache/BasicPbcStorageServiceTest.java similarity index 83% rename from src/test/java/org/prebid/server/cache/BasicModuleCacheServiceTest.java rename to src/test/java/org/prebid/server/cache/BasicPbcStorageServiceTest.java index 05f212d8e85..3a146a26dc4 100644 --- a/src/test/java/org/prebid/server/cache/BasicModuleCacheServiceTest.java +++ b/src/test/java/org/prebid/server/cache/BasicPbcStorageServiceTest.java @@ -12,7 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.prebid.server.VertxTest; import org.prebid.server.cache.proto.request.module.ModuleCacheRequest; -import org.prebid.server.cache.proto.request.module.ModuleCacheType; +import org.prebid.server.cache.proto.request.module.StorageDataType; import org.prebid.server.cache.proto.response.module.ModuleCacheResponse; import org.prebid.server.exception.PreBidException; import org.prebid.server.util.HttpUtil; @@ -31,16 +31,16 @@ import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) -public class BasicModuleCacheServiceTest extends VertxTest { +public class BasicPbcStorageServiceTest extends VertxTest { @Mock(strictness = LENIENT) private HttpClient httpClient; - private BasicModuleCacheService target; + private BasicPbcStorageService target; @BeforeEach public void setUp() throws MalformedURLException, JsonProcessingException { - target = new BasicModuleCacheService( + target = new BasicPbcStorageService( httpClient, new URL("http://cache-service/cache"), "pbc-api-key", @@ -51,15 +51,15 @@ public void setUp() throws MalformedURLException, JsonProcessingException { HttpClientResponse.of(200, null, "someBody"))); given(httpClient.get(anyString(), any(), anyLong())).willReturn(Future.succeededFuture( HttpClientResponse.of(200, null, mapper.writeValueAsString( - ModuleCacheResponse.of("some-key", ModuleCacheType.JSON, "some-value"))))); + ModuleCacheResponse.of("some-key", StorageDataType.JSON, "some-value"))))); } @Test public void storeModuleEntryShouldStoreExpectedKey() { // when - target.storeModuleEntry("some-key", + target.storeEntry("some-key", "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", "some-module-code"); @@ -72,9 +72,9 @@ public void storeModuleEntryShouldStoreExpectedKey() { @Test public void storeModuleEntryShouldStoreExpectedValue() { // when - target.storeModuleEntry("some-key", + target.storeEntry("some-key", "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", "some-module-code"); @@ -87,9 +87,9 @@ public void storeModuleEntryShouldStoreExpectedValue() { @Test public void storeModuleEntryShouldStoreExpectedApplication() { // when - target.storeModuleEntry("some-key", + target.storeEntry("some-key", "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", "some-module-code"); @@ -102,24 +102,24 @@ public void storeModuleEntryShouldStoreExpectedApplication() { @Test public void storeModuleEntryShouldStoreExpectedMediaType() { // when - target.storeModuleEntry("some-key", + target.storeEntry("some-key", "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", "some-module-code"); // then final ModuleCacheRequest result = captureModuleCacheRequest(); - assertThat(result.getType()).isEqualTo(ModuleCacheType.TEXT); + assertThat(result.getType()).isEqualTo(StorageDataType.TEXT); } @Test public void storeModuleEntryShouldStoreExpectedTtl() { // when - target.storeModuleEntry("some-key", + target.storeEntry("some-key", "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", "some-module-code"); @@ -130,11 +130,11 @@ public void storeModuleEntryShouldStoreExpectedTtl() { } @Test - public void storeModuleEntryShouldReturnFailedFutureIfKeyIsMissed() { + public void storeEntryShouldReturnFailedFutureIfKeyIsMissed() { // when - final Future result = target.storeModuleEntry(null, + final Future result = target.storeEntry(null, "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", "some-module-code"); @@ -146,11 +146,11 @@ public void storeModuleEntryShouldReturnFailedFutureIfKeyIsMissed() { } @Test - public void storeModuleEntryShouldReturnFailedFutureIfValueIsMissed() { + public void storeEntryShouldReturnFailedFutureIfValueIsMissed() { // when - final Future result = target.storeModuleEntry("some-key", + final Future result = target.storeEntry("some-key", null, - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", "some-module-code"); @@ -162,11 +162,11 @@ public void storeModuleEntryShouldReturnFailedFutureIfValueIsMissed() { } @Test - public void storeModuleEntryShouldReturnFailedFutureIfApplicationIsMissed() { + public void storeEntryShouldReturnFailedFutureIfApplicationIsMissed() { // when - final Future result = target.storeModuleEntry("some-key", + final Future result = target.storeEntry("some-key", "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, null, "some-module-code"); @@ -178,9 +178,9 @@ public void storeModuleEntryShouldReturnFailedFutureIfApplicationIsMissed() { } @Test - public void storeModuleEntryShouldReturnFailedFutureIfTypeIsMissed() { + public void storeEntryShouldReturnFailedFutureIfTypeIsMissed() { // when - final Future result = target.storeModuleEntry("some-key", + final Future result = target.storeEntry("some-key", "some-value", null, 12, @@ -194,11 +194,11 @@ public void storeModuleEntryShouldReturnFailedFutureIfTypeIsMissed() { } @Test - public void storeModuleEntryShouldReturnFailedFutureIfModuleCodeIsMissed() { + public void storeModuleEntryShouldReturnFailedFutureIfCodeIsMissed() { // when - final Future result = target.storeModuleEntry("some-key", + final Future result = target.storeEntry("some-key", "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", null); @@ -210,11 +210,11 @@ public void storeModuleEntryShouldReturnFailedFutureIfModuleCodeIsMissed() { } @Test - public void storeModuleEntryShouldCreateCallWithApiKeyInHeader() { + public void storeEntryShouldCreateCallWithApiKeyInHeader() { // when - target.storeModuleEntry("some-key", + target.storeEntry("some-key", "some-value", - ModuleCacheType.TEXT, + StorageDataType.TEXT, 12, "some-application", "some-module-code"); @@ -289,7 +289,7 @@ public void retrieveModuleEntryShouldReturnExpectedResponse() { // then assertThat(result.result()) - .isEqualTo(ModuleCacheResponse.of("some-key", ModuleCacheType.JSON, "some-value")); + .isEqualTo(ModuleCacheResponse.of("some-key", StorageDataType.JSON, "some-value")); } @SneakyThrows