Skip to content

Commit 1f62696

Browse files
committed
refactor(schema): remove 'features' key
1 parent a872814 commit 1f62696

File tree

4 files changed

+302
-375
lines changed

4 files changed

+302
-375
lines changed

aws_lambda_powertools/utilities/feature_flags/feature_flags.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def get_configuration(self) -> Union[Dict[str, Dict], Dict]:
121121
validator = schema.SchemaValidator(schema=config)
122122
validator.validate()
123123

124-
return config.get(schema.FEATURES_KEY, {})
124+
return config
125125

126126
def evaluate(self, *, name: str, context: Optional[Dict[str, Any]] = None, default: bool) -> bool:
127127
"""Get a feature toggle boolean value. Value is calculated according to a set of rules and conditions.
@@ -154,8 +154,8 @@ def evaluate(self, *, name: str, context: Optional[Dict[str, Any]] = None, defau
154154

155155
try:
156156
features = self.get_configuration()
157-
except ConfigurationError:
158-
logger.debug("Unable to get feature toggles JSON, returning provided default value")
157+
except ConfigurationError as err:
158+
logger.debug(f"Unable to get feature toggles JSON, returning provided default value, reason={err}")
159159
return default
160160

161161
feature = features.get(name)
@@ -165,9 +165,9 @@ def evaluate(self, *, name: str, context: Optional[Dict[str, Any]] = None, defau
165165
)
166166
return default
167167

168-
rules_list = feature.get(schema.RULES_KEY)
168+
rules = feature.get(schema.RULES_KEY)
169169
feature_default_value = feature.get(schema.FEATURE_DEFAULT_VAL_KEY)
170-
if not rules_list:
170+
if not rules:
171171
# no rules but value
172172
logger.debug(
173173
f"no rules found, returning feature default value, name={name}, "
@@ -181,7 +181,7 @@ def evaluate(self, *, name: str, context: Optional[Dict[str, Any]] = None, defau
181181
feature_name=name,
182182
context=context,
183183
feature_default_value=bool(feature_default_value),
184-
rules=cast(List, rules_list),
184+
rules=rules,
185185
)
186186

187187
def get_enabled_features(self, *, context: Optional[Dict[str, Any]] = None) -> List[str]:

aws_lambda_powertools/utilities/feature_flags/schema.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
logger = logging.getLogger(__name__)
99

10-
FEATURES_KEY = "features"
1110
RULES_KEY = "rules"
1211
FEATURE_DEFAULT_VAL_KEY = "default"
1312
CONDITIONS_KEY = "conditions"
@@ -30,7 +29,7 @@ def __init__(self, schema: Dict[str, Any]):
3029

3130
def validate(self) -> None:
3231
if not isinstance(self.schema, dict):
33-
raise ConfigurationError(f"Schema must be a dictionary, schema={str(self.schema)}")
32+
raise ConfigurationError(f"Features must be a dictionary, schema={str(self.schema)}")
3433

3534
features = FeaturesValidator(schema=self.schema)
3635
features.validate()
@@ -39,13 +38,9 @@ def validate(self) -> None:
3938
class FeaturesValidator(BaseValidator):
4039
def __init__(self, schema: Dict):
4140
self.schema = schema
42-
self.features: Optional[Dict[str, Dict]] = self.schema.get(FEATURES_KEY)
4341

4442
def validate(self):
45-
if not isinstance(self.features, dict):
46-
raise ConfigurationError(f"'features' key must be a dictionary, schema={self.schema}")
47-
48-
for name, feature in self.features.items():
43+
for name, feature in self.schema.items():
4944
self.validate_feature(name, feature)
5045
rules = RulesValidator(feature=feature)
5146
rules.validate()

0 commit comments

Comments
 (0)