Skip to content

Commit

Permalink
Add multiple result (query) filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
calina-c committed Apr 6, 2022
1 parent 971d26a commit b89dd2e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions aquarius/app/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import requests

from aquarius.app.es_instance import ElasticsearchInstance
from aquarius.app.util import sanitize_record, get_signature_vrs, get_allowed_publishers
from aquarius.app.util import sanitize_record, sanitize_query_result, get_signature_vrs, get_allowed_publishers
from aquarius.ddo_checker.shacl_checker import validate_dict
from aquarius.events.processors import (
MetadataCreatedProcessor,
Expand Down Expand Up @@ -283,7 +283,7 @@ def query_ddo():
)

try:
return es_instance.es.search(data)
return sanitize_query_result(es_instance.es.search(data))
except elasticsearch.exceptions.TransportError as e:
error = e.error if isinstance(e.error, str) else str(e.error)
info = e.info if isinstance(e.info, dict) else ""
Expand Down
13 changes: 13 additions & 0 deletions aquarius/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def sanitize_record(data_record):
return json.dumps(data_record, default=datetime_converter)


def sanitize_query_result(query_result):
if not os.getenv("RBAC_SERVER_URL"):
return query_result

payload = {
"eventType": "filter_query_result",
"component": "metadatacache",
"query_result": query_result,
}

return requests.post(os.getenv("RBAC_SERVER_URL"), json=payload).json()


def get_bool_env_value(envvar_name, default_value=0):
assert default_value in (0, 1), "bad default value, must be either 0 or 1"
try:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
datetime_converter,
get_bool_env_value,
sanitize_record,
sanitize_query_result,
get_aquarius_wallet,
AquariusPrivateKeyException,
get_signature_vrs,
Expand Down Expand Up @@ -125,6 +126,21 @@ def test_sanitize_record_through_rbac(monkeypatch):
assert result["this_is"] == "SPARTAAA!"


def test_sanitize_query_result(monkeypatch):
result = sanitize_query_result({"this_is": "Athens, for some reason."})
assert result["this_is"] == "Athens, for some reason."

monkeypatch.setenv("RBAC_SERVER_URL", "test")

with patch("requests.post") as mock:
response = Mock(spec=Response)
response.json.return_value = {"this_is": "SPARTAAA!"}
mock.return_value = response

result = sanitize_query_result({})
assert result["this_is"] == "SPARTAAA!"


class BlockProcessingClassChild(BlockProcessingClass):
def get_last_processed_block(self):
raise Exception("BAD!")
Expand Down

0 comments on commit b89dd2e

Please sign in to comment.