Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…tools-python into develop

* 'develop' of https://github.com/awslabs/aws-lambda-powertools-python:
  feat(feature_flags): Added inequality conditions (aws-powertools#721)
  fix(feature-flags): rules should evaluate with an AND op (aws-powertools#724)
  fix(logger): push extra keys to the end (aws-powertools#722)
  • Loading branch information
heitorlessa committed Oct 5, 2021
2 parents 6047f6c + 922ecf2 commit d019803
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 10 deletions.
14 changes: 8 additions & 6 deletions aws_lambda_powertools/utilities/feature_flags/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def _match_by_action(self, action: str, condition_value: Any, context_value: Any
return False
mapping_by_action = {
schema.RuleAction.EQUALS.value: lambda a, b: a == b,
schema.RuleAction.NOT_EQUALS.value: lambda a, b: a != b,
schema.RuleAction.KEY_GREATER_THAN_VALUE.value: lambda a, b: a > b,
schema.RuleAction.KEY_GREATER_THAN_OR_EQUAL_VALUE.value: lambda a, b: a >= b,
schema.RuleAction.KEY_LESS_THAN_VALUE.value: lambda a, b: a < b,
schema.RuleAction.KEY_LESS_THAN_OR_EQUAL_VALUE.value: lambda a, b: a <= b,
schema.RuleAction.STARTSWITH.value: lambda a, b: a.startswith(b),
schema.RuleAction.ENDSWITH.value: lambda a, b: a.endswith(b),
schema.RuleAction.IN.value: lambda a, b: a in b,
Expand Down Expand Up @@ -105,12 +110,9 @@ def _evaluate_rules(
if self._evaluate_conditions(rule_name=rule_name, feature_name=feature_name, rule=rule, context=context):
return bool(rule_match_value)

# no rule matched, return default value of feature
self.logger.debug(
f"no rule matched, returning feature default, default={feat_default}, name={feature_name}"
)
return feat_default
return False
# no rule matched, return default value of feature
self.logger.debug(f"no rule matched, returning feature default, default={feat_default}, name={feature_name}")
return feat_default

def get_configuration(self) -> Dict:
"""Get validated feature flag schema from configured store.
Expand Down
5 changes: 5 additions & 0 deletions aws_lambda_powertools/utilities/feature_flags/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

class RuleAction(str, Enum):
EQUALS = "EQUALS"
NOT_EQUALS = "NOT_EQUALS"
KEY_GREATER_THAN_VALUE = "KEY_GREATER_THAN_VALUE"
KEY_GREATER_THAN_OR_EQUAL_VALUE = "KEY_GREATER_THAN_OR_EQUAL_VALUE"
KEY_LESS_THAN_VALUE = "KEY_LESS_THAN_VALUE"
KEY_LESS_THAN_OR_EQUAL_VALUE = "KEY_LESS_THAN_OR_EQUAL_VALUE"
STARTSWITH = "STARTSWITH"
ENDSWITH = "ENDSWITH"
IN = "IN"
Expand Down
5 changes: 5 additions & 0 deletions docs/utilities/feature_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ The `action` configuration can have the following values, where the expressions
Action | Equivalent expression
------------------------------------------------- | ---------------------------------------------------------------------------------
**EQUALS** | `lambda a, b: a == b`
**NOT_EQUALS** | `lambda a, b: a != b`
**KEY_GREATER_THAN_VALUE** | `lambda a, b: a > b`
**KEY_GREATER_THAN_OR_EQUAL_VALUE** | `lambda a, b: a >= b`
**KEY_LESS_THAN_VALUE** | `lambda a, b: a < b`
**KEY_LESS_THAN_OR_EQUAL_VALUE** | `lambda a, b: a <= b`
**STARTSWITH** | `lambda a, b: a.startswith(b)`
**ENDSWITH** | `lambda a, b: a.endswith(b)`
**KEY_IN_VALUE** | `lambda a, b: a in b`
Expand Down
Loading

0 comments on commit d019803

Please sign in to comment.