-
Notifications
You must be signed in to change notification settings - Fork 22
Added models and updated config and validator #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
57cac15
Added models and updated config and validator
chillaq 6a74292
Update client/src/main/java/io/split/client/SplitClientConfig.java
chillaq 0ba014e
Update client/src/main/java/io/split/client/dtos/FallbackTreatmentsCo…
chillaq 0815b1a
Update client/src/main/java/io/split/inputValidation/FallbackTreatmen…
chillaq 092207b
polish
chillaq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
client/src/main/java/io/split/client/dtos/FallbackTreatment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package io.split.client.dtos; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class FallbackTreatment { | ||
| private final Map<String, Object> _config; | ||
| private final String _treatment; | ||
| private final String _label; | ||
|
|
||
| public FallbackTreatment(String treatment, Map<String, Object> config) { | ||
| _treatment = treatment; | ||
| _config = config; | ||
| _label = "fallback - "; | ||
| } | ||
|
|
||
| public FallbackTreatment(String treatment) { | ||
| _treatment = treatment; | ||
| _config = null; | ||
| _label = "fallback - "; | ||
| } | ||
|
|
||
| public Map<String, Object> getConfig() { | ||
| return _config; | ||
| } | ||
|
|
||
| public String getTreatment() { | ||
| return _treatment; | ||
| } | ||
|
|
||
| public String getLabel() { | ||
| return _label; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
client/src/main/java/io/split/client/dtos/FallbackTreatmentsConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.split.client.dtos; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class FallbackTreatmentsConfiguration { | ||
| private final FallbackTreatment _globalFallbackTreatment; | ||
| private final Map<String, FallbackTreatment> _byFlagFallbackTreatment; | ||
|
|
||
| public FallbackTreatmentsConfiguration(FallbackTreatment globalFallbackTreatment, Map<String, FallbackTreatment> byFlagFallbackTreatment) { | ||
| _globalFallbackTreatment = globalFallbackTreatment; | ||
| _byFlagFallbackTreatment = byFlagFallbackTreatment; | ||
| } | ||
|
|
||
| public FallbackTreatment getGlobalFallbackTreatment() { | ||
| return _globalFallbackTreatment; | ||
| } | ||
|
|
||
| public Map<String, FallbackTreatment> getByFlagFallbackTreatment() { return _byFlagFallbackTreatment;} | ||
| } |
69 changes: 69 additions & 0 deletions
69
client/src/main/java/io/split/inputValidation/FallbackTreatmentValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package io.split.inputValidation; | ||
|
|
||
| import io.split.client.dtos.FallbackTreatment; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import static io.split.inputValidation.SplitNameValidator.isValid; | ||
|
|
||
| public class FallbackTreatmentValidator { | ||
| private static final Logger _log = LoggerFactory.getLogger(FallbackTreatmentValidator.class); | ||
| private static final Pattern TREATMENT_MATCHER = Pattern.compile("^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$"); | ||
| private static final int MAX_LENGTH = 100; | ||
|
|
||
| public static String isValidTreatment(String name, String method) { | ||
| if (name == null) { | ||
| _log.error(String.format("%s: you passed a null treatment, fallback treatment must be a non-empty string", method)); | ||
| return null; | ||
| } | ||
|
|
||
| if (name.isEmpty()) { | ||
| _log.error(String.format("%s: you passed an empty treatment, fallback treatment must be a non-empty string", method)); | ||
| return null; | ||
| } | ||
|
|
||
| String trimmed = name.trim(); | ||
| if (!trimmed.equals(name)) { | ||
| _log.warn(String.format("%s: fallback treatment %s has extra whitespace, trimming", method, name)); | ||
| name = trimmed; | ||
| } | ||
|
|
||
| if (name.length() > MAX_LENGTH) { | ||
| return null; | ||
| } | ||
|
|
||
| if (!TREATMENT_MATCHER.matcher(name).find()) { | ||
| _log.error(String.format("%s: you passed %s, treatment must adhere to the regular expression " + | ||
| "^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$", method, name)); | ||
| return null; | ||
| } | ||
|
|
||
| return name; | ||
| } | ||
|
|
||
| public static Map<String, FallbackTreatment> isValidByFlagTreatment(Map<String, FallbackTreatment> byFlagTreatment, String method) { | ||
| Map<String, FallbackTreatment> result = new HashMap<>(); | ||
| for (Map.Entry<String, FallbackTreatment> entry : byFlagTreatment.entrySet()) { | ||
| Optional<String> feature_name = isValid(entry.getKey(), "Validator"); | ||
| if (feature_name.equals(Optional.empty())) { | ||
| continue; | ||
| } | ||
|
|
||
| FallbackTreatment fallbackTreatment = entry.getValue(); | ||
| String treatment = isValidTreatment(fallbackTreatment.getTreatment(), "Validator"); | ||
| if (treatment == null) { | ||
| continue; | ||
| } | ||
|
|
||
| result.put(feature_name.get(), new FallbackTreatment(treatment, fallbackTreatment.getConfig())); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.