@@ -114,13 +114,15 @@ def get_configuration(self) -> Dict[str, Any]:
114
114
self ._schema_validator .validate_json_schema (schema )
115
115
return schema
116
116
117
- def get_feature_toggle (self , * , feature_name : str , rules_context : Dict [str , Any ], value_if_missing : bool ) -> bool :
117
+ def get_feature_toggle (
118
+ self , * , feature_name : str , rules_context : Optional [Dict [str , Any ]] = None , value_if_missing : bool
119
+ ) -> bool :
118
120
"""get a feature toggle boolean value. Value is calculated according to a set of rules and conditions.
119
121
see below for explanation.
120
122
121
123
Args:
122
124
feature_name (str): feature name that you wish to fetch
123
- rules_context (Dict[str, Any]): dict of attributes that you would like to match the rules
125
+ rules_context (Optional[ Dict[str, Any] ]): dict of attributes that you would like to match the rules
124
126
against, can be {'tenant_id: 'X', 'username':' 'Y', 'region': 'Z'} etc.
125
127
value_if_missing (bool): this will be the returned value in case the feature toggle doesn't exist in
126
128
the schema or there has been an error while fetching the
@@ -134,6 +136,9 @@ def get_feature_toggle(self, *, feature_name: str, rules_context: Dict[str, Any]
134
136
the defined feature
135
137
3. feature exists and a rule matches -> rule_default_value of rule is returned
136
138
"""
139
+ if rules_context is None :
140
+ rules_context = {}
141
+
137
142
try :
138
143
toggles_dict : Dict [str , Any ] = self .get_configuration ()
139
144
except ConfigurationException :
@@ -166,17 +171,19 @@ def get_feature_toggle(self, *, feature_name: str, rules_context: Dict[str, Any]
166
171
rules = rules_list ,
167
172
)
168
173
169
- def get_all_enabled_feature_toggles (self , * , rules_context : Dict [str , Any ]) -> List [str ]:
174
+ def get_all_enabled_feature_toggles (self , * , rules_context : Optional [ Dict [str , Any ]] = None ) -> List [str ]:
170
175
"""Get all enabled feature toggles while also taking into account rule_context (when a feature has defined rules)
171
176
172
177
Args:
173
- rules_context (Dict[str, Any]): dict of attributes that you would like to match the rules
178
+ rules_context (Optional[ Dict[str, Any] ]): dict of attributes that you would like to match the rules
174
179
against, can be {'tenant_id: 'X', 'username':' 'Y', 'region': 'Z'} etc.
175
180
176
181
Returns:
177
182
List[str]: a list of all features name that are enabled by also taking into account
178
183
rule_context (when a feature has defined rules)
179
184
"""
185
+ if rules_context is None :
186
+ rules_context = {}
180
187
try :
181
188
toggles_dict : Dict [str , Any ] = self .get_configuration ()
182
189
except ConfigurationException :
0 commit comments