diff --git a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/RedisConfig.java b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/RedisConfig.java index 75163aacf807903e9656c3888abe7c0b1389b3e8..66f768012912c207eb97eb3dcf15b6c0058cf00f 100644 --- a/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/RedisConfig.java +++ b/provider/partition-azure/src/main/java/org/opengroup/osdu/partition/provider/azure/di/RedisConfig.java @@ -1,10 +1,7 @@ package org.opengroup.osdu.partition.provider.azure.di; -import com.azure.security.keyvault.secrets.SecretClient; -import com.lambdaworks.redis.ClientOptions; -import com.lambdaworks.redis.SocketOptions; -import org.opengroup.osdu.azure.KeyVaultFacade; -import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.azure.cache.RedisAzureCache; +import org.opengroup.osdu.azure.di.RedisAzureConfiguration; import org.opengroup.osdu.partition.model.PartitionInfo; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -13,88 +10,30 @@ import org.springframework.context.annotation.Configuration; import javax.inject.Named; import java.util.List; -import java.util.concurrent.TimeUnit; @Configuration public class RedisConfig { + @Value("${redis.port}") + private int port; - @Bean - @Named("REDIS_HOST") - public String redisHost(SecretClient kv) { - return KeyVaultFacade.getSecretWithValidation(kv, "redis-hostname"); - } - - @Bean - @Named("REDIS_PASSWORD") - public String redisPassword(SecretClient kv) { - return KeyVaultFacade.getSecretWithValidation(kv, "redis-password"); - } - - @Configuration - @ConditionalOnExpression(value = "'${cache.provider}' == 'redis' && '${redis.ssl.enabled:true}'") - static class SslConfig { - - @Value("${redis.port}") - private int port; - - @Value("${redis.expiration}") - private int expiration; - - @Value("${redis.database}") - private int database; - - @Value("${redis.connection.timeout}") - private long timeout; + @Value("${redis.expiration}") + private int expiration; - @Bean - public RedisCache<String, PartitionInfo> partitionServiceCache(@Named("REDIS_HOST") String host, @Named("REDIS_PASSWORD") String password) { - ClientOptions clientOptions = ClientOptions.builder() - .socketOptions(SocketOptions.builder().connectTimeout(timeout, TimeUnit.SECONDS).build()) - .build(); - return new RedisCache<>(host, port, password, expiration, database, clientOptions, String.class, PartitionInfo.class); - } + @Value("${redis.database}") + private int database; - @Bean - public RedisCache<String, List<String>> partitionListCache(@Named("REDIS_HOST") String host, @Named("REDIS_PASSWORD") String password) { - ClientOptions clientOptions = ClientOptions.builder() - .socketOptions(SocketOptions.builder().connectTimeout(timeout, TimeUnit.SECONDS).build()) - .build(); - return new RedisCache(host, port, password, expiration, database, clientOptions, String.class, List.class); - } + @Value("${redis.connection.timeout}") + private long timeout; + @Bean + public RedisAzureCache<String, PartitionInfo> partitionServiceCache() { + RedisAzureConfiguration redisAzureConfiguration = new RedisAzureConfiguration(database, expiration, port, timeout); + return new RedisAzureCache<>(String.class, PartitionInfo.class, redisAzureConfiguration); } - @Configuration - @ConditionalOnExpression(value = "'${cache.provider}' == 'redis' && !'${redis.ssl.enabled:true}'") - static class NoSslConfig { - - @Value("${redis.port}") - private int port; - - @Value("${redis.expiration}") - private int expiration; - - @Value("${redis.database}") - private int database; - - @Value("${redis.connection.timeout}") - private long timeout; - - @Bean - public RedisCache<String, PartitionInfo> partitionServiceCache(@Named("REDIS_HOST") String host) { - ClientOptions clientOptions = ClientOptions.builder() - .socketOptions(SocketOptions.builder().connectTimeout(timeout, TimeUnit.SECONDS).build()) - .build(); - return new RedisCache<>(host, port, expiration, database, clientOptions, String.class, PartitionInfo.class); - } - - @Bean - public RedisCache<String, List<String>> partitionListCache(@Named("REDIS_HOST") String host) { - ClientOptions clientOptions = ClientOptions.builder() - .socketOptions(SocketOptions.builder().connectTimeout(timeout, TimeUnit.SECONDS).build()) - .build(); - return new RedisCache(host, port, expiration, database, clientOptions, String.class, List.class); - } - + @Bean + public RedisAzureCache<String, List<String>> partitionListCache() { + RedisAzureConfiguration redisAzureConfiguration = new RedisAzureConfiguration(database, expiration, port, timeout); + return new RedisAzureCache(String.class, List.class, redisAzureConfiguration); } }