Skip to content

Commit 429e083

Browse files
Parity commit
1 parent 5d5f882 commit 429e083

File tree

112 files changed

+75
-732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+75
-732
lines changed

FeatureToggle/__init__.py

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from UnleashClient import constants as consts
88
from UnleashClient import UnleashClient
99
from UnleashClient.utils import LOGGER
10-
from FeatureToggle.utils import timed_lru_cache
1110

1211

1312
def split_and_strip(parameters: str):
@@ -51,7 +50,6 @@ def initialize(url: str,
5150
FeatureToggles.__redis_db = redis_db
5251
FeatureToggles.__enable_toggle_service = enable_toggle_service
5352
FeatureToggles.__cache = FeatureToggles.__get_cache()
54-
LOGGER.info(f'Initializing Feature toggles')
5553
else:
5654
raise Exception("Client has been already initialized")
5755

@@ -90,9 +88,9 @@ def update_cache(data: Dict[str, Any]) -> None:
9088
)
9189
except Exception as err:
9290
raise Exception(
93-
f'Exception occurred while updating the redis cache: {str(err)}'
91+
f'Exception occured while updating the redis cache: {str(err)}'
9492
)
95-
LOGGER.info(f'[Feature Toggles] Cache Updated')
93+
LOGGER.info(f'Cache Updatation is Done')
9694

9795
@staticmethod
9896
def __get_unleash_client():
@@ -147,8 +145,14 @@ def is_enabled_for_domain(feature_name: str,
147145
Returns:
148146
(bool): True if Feature is enabled else False
149147
"""
150-
feature_toggles = FeatureToggles.fetch_feature_toggles()
151-
return domain_name in feature_toggles.get(feature_name, {}).get('domain_names', [])
148+
feature_name = FeatureToggles.__get_full_feature_name(feature_name)
149+
150+
context = {}
151+
if domain_name:
152+
context['domain_names'] = domain_name
153+
154+
return FeatureToggles.__get_unleash_client().is_enabled(feature_name,
155+
context)
152156

153157
@staticmethod
154158
def is_enabled_for_partner(feature_name: str,
@@ -161,8 +165,14 @@ def is_enabled_for_partner(feature_name: str,
161165
Returns:
162166
(bool): True if Feature is enabled else False
163167
"""
164-
feature_toggles = FeatureToggles.fetch_feature_toggles()
165-
return partner_name in feature_toggles.get(feature_name, {}).get('partner_names', [])
168+
feature_name = FeatureToggles.__get_full_feature_name(feature_name)
169+
170+
context = {}
171+
if partner_name:
172+
context['partner_names'] = partner_name
173+
174+
return FeatureToggles.__get_unleash_client().is_enabled(feature_name,
175+
context)
166176

167177
@staticmethod
168178
def is_enabled_for_business(feature_name: str,
@@ -175,8 +185,14 @@ def is_enabled_for_business(feature_name: str,
175185
Returns:
176186
(bool): True if Feature is enabled else False
177187
"""
178-
feature_toggles = FeatureToggles.fetch_feature_toggles()
179-
return business_via_name in feature_toggles.get(feature_name, {}).get('business_via_names', [])
188+
feature_name = FeatureToggles.__get_full_feature_name(feature_name)
189+
190+
context = {}
191+
if business_via_name:
192+
context['business_via_names'] = business_via_name
193+
194+
return FeatureToggles.__get_unleash_client().is_enabled(feature_name,
195+
context)
180196

181197
@staticmethod
182198
def is_enabled_for_expert(feature_name: str,
@@ -189,8 +205,14 @@ def is_enabled_for_expert(feature_name: str,
189205
Returns:
190206
(bool): True if Feature is enabled else False
191207
"""
192-
feature_toggles = FeatureToggles.fetch_feature_toggles()
193-
return expert_email in feature_toggles.get(feature_name, {}).get('expert_emails', [])
208+
feature_name = FeatureToggles.__get_full_feature_name(feature_name)
209+
210+
context = {}
211+
if expert_email:
212+
context['expert_emails'] = expert_email
213+
214+
return FeatureToggles.__get_unleash_client().is_enabled(feature_name,
215+
context)
194216

195217
@staticmethod
196218
def is_enabled_for_team(feature_name: str,
@@ -203,11 +225,19 @@ def is_enabled_for_team(feature_name: str,
203225
Returns:
204226
(bool): True if feature is enabled else False
205227
"""
206-
feature_toggles = FeatureToggles.fetch_feature_toggles()
207-
return team_id in feature_toggles.get(feature_name, {}).get('team_ids', [])
228+
feature_name = FeatureToggles.__get_full_feature_name(feature_name)
229+
230+
context = {}
231+
if team_id:
232+
context['team_ids'] = team_id
233+
234+
return (
235+
FeatureToggles
236+
.__get_unleash_client()
237+
.is_enabled(feature_name, context)
238+
)
208239

209240
@staticmethod
210-
@timed_lru_cache(seconds=(60*60), maxsize=2048)
211241
def fetch_feature_toggles():
212242
"""
213243
Returns(Dict):
@@ -221,7 +251,7 @@ def fetch_feature_toggles():
221251
}
222252
"""
223253
# TODO: Remove the cas and environment name from the feature toggles while returning the response
224-
LOGGER.info(f'Loading Feature Toggles from Redis')
254+
225255
if FeatureToggles.__cache is None:
226256
raise Exception(
227257
'To update cache Feature Toggles class needs to be initialised'
@@ -281,4 +311,5 @@ def fetch_feature_toggles():
281311
except Exception as err:
282312
# Handle this exception from where this util gets called
283313
raise Exception(f'An error occurred while parsing the response: {str(err)}')
314+
284315
return response

FeatureToggle/utils.py

Lines changed: 0 additions & 23 deletions
This file was deleted.
File renamed without changes.

unleash-client-python/UnleashClient/__init__.py renamed to UnleashClient/__init__.py

File renamed without changes.

unleash-client-python/UnleashClient/api/__init__.py renamed to UnleashClient/api/__init__.py

File renamed without changes.

unleash-client-python/UnleashClient/api/features.py renamed to UnleashClient/api/features.py

File renamed without changes.

0 commit comments

Comments
 (0)