Skip to content

Commit a7e1f7b

Browse files
madgaetgreyners
andauthored
feat: Add support for http protocols option with flagsmith client (#950)
Signed-off-by: Reyners Gaëtan <[email protected]> Co-authored-by: Reyners Gaëtan <[email protected]>
1 parent a1991bd commit a7e1f7b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

Diff for: providers/flagsmith/src/main/java/dev.openfeature.contrib.providers.flagsmith/FlagsmithClientConfigurer.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.flagsmith.FlagsmithClient;
44
import com.flagsmith.config.FlagsmithCacheConfig;
5+
import com.flagsmith.config.FlagsmithConfig;
56
import com.flagsmith.config.Retry;
67
import dev.openfeature.contrib.providers.flagsmith.exceptions.InvalidCacheOptionsException;
78
import dev.openfeature.contrib.providers.flagsmith.exceptions.InvalidOptionsException;
@@ -35,7 +36,7 @@ static FlagsmithClient initializeProvider(FlagsmithProviderOptions options) {
3536
flagsmithBuilder.withCache(flagsmithCacheConfig);
3637
}
3738

38-
com.flagsmith.config.FlagsmithConfig flagsmithConfig = initializeConfig(options);
39+
final FlagsmithConfig flagsmithConfig = initializeConfig(options);
3940
flagsmithBuilder.withConfiguration(flagsmithConfig);
4041

4142
return flagsmithBuilder.build();
@@ -88,10 +89,8 @@ private static FlagsmithCacheConfig initializeCacheConfig(FlagsmithProviderOptio
8889
* @param options The options used to create the provider
8990
* @return a FlagsmithConfig object with the FlagsmithClient settings
9091
*/
91-
private static com.flagsmith.config.FlagsmithConfig initializeConfig(
92-
FlagsmithProviderOptions options) {
93-
com.flagsmith.config.FlagsmithConfig.Builder flagsmithConfig = com.flagsmith.config.FlagsmithConfig
94-
.newBuilder();
92+
private static FlagsmithConfig initializeConfig(FlagsmithProviderOptions options) {
93+
FlagsmithConfig.Builder flagsmithConfig = FlagsmithConfig.newBuilder();
9594

9695
// Set client level configuration settings
9796
if (options.getBaseUri() != null) {
@@ -136,6 +135,10 @@ private static com.flagsmith.config.FlagsmithConfig initializeConfig(
136135
flagsmithConfig.withEnableAnalytics(options.isEnableAnalytics());
137136
}
138137

138+
if (options.getSupportedProtocols() != null && !options.getSupportedProtocols().isEmpty()) {
139+
flagsmithConfig.withSupportedProtocols(options.getSupportedProtocols());
140+
}
141+
139142
return flagsmithConfig.build();
140143
}
141144

Diff for: providers/flagsmith/src/main/java/dev.openfeature.contrib.providers.flagsmith/FlagsmithProviderOptions.java

+13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
44

5+
import com.flagsmith.config.FlagsmithConfig.Protocol;
6+
import java.util.Arrays;
57
import java.util.HashMap;
8+
import java.util.List;
69
import java.util.concurrent.TimeUnit;
10+
import java.util.stream.Collectors;
11+
712
import lombok.Builder;
813
import lombok.Getter;
914
import javax.net.ssl.SSLSocketFactory;
@@ -183,4 +188,12 @@ public class FlagsmithProviderOptions {
183188
*/
184189
@Builder.Default
185190
private boolean usingBooleanConfigValue = false;
191+
192+
/**
193+
* Set the list of supported protocols that should be used.
194+
* Optional.
195+
* Default: All the enum protocols from FlagsmithConfig.
196+
*/
197+
@Builder.Default
198+
private List<Protocol> supportedProtocols = Arrays.stream(Protocol.values()).collect(Collectors.toList());
186199
}

Diff for: providers/flagsmith/src/test/java/dev.openfeature.contrib.providers.flagsmith/FlagsmithProviderTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.flagsmith.config.FlagsmithConfig;
56
import dev.openfeature.contrib.providers.flagsmith.exceptions.InvalidCacheOptionsException;
67
import dev.openfeature.contrib.providers.flagsmith.exceptions.InvalidOptionsException;
78
import dev.openfeature.sdk.EvaluationContext;
@@ -16,6 +17,8 @@
1617
import java.lang.reflect.Method;
1718
import java.nio.file.Files;
1819
import java.nio.file.Paths;
20+
import java.util.Arrays;
21+
import java.util.Collections;
1922
import java.util.HashMap;
2023
import java.util.Map;
2124
import java.util.concurrent.TimeUnit;
@@ -191,6 +194,7 @@ void shouldInitializeProviderWhenAllOptionsSet() {
191194
.environmentRefreshIntervalSeconds(1)
192195
.enableAnalytics(true)
193196
.usingBooleanConfigValue(false)
197+
.supportedProtocols(Collections.singletonList(FlagsmithConfig.Protocol.HTTP_1_1))
194198
.build();
195199
assertDoesNotThrow(() -> new FlagsmithProvider(options));
196200
}

0 commit comments

Comments
 (0)