Skip to content

Commit 52a2967

Browse files
committed
Removed FallbackConfig object and updated config parameter name
1 parent 5da06df commit 52a2967

File tree

6 files changed

+55
-81
lines changed

6 files changed

+55
-81
lines changed

splitio/client/config.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from splitio.engine.impressions import ImpressionsMode
77
from splitio.client.input_validator import validate_flag_sets, validate_fallback_treatment, validate_regex_name
8-
from splitio.models.fallback_config import FallbackConfig, FallbackTreatmentsConfiguration
8+
from splitio.models.fallback_config import FallbackTreatmentsConfiguration
99

1010
_LOGGER = logging.getLogger(__name__)
1111
DEFAULT_DATA_SAMPLING = 1
@@ -71,7 +71,7 @@ class AuthenticateScheme(Enum):
7171
'httpAuthenticateScheme': AuthenticateScheme.NONE,
7272
'kerberosPrincipalUser': None,
7373
'kerberosPrincipalPassword': None,
74-
'fallbackTreatmentsConfiguration': FallbackTreatmentsConfiguration(None)
74+
'fallbackTreatments': FallbackTreatmentsConfiguration(None)
7575
}
7676

7777
def _parse_operation_mode(sdk_key, config):
@@ -175,32 +175,26 @@ def sanitize(sdk_key, config):
175175
return processed
176176

