Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions prefab.proto
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ message Criterion {
PROP_DOES_NOT_END_WITH_ONE_OF = 9;
HIERARCHICAL_MATCH = 10;
IN_INT_RANGE = 11;
PROP_STARTS_WITH_ONE_OF = 12;
PROP_DOES_NOT_START_WITH_ONE_OF =13;
PROP_CONTAINS_ONE_OF = 14;
PROP_DOES_NOT_CONTAIN_ONE_OF = 15;
PROP_LESS_THAN = 16;
PROP_LESS_THAN_OR_EQUAL = 17;
PROP_GREATER_THAN = 18;
PROP_GREATER_THAN_OR_EQUAL = 19;
PROP_BEFORE = 20;
PROP_AFTER = 21;
}
string property_name = 1;
CriterionOperator operator = 2;
Expand Down
62 changes: 48 additions & 14 deletions prefab_cloud_python/config_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,53 @@ def evaluate_criterion(self, criterion, properties):
return self.in_segment(criterion, properties)
if criterion.operator == OPS.NOT_IN_SEG:
return not self.in_segment(criterion, properties)
if criterion.operator == OPS.PROP_ENDS_WITH_ONE_OF:
if criterion.operator in [
OPS.PROP_ENDS_WITH_ONE_OF,
OPS.PROP_DOES_NOT_END_WITH_ONE_OF,
]:
negative = criterion.operator == OPS.PROP_DOES_NOT_END_WITH_ONE_OF
if value_from_properties is None:
return False
return any(
[
str(value_from_properties).endswith(ending)
for ending in criterion.value_to_match.string_list.values
]
return self.negate(negative, False)
return self.negate(
negative,
any(
[
str(value_from_properties).endswith(ending)
for ending in criterion.value_to_match.string_list.values
]
),
)
if criterion.operator in [
OPS.PROP_STARTS_WITH_ONE_OF,
OPS.PROP_DOES_NOT_START_WITH_ONE_OF,
]:
negative = criterion.operator == OPS.PROP_DOES_NOT_START_WITH_ONE_OF
if value_from_properties is None:
return self.negate(negative, False)
return self.negate(
negative,
any(
[
str(value_from_properties).startswith(beginning)
for beginning in criterion.value_to_match.string_list.values
]
),
)
if criterion.operator == OPS.PROP_DOES_NOT_END_WITH_ONE_OF:
if criterion.operator in [
OPS.PROP_CONTAINS_ONE_OF,
OPS.PROP_DOES_NOT_CONTAIN_ONE_OF,
]:
negative = criterion.operator == OPS.PROP_DOES_NOT_CONTAIN_ONE_OF
if value_from_properties is None:
return True
return not any(
[
str(value_from_properties).endswith(ending)
for ending in criterion.value_to_match.string_list.values
]
return self.negate(negative, False)
return self.negate(
negative,
any(
[
string in str(value_from_properties)
for string in criterion.value_to_match.string_list.values
]
),
)
if criterion.operator == OPS.HIERARCHICAL_MATCH:
return value_from_properties.startswith(criterion.value_to_match.string)
Expand All @@ -158,6 +188,10 @@ def evaluate_criterion(self, criterion, properties):
logger.info(f"Unknown criterion operator {criterion.operator}")
return False

@staticmethod
def negate(negate, value):
return not value if negate else value

def matches(self, criterion, value, properties):
criterion_value_or_values = ConfigValueUnwrapper.deepest_value(
criterion.value_to_match, self.config.key, properties
Expand Down
Loading
Loading