Skip to content

Commit

Permalink
Merge branch 'main' into multichain
Browse files Browse the repository at this point in the history
  • Loading branch information
calina-c committed Mar 10, 2023
2 parents f8801ba + 33bd03a commit 3bb5f06
Show file tree
Hide file tree
Showing 84 changed files with 343 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .copyright.tmpl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Copyright 2021 Ocean Protocol Foundation
Copyright 2023 Ocean Protocol Foundation
SPDX-License-Identifier: Apache-2.0
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
## Copyright 2021 Ocean Protocol Foundation
## Copyright 2023 Ocean Protocol Foundation
## SPDX-License-Identifier: Apache-2.0
##
name: black
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
## Copyright 2021 Ocean Protocol Foundation
## Copyright 2023 Ocean Protocol Foundation
## SPDX-License-Identifier: Apache-2.0
##
name: Provider tests
Expand Down Expand Up @@ -46,13 +46,14 @@ jobs:
sleep 10
[ -f "$HOME/.ocean/ocean-contracts/artifacts/ready" -a -f "$HOME/.ocean/ocean-c2d/ready" ] && break
done
- name: Test with pytest
run: |
coverage run --source ocean_provider -m pytest
coverage report
coverage xml
- name: docker logs
run: docker logs ocean_aquarius_1 && docker logs ocean_provider_1 && docker logs ocean_provider2_1 && docker logs ocean_computetodata_1
run: docker logs ocean_aquarius_1 && docker logs ocean_provider_1 && docker logs ocean_provider2_1
if: ${{ failure() }}
- name: Publish code coverage
uses: paambaati/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright 2021 Ocean Protocol Foundation
Copyright 2023 Ocean Protocol Foundation
SPDX-License-Identifier: Apache-2.0
-->

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright 2021 Ocean Protocol Foundation
Copyright 2023 Ocean Protocol Foundation
SPDX-License-Identifier: Apache-2.0
-->
History
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
## Copyright 2021 Ocean Protocol Foundation
## Copyright 2023 Ocean Protocol Foundation
## SPDX-License-Identifier: Apache-2.0
##
FROM ubuntu:18.04
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright 2022 Ocean Protocol Foundation
Copyright 2023 Ocean Protocol Foundation
SPDX-License-Identifier: Apache-2.0
-->
[![banner](https://raw.githubusercontent.com/oceanprotocol/art/master/github/repo-banner%402x.png)](https://oceanprotocol.com)
Expand Down
2 changes: 1 addition & 1 deletion bumpversion.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
##
## Copyright 2021 Ocean Protocol Foundation
## Copyright 2023 Ocean Protocol Foundation
## SPDX-License-Identifier: Apache-2.0
##

Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
## Copyright 2021 Ocean Protocol Foundation
## Copyright 2023 Ocean Protocol Foundation
## SPDX-License-Identifier: Apache-2.0
##
version: '3'
Expand Down
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
##
## Copyright 2021 Ocean Protocol Foundation
## Copyright 2023 Ocean Protocol Foundation
## SPDX-License-Identifier: Apache-2.0
##

Expand Down
2 changes: 1 addition & 1 deletion logging.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
## Copyright 2021 Ocean Protocol Foundation
## Copyright 2023 Ocean Protocol Foundation
## SPDX-License-Identifier: Apache-2.0
##
version: 1
Expand Down
2 changes: 1 addition & 1 deletion ocean_provider/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
2 changes: 1 addition & 1 deletion ocean_provider/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#

Expand Down
2 changes: 1 addition & 1 deletion ocean_provider/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#

Expand Down
23 changes: 0 additions & 23 deletions ocean_provider/file_types/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,6 @@ def check_details(self, with_checksum=False):
return False, {}

def _get_result_from_url(self, with_checksum=False):
lightweight_methods = [] if self.method == "post" else ["head", "options"]
# if checksum is not needed, try with head/options, mabye we are lucky
if not with_checksum:
for method in lightweight_methods:
url = self.get_download_url()
func = getattr(requests, method)
result = func(
url,
timeout=REQUEST_TIMEOUT,
headers=self.headers,
params=self.format_userdata(),
)
if (
result.status_code == 200
and (
result.headers.get("Content-Type")
or result.headers.get("Content-Range")
)
and result.headers.get("Content-Length")
):
return result, {}

func, func_args = self._get_func_and_args()

# overwrite checksum flag if file is too large
Expand All @@ -154,7 +132,6 @@ def _get_result_from_url(self, with_checksum=False):
with_checksum = False

if not with_checksum:
# fallback on full request, since head and options did not work
return func(**func_args), {}

sha = hashlib.sha256()
Expand Down
2 changes: 1 addition & 1 deletion ocean_provider/http_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
from typing import Any, Dict
Expand Down
2 changes: 1 addition & 1 deletion ocean_provider/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#

Expand Down
2 changes: 1 addition & 1 deletion ocean_provider/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
from sqlalchemy import Column, String
Expand Down
2 changes: 1 addition & 1 deletion ocean_provider/myapp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#

Expand Down
9 changes: 5 additions & 4 deletions ocean_provider/requests_session.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
from requests.adapters import HTTPAdapter
from requests.adapters import HTTPAdapter, Retry
from requests.sessions import Session


Expand All @@ -13,16 +13,17 @@ def get_requests_session() -> Session:
:return: requests session
"""
session = Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504])
session.mount(
"http://",
HTTPAdapter(
pool_connections=25, pool_maxsize=25, pool_block=True, max_retries=1
pool_connections=25, pool_maxsize=25, pool_block=True, max_retries=retries
),
)
session.mount(
"https://",
HTTPAdapter(
pool_connections=25, pool_maxsize=25, pool_block=True, max_retries=1
pool_connections=25, pool_maxsize=25, pool_block=True, max_retries=retries
),
)
return session
2 changes: 1 addition & 1 deletion ocean_provider/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
"""Unites routes from compute and consume files."""
Expand Down
6 changes: 3 additions & 3 deletions ocean_provider/routes/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import logging
Expand Down Expand Up @@ -34,7 +34,7 @@ def create_auth_token():
(expiration date is in the future), the same token is re-enabled.
---
tags:
- services
- auth
consumes:
- application/json
parameters:
Expand Down Expand Up @@ -85,7 +85,7 @@ def delete_auth_token():
disallowing API calls with that token.
---
tags:
- services
- auth
consumes:
- application/json
parameters:
Expand Down
29 changes: 22 additions & 7 deletions ocean_provider/routes/compute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import functools
Expand Down Expand Up @@ -211,7 +211,7 @@ def computeDelete():
---
tags:
- services
- compute
consumes:
- application/json
parameters:
Expand Down Expand Up @@ -267,7 +267,7 @@ def computeStop():
---
tags:
- services
- compute
consumes:
- application/json
parameters:
Expand Down Expand Up @@ -328,7 +328,7 @@ def computeStatus():
---
tags:
- services
- compute
consumes:
- application/json
parameters:
Expand Down Expand Up @@ -383,7 +383,7 @@ def computeStart():
---
tags:
- services
- compute
consumes:
- application/json
parameters:
Expand Down Expand Up @@ -483,7 +483,7 @@ def computeResult():
---
tags:
- services
- compute
consumes:
- application/json
parameters:
Expand Down Expand Up @@ -560,7 +560,7 @@ def computeEnvironments():
---
tags:
- services
- compute
consumes:
- application/json
Expand All @@ -581,6 +581,21 @@ def computeEnvironments():

@services.route("/validateContainer", methods=["POST"])
def validateContainer():
"""Validate a c2d container json
---
tags:
- compute
consumes:
- application/json
responses:
200:
description: Container is valid.
400:
description: Container is invalid.
return: error dict if container is invalid
"""
container = get_request_data(request)
valid, messages = validate_container(container)

Expand Down
27 changes: 23 additions & 4 deletions ocean_provider/routes/consume.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021 Ocean Protocol Foundation
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import json
Expand Down Expand Up @@ -40,7 +40,24 @@
@services.route("/nonce", methods=["GET"])
@validate(NonceRequest)
def nonce():
"""Returns a decimal `nonce` for the given account address."""
"""Returns a decimal `nonce` for the given account address.
---
tags:
- consume
consumes:
- application/json
parameters:
- name: userAddress
description: The address of the account
required: true
type: string
responses:
200:
description: nonce returned
return: nonce for user address
"""
logger.info("nonce endpoint called")
data = get_request_data(request)
address = data.get("userAddress")
Expand All @@ -65,7 +82,7 @@ def fileinfo():
---
tags:
- services
- consume
responses:
200:
Expand Down Expand Up @@ -137,6 +154,8 @@ def initialize():
where the approval is given to the provider's ethereum account for
the number of tokens required by the service.
tags:
- consume
responses:
400:
description: One or more of the required attributes are missing or invalid.
Expand Down Expand Up @@ -253,7 +272,7 @@ def download():
---
tags:
- services
- consume
consumes:
- application/json
parameters:
Expand Down
Loading

0 comments on commit 3bb5f06

Please sign in to comment.