From 8af4c1f784fc3f14f545fc0353e0327d637046da Mon Sep 17 00:00:00 2001 From: Calina Cenan Date: Wed, 25 Oct 2023 10:25:53 +0000 Subject: [PATCH] Nonce fixes. --- ocean_lib/data_provider/base.py | 4 +--- ocean_lib/data_provider/data_service_provider.py | 9 +++++++-- tests/readmes/test_readmes.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ocean_lib/data_provider/base.py b/ocean_lib/data_provider/base.py index cda0ffce8..9f843131f 100644 --- a/ocean_lib/data_provider/base.py +++ b/ocean_lib/data_provider/base.py @@ -46,9 +46,7 @@ def set_http_client(http_client: Session) -> None: @staticmethod @enforce_types - def sign_message( - wallet, msg: str, provider_uri: Optional[str] = None - ) -> Tuple[str, str]: + def sign_message(wallet, msg: str, provider_uri: str) -> Tuple[str, str]: if provider_uri: method, nonce_endpoint = DataServiceProviderBase.build_endpoint( "nonce", provider_uri diff --git a/ocean_lib/data_provider/data_service_provider.py b/ocean_lib/data_provider/data_service_provider.py index e27807751..317c95a4d 100644 --- a/ocean_lib/data_provider/data_service_provider.py +++ b/ocean_lib/data_provider/data_service_provider.py @@ -6,11 +6,9 @@ """Provider module.""" import json import logging -from datetime import datetime, timezone from json import JSONDecodeError from pathlib import Path from typing import Any, Dict, List, Optional, Union -from unittest.mock import Mock from enforce_typing import enforce_types from requests.models import PreparedRequest, Response @@ -219,6 +217,7 @@ def start_compute_job( consumer=consumer, dataset=dataset, compute_environment=compute_environment, + dataset_compute_service=dataset_compute_service, algorithm=algorithm, algorithm_meta=algorithm_meta, algorithm_custom_data=algorithm_custom_data, @@ -345,6 +344,7 @@ def compute_job_result( nonce, signature = DataServiceProvider.sign_message( consumer, f"{consumer.address}{job_id}{str(index)}", + provider_uri=dataset_compute_service.service_endpoint, ) req = PreparedRequest() @@ -415,6 +415,7 @@ def _send_compute_request( nonce, signature = DataServiceProvider.sign_message( consumer, f"{consumer.address}{job_id}{did}", + provider_uri=service_endpoint, ) req = PreparedRequest() @@ -449,6 +450,7 @@ def _send_compute_request( def _prepare_compute_payload( consumer, dataset: ComputeInput, + dataset_compute_service: Any, # Can not add Service typing due to enforce_type errors. compute_environment: str, algorithm: Optional[ComputeInput] = None, algorithm_meta: Optional[AlgorithmMetadata] = None, @@ -473,9 +475,12 @@ def _prepare_compute_payload( _input, req_key ), f"The received dataset does not have a {req_key}." + # TODO: is the nonce correct here? + # Should it be the one from the compute service or a dataset? nonce, signature = DataServiceProvider.sign_message( consumer, f"{consumer.address}{dataset.did}", + provider_uri=dataset_compute_service.service_endpoint, ) payload = { diff --git a/tests/readmes/test_readmes.py b/tests/readmes/test_readmes.py index 7f4d6d8e2..f0805b7fc 100644 --- a/tests/readmes/test_readmes.py +++ b/tests/readmes/test_readmes.py @@ -48,7 +48,7 @@ def test_script_execution(self, script_name): "publish-flow-credentials", "publish-flow-restapi", # TODO: fix and restore "gas-strategy-remote", - # "using-clef", # TODO: removed original clef readme, to reinstate in #1461 + "using-clef", # TODO: removed original clef readme, to reinstate in #1461 ] if script_name.replace("test_", "").replace(".py", "") in skippable: