diff --git a/ocean_provider/routes/consume.py b/ocean_provider/routes/consume.py index fe393330..91b6860a 100644 --- a/ocean_provider/routes/consume.py +++ b/ocean_provider/routes/consume.py @@ -337,15 +337,9 @@ def download(): # the datatoken address asset = get_asset_from_metadatastore(get_metadata_url(), did) - consumable, message = asset.is_consumable( - credential={"type": "address", "value": [consumer_address]} - ) + consumable, message = check_asset_consumable(asset, consumer_address, logger) if not consumable: - return error_response( - f"Asset cannot be consumed. Error: {message}", - 400, - logger, - ) + return error_response(message, 400, logger) service = asset.get_service_by_id(service_id) diff --git a/ocean_provider/utils/credentials.py b/ocean_provider/utils/credentials.py index 58ac5a27..4bd5fa33 100644 --- a/ocean_provider/utils/credentials.py +++ b/ocean_provider/utils/credentials.py @@ -2,6 +2,7 @@ # Copyright 2023 Ocean Protocol Foundation # SPDX-License-Identifier: Apache-2.0 # +import json from typing import Optional from ocean_provider.utils.consumable import ConsumableCodes, MalformedCredential @@ -100,8 +101,14 @@ def get_address_entry_of_class(self, access_class: str = "allow") -> Optional[di """Get address credentials entry of the specified access class. access_class = "allow" or "deny".""" if not self.asset.credentials: return None - entries = self.asset.credentials.get(access_class, []) - address_entries = [entry for entry in entries if entry.get("type") == "address"] + if isinstance(self.asset.credentials, str): + credentials = json.loads(self.asset.credentials) + else: + credentials = self.asset.credentials + entries = credentials.get(access_class, []) + address_entries = [ + entry for entry in entries if json.loads(entry).get("type") == "address" + ] return address_entries[0] if address_entries else None