99from UnleashClient .utils import LOGGER
1010
1111
12+ def split_and_strip (parameters : str ):
13+ return [
14+ x .strip () for x in parameters .split (',' )
15+ ]
16+
17+
1218class FeatureToggles :
1319 __client = None
1420 __url = None
@@ -208,6 +214,29 @@ def is_enabled_for_expert(feature_name: str,
208214 return FeatureToggles .__get_unleash_client ().is_enabled (feature_name ,
209215 context )
210216
217+ @staticmethod
218+ def is_enabled_for_team (feature_name : str ,
219+ team_id : Optional [int ] = None ):
220+ """
221+ Util method to check whether given feature is enabled or not
222+ Args:
223+ feature_name(str): feature name
224+ team_id(Optional[str]): list of team IDs
225+ Returns:
226+ (bool): True if feature is enabled else False
227+ """
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+ )
239+
211240 @staticmethod
212241 def fetch_feature_toggles ():
213242 """
@@ -247,6 +276,7 @@ def fetch_feature_toggles():
247276 partner_names = []
248277 business_via_names = []
249278 expert_emails = []
279+ team_ids = []
250280
251281 if cas_name == FeatureToggles .__cas_name and environment == FeatureToggles .__environment :
252282 # Strip CAS and ENV name from feature name
@@ -260,14 +290,15 @@ def fetch_feature_toggles():
260290 strategy_name = strategy .get ('name' , '' )
261291 parameters = strategy .get ('parameters' , {})
262292 if strategy_name == 'EnableForPartners' :
263- partner_names = parameters .get ('partner_names' , '' ).replace (', ' , ',' ).split (',' )
264-
293+ partner_names = split_and_strip (parameters .get ('partner_names' , '' ))
265294 elif strategy_name == 'EnableForBusinesses' :
266- business_via_names = parameters .get ('business_via_names' , '' ). replace ( ', ' , ',' ). split ( ',' )
295+ business_via_names = split_and_strip ( parameters .get ('business_via_names' , '' ))
267296 elif strategy_name == 'EnableForDomains' :
268- domain_names = parameters .get ('domain_names' , '' ). replace ( ', ' , ',' ). split ( ',' )
297+ domain_names = split_and_strip ( parameters .get ('domain_names' , '' ))
269298 elif strategy_name == 'EnableForExperts' :
270- expert_emails = parameters .get ('expert_emails' , '' ).replace (', ' , ',' ).split (',' )
299+ expert_emails = split_and_strip (parameters .get ('expert_emails' , '' ))
300+ elif strategy_name == 'EnableForTeams' :
301+ team_ids = split_and_strip (parameters .get ('team_ids' , '' ))
271302
272303 # Keep updating this list for new strategies which gets added
273304
@@ -276,8 +307,9 @@ def fetch_feature_toggles():
276307 response [full_feature_name ]['business_via_names' ] = business_via_names
277308 response [full_feature_name ]['domain_names' ] = domain_names
278309 response [full_feature_name ]['expert_emails' ] = expert_emails
310+ response [full_feature_name ]['team_ids' ] = team_ids
279311 except Exception as err :
280312 # Handle this exception from where this util gets called
281- raise Exception (f'Error occured while parsing the response: { str (err )} ' )
313+ raise Exception (f'An error occurred while parsing the response: { str (err )} ' )
282314
283- return response
315+ return response
0 commit comments