Skip to content

Commit

Permalink
fixup! fixup! Issue #139 add backend-aware collection allow-list conf…
Browse files Browse the repository at this point in the history
…ig option
  • Loading branch information
soxofaan committed Apr 2, 2024
1 parent 77a7947 commit f90e884
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/openeo_aggregator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ class AggregatorBackendConfig(OpenEoBackendConfig):
# TODO: remove this deprecated field
collection_whitelist: Optional[List[Union[str, re.Pattern]]] = None

# List of collection ids to cover with the aggregator.
# By default (or value None): support union of all upstream collections
# Each item can be a string (collection id), regex pattern for collection id, or dict with:
# - required key "collection_id" (string or regex)
# - optional "allowed_backends": list of backends to consider for this collection
# Allow list for collection ids to cover with the aggregator.
# By default (value `None`): support union of all upstream collections.
# To enable a real allow list, use a list of items as illustrated:
# [
# # Regular string: match exactly
# "COPERNICUS_30",
# # Regex pattern object: match collection id with regex (`fullmatch` mode)
# re.compile(r"CGLS_.*"),
# # Dict: match collection id (again as string or with regex pattern)
# # and additionally only consider specific backends by id (per `aggregator_backends` config)
# {"collection_id": "SENTINEL2_L2A", "allowed_backends": ["b2"]},
# ]
collection_allow_list: Optional[List[Union[str, re.Pattern, dict]]] = None

zookeeper_prefix: str = "/openeo-aggregator/"
Expand Down
2 changes: 1 addition & 1 deletion src/openeo_aggregator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,4 @@ def string_or_regex_match(pattern: Union[str, re.Pattern], value: str) -> bool:
elif isinstance(pattern, re.Pattern):
return bool(pattern.fullmatch(value))
else:
raise TypeError(f"Invalid pattern type {type(pattern)}")
raise TypeError(f"Invalid pattern {pattern}")
20 changes: 20 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
drop_dict_keys,
is_whitelisted,
normalize_issuer_url,
string_or_regex_match,
strip_join,
subdict,
timestamp_to_rfc3339,
Expand Down Expand Up @@ -343,3 +344,22 @@ def meh(self, x):
assert foo.meh(6) == 12

assert foo.stats == {"bar": 1}


def test_string_or_regex_match_str():
assert string_or_regex_match("foo", "foo") is True
assert string_or_regex_match("foo", "bar") is False


def test_string_or_regex_match_regex():
assert string_or_regex_match(re.compile("(foo|bar)"), "foo") is True
assert string_or_regex_match(re.compile("(foo|ba+r)"), "baaar") is True
assert string_or_regex_match(re.compile("(foo|bar)"), "meh") is False
assert string_or_regex_match(re.compile("(foo|bar)"), "foobar") is False
assert string_or_regex_match(re.compile("(foo|bar).*"), "foozuu") is True
assert string_or_regex_match(re.compile(".*(foo|bar)"), "meebar") is True


def test_string_or_regex_match_invalid():
with pytest.raises(TypeError, match=re.escape("Invalid pattern [1, 2, 3]")):
string_or_regex_match([1, 2, 3], "foo")

0 comments on commit f90e884

Please sign in to comment.