177177
def _sanitize_fallback_config(config, processed):
178-
if config.get('fallbackTreatmentsConfiguration') is not None:
179-
if not isinstance(config['fallbackTreatmentsConfiguration'], FallbackTreatmentsConfiguration):
180-
_LOGGER.warning('Config: fallbackTreatmentsConfiguration parameter should be of `FallbackTreatmentsConfiguration` class.')
181-
processed['fallbackTreatmentsConfiguration'] = FallbackTreatmentsConfiguration(None)
178+
if config.get('fallbackTreatments') is not None:
179+
if not isinstance(config['fallbackTreatments'], FallbackTreatmentsConfiguration):
180+
_LOGGER.warning('Config: fallbackTreatments parameter should be of `FallbackTreatmentsConfiguration` class.')
181+
processed['fallbackTreatments'] = None
182182
return processed
183-
184-
if config['fallbackTreatmentsConfiguration'].fallback_config != None:
185-
if not isinstance(config['fallbackTreatmentsConfiguration'].fallback_config, FallbackConfig):
186-
_LOGGER.warning('Config: fallback_config parameter should be of `FallbackConfig` class.')
187-
processed['fallbackTreatmentsConfiguration'].fallback_config = FallbackConfig(None, None)
188-
return processed
189-
190-
if config['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment is not None and not validate_fallback_treatment(config['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment):
191-
_LOGGER.warning('Config: global fallbacktreatment parameter is discarded.')
192-
processed['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment = None
193-
return processed
194-
195-
if config['fallbackTreatmentsConfiguration'].fallback_config.by_flag_fallback_treatment is not None:
196-
sanitized_flag_fallback_treatments = {}
197-
for feature_name in config['fallbackTreatmentsConfiguration'].fallback_config.by_flag_fallback_treatment.keys():
198-
if not validate_regex_name(feature_name) or not validate_fallback_treatment(config['fallbackTreatmentsConfiguration'].fallback_config.by_flag_fallback_treatment[feature_name]):
199-
_LOGGER.warning('Config: fallback treatment parameter for feature flag %s is discarded.', feature_name)
200-
continue
201-
202-
sanitized_flag_fallback_treatments[feature_name] = config['fallbackTreatmentsConfiguration'].fallback_config.by_flag_fallback_treatment[feature_name]
203-
204-
processed['fallbackTreatmentsConfiguration'].fallback_config = FallbackConfig(config['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment, sanitized_flag_fallback_treatments)
205-
183+
184+
sanitized_global_fallback_treatment = config['fallbackTreatments'].global_fallback_treatment
185+
if config['fallbackTreatments'].global_fallback_treatment is not None and not validate_fallback_treatment(config['fallbackTreatments'].global_fallback_treatment):
186+
_LOGGER.warning('Config: global fallbacktreatment parameter is discarded.')
187+
sanitized_global_fallback_treatment = None
188+
189+
sanitized_flag_fallback_treatments = {}
190+
if config['fallbackTreatments'].by_flag_fallback_treatment is not None:
191+
for feature_name in config['fallbackTreatments'].by_flag_fallback_treatment.keys():
192+
if not validate_regex_name(feature_name) or not validate_fallback_treatment(config['fallbackTreatments'].by_flag_fallback_treatment[feature_name]):
193+
_LOGGER.warning('Config: fallback treatment parameter for feature flag %s is discarded.', feature_name)
194+
continue
195+
196+
sanitized_flag_fallback_treatments[feature_name] = config['fallbackTreatments'].by_flag_fallback_treatment[feature_name]
197+
198+
processed['fallbackTreatments'] = FallbackTreatmentsConfiguration(sanitized_global_fallback_treatment, sanitized_flag_fallback_treatments)
199+
206200
return processed

splitio/client/input_validator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from splitio.client.key import Key
99
from splitio.client import client
1010
from splitio.engine.evaluator import CONTROL
11+
from splitio.models.fallback_treatment import FallbackTreatment
1112

1213

1314
_LOGGER = logging.getLogger(__name__)
@@ -715,6 +716,10 @@ def validate_flag_sets(flag_sets, method_name):
715716
return list(sanitized_flag_sets)
716717

717718
def validate_fallback_treatment(fallback_treatment):
719+
if not isinstance(fallback_treatment, FallbackTreatment):
720+
_LOGGER.warning("Config: Fallback treatment instance should be FallbackTreatment, input is discarded")
721+
return False
722+
718723
if not validate_regex_name(fallback_treatment.treatment):
719724
_LOGGER.warning("Config: Fallback treatment should match regex %s", _FALLBACK_TREATMENT_REGEX)
720725
return False

splitio/models/fallback_config.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
11
"""Segment module."""
22

33
class FallbackTreatmentsConfiguration(object):
4-
"""FallbackConfiguration object class."""
5-
6-
def __init__(self, fallback_config):
7-
"""
8-
Class constructor.
9-
10-
:param fallback_config: fallback config object.
11-
:type fallback_config: FallbackConfig
12-
13-
:param by_flag_fallback_treatment: Dict of flags and their fallback treatment
14-
:type by_flag_fallback_treatment: {str: FallbackTreatment}
15-
"""
16-
self._fallback_config = fallback_config
17-
18-
@property
19-
def fallback_config(self):
20-
"""Return fallback config."""
21-
return self._fallback_config
22-
23-
@fallback_config.setter
24-
def fallback_config(self, new_value):
25-
"""Set fallback config."""
26-
self._fallback_config = new_value
27-
28-
class FallbackConfig(object):
29-
"""FallbackConfig object class."""
4+
"""FallbackTreatmentsConfiguration object class."""
305

316
def __init__(self, global_fallback_treatment=None, by_flag_fallback_treatment=None):
327
"""

splitio/models/fallback_treatment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33

44
class FallbackTreatment(object):
5-
"""Segment object class."""
5+
"""FallbackTreatment object class."""
66

77
def __init__(self, treatment, config=None):
88
"""

tests/client/test_config.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from splitio.client import config
55
from splitio.engine.impressions.impressions import ImpressionsMode
66
from splitio.models.fallback_treatment import FallbackTreatment
7-
from splitio.models.fallback_config import FallbackConfig, FallbackTreatmentsConfiguration
7+
from splitio.models.fallback_config import FallbackTreatmentsConfiguration
88

99
class ConfigSanitizationTests(object):
1010
"""Inmemory storage-based integration tests."""
@@ -92,34 +92,34 @@ def test_sanitize(self, mocker):
9292
assert processed['httpAuthenticateScheme'] is config.AuthenticateScheme.NONE
9393

9494
_logger.reset_mock()
95-
processed = config.sanitize('some', {'fallbackTreatmentsConfiguration': 'NONE'})
96-
assert processed['fallbackTreatmentsConfiguration'].fallback_config == None
97-
assert _logger.warning.mock_calls[1] == mocker.call("Config: fallbackTreatmentsConfiguration parameter should be of `FallbackTreatmentsConfiguration` class.")
95+
processed = config.sanitize('some', {'fallbackTreatments': 'NONE'})
96+
assert processed['fallbackTreatments'] == None
97+
assert _logger.warning.mock_calls[1] == mocker.call("Config: fallbackTreatments parameter should be of `FallbackTreatmentsConfiguration` class.")
9898

9999
_logger.reset_mock()
100-
processed = config.sanitize('some', {'fallbackTreatmentsConfiguration': FallbackTreatmentsConfiguration(123)})
101-
assert processed['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment == None
102-
assert _logger.warning.mock_calls[1] == mocker.call("Config: fallback_config parameter should be of `FallbackConfig` class.")
100+
processed = config.sanitize('some', {'fallbackTreatments': FallbackTreatmentsConfiguration(123)})
101+
assert processed['fallbackTreatments'].global_fallback_treatment == None
102+
assert _logger.warning.mock_calls[1] == mocker.call("Config: global fallbacktreatment parameter is discarded.")
103103

104104
_logger.reset_mock()
105-
processed = config.sanitize('some', {'fallbackTreatmentsConfiguration': FallbackTreatmentsConfiguration(FallbackConfig(FallbackTreatment("123")))})
106-
assert processed['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment == None
105+
processed = config.sanitize('some', {'fallbackTreatments': FallbackTreatmentsConfiguration(FallbackTreatment("123"))})
106+
assert processed['fallbackTreatments'].global_fallback_treatment == None
107107
assert _logger.warning.mock_calls[1] == mocker.call("Config: global fallbacktreatment parameter is discarded.")
108108

109-
fb = FallbackTreatmentsConfiguration(FallbackConfig(FallbackTreatment('on')))
110-
processed = config.sanitize('some', {'fallbackTreatmentsConfiguration': fb})
111-
assert processed['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment.treatment == fb.fallback_config.global_fallback_treatment.treatment
112-
assert processed['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment.label_prefix == "fallback - "
109+
fb = FallbackTreatmentsConfiguration(FallbackTreatment('on'))
110+
processed = config.sanitize('some', {'fallbackTreatments': fb})
111+
assert processed['fallbackTreatments'].global_fallback_treatment.treatment == fb.global_fallback_treatment.treatment
112+
assert processed['fallbackTreatments'].global_fallback_treatment.label_prefix == "fallback - "
113113

114-
fb = FallbackTreatmentsConfiguration(FallbackConfig(FallbackTreatment('on'), {"flag": FallbackTreatment("off")}))
115-
processed = config.sanitize('some', {'fallbackTreatmentsConfiguration': fb})
116-
assert processed['fallbackTreatmentsConfiguration'].fallback_config.global_fallback_treatment.treatment == fb.fallback_config.global_fallback_treatment.treatment
117-
assert processed['fallbackTreatmentsConfiguration'].fallback_config.by_flag_fallback_treatment["flag"] == fb.fallback_config.by_flag_fallback_treatment["flag"]
118-
assert processed['fallbackTreatmentsConfiguration'].fallback_config.by_flag_fallback_treatment["flag"].label_prefix == "fallback - "
114+
fb = FallbackTreatmentsConfiguration(FallbackTreatment('on'), {"flag": FallbackTreatment("off")})
115+
processed = config.sanitize('some', {'fallbackTreatments': fb})
116+
assert processed['fallbackTreatments'].global_fallback_treatment.treatment == fb.global_fallback_treatment.treatment
117+
assert processed['fallbackTreatments'].by_flag_fallback_treatment["flag"] == fb.by_flag_fallback_treatment["flag"]
118+
assert processed['fallbackTreatments'].by_flag_fallback_treatment["flag"].label_prefix == "fallback - "
119119

120120
_logger.reset_mock()
121-
fb = FallbackTreatmentsConfiguration(FallbackConfig(None, {"flag#%": FallbackTreatment("off"), "flag2": FallbackTreatment("on")}))
122-
processed = config.sanitize('some', {'fallbackTreatmentsConfiguration': fb})
123-
assert len(processed['fallbackTreatmentsConfiguration'].fallback_config.by_flag_fallback_treatment) == 1
124-
assert processed['fallbackTreatmentsConfiguration'].fallback_config.by_flag_fallback_treatment.get("flag2") == fb.fallback_config.by_flag_fallback_treatment["flag2"]
121+
fb = FallbackTreatmentsConfiguration(None, {"flag#%": FallbackTreatment("off"), "flag2": FallbackTreatment("on")})
122+
processed = config.sanitize('some', {'fallbackTreatments': fb})
123+
assert len(processed['fallbackTreatments'].by_flag_fallback_treatment) == 1
124+
assert processed['fallbackTreatments'].by_flag_fallback_treatment.get("flag2") == fb.by_flag_fallback_treatment["flag2"]
125125
assert _logger.warning.mock_calls[1] == mocker.call('Config: fallback treatment parameter for feature flag %s is discarded.', 'flag#%')

tests/models/test_fallback.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from splitio.models.fallback_treatment import FallbackTreatment
2-
from splitio.models.fallback_config import FallbackConfig
2+
from splitio.models.fallback_config import FallbackTreatmentsConfiguration
33

44
class FallbackTreatmentModelTests(object):
55
"""Fallback treatment model tests."""
@@ -13,13 +13,13 @@ def test_working(self):
1313
assert fallback_treatment.config == None
1414
assert fallback_treatment.treatment == 'off'
1515

16-
class FallbackConfigModelTests(object):
16+
class FallbackTreatmentsConfigModelTests(object):
1717
"""Fallback treatment model tests."""
1818

1919
def test_working(self):
2020
global_fb = FallbackTreatment("on")
2121
flag_fb = FallbackTreatment("off")
22-
fallback_config = FallbackConfig(global_fb, {"flag1": flag_fb})
22+
fallback_config = FallbackTreatmentsConfiguration(global_fb, {"flag1": flag_fb})
2323
assert fallback_config.global_fallback_treatment == global_fb
2424
assert fallback_config.by_flag_fallback_treatment == {"flag1": flag_fb}
2525

0 commit comments

Comments
 (0)