Skip to content

Commit

Permalink
JSON loads.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacarmina committed Oct 4, 2023
1 parent b12cbf5 commit 57cd9bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 2 additions & 8 deletions ocean_provider/routes/consume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 9 additions & 2 deletions ocean_provider/utils/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 57cd9bb

Please sign in to comment.