Skip to content

Commit 70a78fd

Browse files
authored
Merge pull request #72 from oceanprotocol/feature/integrate-new-squid
Feature/integrate new squid
2 parents 8b0f2d9 + e67106e commit 70a78fd

File tree

12 files changed

+137
-164
lines changed

12 files changed

+137
-164
lines changed

.bumpversion.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[bumpversion]
2-
current_version = 0.1.0
2+
current_version = 0.1.1
33

44
[bumpversion:file:setup.cfg]
5+
56
[bumpversion:file:setup.py]
67

environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ dependencies:
157157
- multidict==4.3.1
158158
- multipipes==0.1.0
159159
- oauthlib==2.1.0
160-
- squid-py==0.1.2
160+
- squid-py==0.1.3
161161
- oceandb-driver-interface==0.1.9
162162
- oceandb-mongodb-driver==0.1.2
163-
- oceandb-elasticsearch-driver==0.0.1
163+
- oceandb-elasticsearch-driver==0.0.2
164164
- parsimonious==0.8.0
165165
- pathtools==0.1.2
166166
- pkginfo==1.4.2

oceandb.ini

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,71 @@
1-
[oceandb]
2-
3-
;enabled = true
4-
;module = bigchaindb
5-
;;location of plugin class
6-
;;module.path=venv/lib/python3.6/site-packages/oceandb_bigchaindb_driver/plugin.py
7-
;secret =
8-
;db.namespace = namespace
9-
;
10-
;;--- local config ---
11-
;db.scheme = http
12-
;db.hostname = localhost
13-
;db.port = 9984
14-
;db.app_id =
15-
;db.app_key =
16-
17-
;; Do before to run with mongo
18-
;; mongo test --eval 'db.createUser({user:"travis",pwd:"test",roles:["readWrite"]});'
19-
20-
enabled = true
21-
module = mongodb
22-
db.hostname = localhost
23-
db.port = 27017
24-
;db.username=travis
25-
;db.password=test
26-
db.name = test
27-
db.collection = protokeeper
28-
29-
# Elasticsearch configuration
30-
;enabled = true
31-
;module = elasticsearch
32-
;db.hostname = localhost
33-
;db.port = 9200
34-
;db.username=elastic
35-
;db.password=changeme
36-
;db.index= oceandb
37-
;db.ssl=False
38-
;db.verify_certs=False
39-
;db.ca_cert_path=
40-
;db.client_key=
41-
;db.client_cert_path=
42-
43-
44-
;;--- remote config with access token ---
45-
;db.scheme=https
46-
;db.hostname=test.bigchaindb.com
47-
;db.port=
48-
;db.app_id=54ed26dd
49-
;db.app_key=d068996d8d5b1a66cfc61dc3a83fa7ee
50-
51-
[keeper-contracts]
52-
keeper.host = http://127.0.0.1
53-
keeper.port = 8545
54-
keeper.network = development
55-
56-
;contracts.folder=venv/contracts
57-
market.address =
58-
auth.address =
59-
token.address =
60-
provider.address =
61-
62-
[resources]
63-
azure.account.name = testocnfiles
64-
azure.account.key = k2Vk4yfb88WNlWW+W54a8ytJm8MYO1GW9IgiV7TNGKSdmKyVNXzyhiRZ3U1OHRotj/vTYdhJj+ho30HPyJpuYQ==
65-
azure.container = testfiles
66-
67-
;; These consitute part of the provider url which is used in setting the `api_url` in the `OceanContractsWrapper`
68-
provider.scheme = http
69-
provider.host = localhost
70-
provider.port = 5000
1+
[oceandb]
2+
3+
;enabled = true
4+
;module = bigchaindb
5+
;;location of plugin class
6+
;;module.path=venv/lib/python3.6/site-packages/oceandb_bigchaindb_driver/plugin.py
7+
;secret =
8+
;db.namespace = namespace
9+
;
10+
;;--- local config ---
11+
;db.scheme = http
12+
;db.hostname = localhost
13+
;db.port = 9984
14+
;db.app_id =
15+
;db.app_key =
16+
17+
;; Do before to run with mongo
18+
;; mongo test --eval 'db.createUser({user:"travis",pwd:"test",roles:["readWrite"]});'
19+
20+
enabled = true
21+
module = mongodb
22+
db.hostname = localhost
23+
db.port = 27017
24+
;db.username=travis
25+
;db.password=test
26+
db.name = test
27+
db.collection = protokeeper
28+
29+
# Elasticsearch configuration
30+
;enabled = true
31+
;module = elasticsearch
32+
;db.hostname = localhost
33+
;db.port = 9200
34+
;db.username=elastic
35+
;db.password=changeme
36+
;db.index= oceandb
37+
;db.ssl=False
38+
;db.verify_certs=False
39+
;db.ca_cert_path=
40+
;db.client_key=
41+
;db.client_cert_path=
42+
43+
44+
;;--- remote config with access token ---
45+
;db.scheme=https
46+
;db.hostname=test.bigchaindb.com
47+
;db.port=
48+
;db.app_id=54ed26dd
49+
;db.app_key=d068996d8d5b1a66cfc61dc3a83fa7ee
50+
51+
[keeper-contracts]
52+
keeper.host = http://127.0.0.1
53+
keeper.port = 8545
54+
keeper.network = development
55+
56+
;contracts.folder=venv/contracts
57+
market.address =
58+
auth.address =
59+
token.address =
60+
provider.address =
61+
provider.account =
62+
63+
[resources]
64+
azure.account.name = testocnfiles
65+
azure.account.key = k2Vk4yfb88WNlWW+W54a8ytJm8MYO1GW9IgiV7TNGKSdmKyVNXzyhiRZ3U1OHRotj/vTYdhJj+ho30HPyJpuYQ==
66+
azure.container = testfiles
67+
68+
;; These consitute part of the provider url which is used in setting the `api_url` in the `OceanContractsWrapper`
69+
provider.scheme = http
70+
provider.host = localhost
71+
provider.port = 5000

provider/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
in collaboration with the keeper-contracts."""
33

44
__author__ = """OceanProtocol"""
5-
__version__ = '0.1.0'
5+
__version__ = '0.1.1'

provider/app/assets.py

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,52 @@
77
from flask import Blueprint, jsonify, request
88
from oceandb_driver_interface.search_model import QueryModel, FullTextModel
99
from squid_py.acl import decode
10-
from squid_py.config_parser import load_config_section
11-
from squid_py.constants import OCEAN_ACL_CONTRACT, OCEAN_MARKET_CONTRACT
12-
from squid_py.ocean_contracts import OceanContracts
10+
from squid_py.config import Config
11+
from squid_py.ocean import Ocean
1312

1413
from provider.app.dao import Dao
1514
from provider.app.filters import Filters
1615
from provider.app.osmosis import generate_sasurl
17-
from provider.constants import ConfigSections, BaseURLs
16+
from provider.constants import BaseURLs
1817
from provider.log import setup_logging
1918
from provider.myapp import app
19+
from provider.constants import ConfigSections
2020

2121
setup_logging()
2222
assets = Blueprint('assets', __name__)
2323

2424
config_file = app.config['CONFIG_FILE']
25+
config = Config(filename=config_file)
2526
# Prepare keeper contracts for on-chain access control
26-
keeper_config = load_config_section(config_file, ConfigSections.KEEPER_CONTRACTS)
27-
res_conf = load_config_section(config_file, ConfigSections.RESOURCES)
2827
# Prepare OceanDB
29-
dao = Dao(config_file)
30-
31-
provider_url = '%s://%s:%s' % (res_conf['provider.scheme'], res_conf['provider.host'], res_conf['provider.port'])
28+
dao = Dao(config_file=config_file)
29+
provider_url = config.provider_url
3230
provider_url += BaseURLs.ASSETS_URL
33-
provider_address = None if not keeper_config['provider.address'] else keeper_config['provider.address']
34-
ocean_contracts = OceanContracts(config_path=config_file)
35-
36-
ocean_contracts.init_contracts()
37-
# Prepare resources access configuration to download assets
38-
resources_config = load_config_section(config_file, ConfigSections.RESOURCES)
31+
provider_address = None if not config.get(ConfigSections.KEEPER_CONTRACTS, 'provider.address') else config.get(ConfigSections.KEEPER_CONTRACTS,
32+
'provider.address')
33+
ocn = Ocean(config_file=config_file)
3934

4035

4136
def get_provider_address_filter():
42-
account = ocean_contracts.web3.eth.accounts[0] if not keeper_config['provider.address'] \
43-
else keeper_config['provider.address']
37+
account = ocn.web3.eth.accounts[0] if not config.get(ConfigSections.KEEPER_CONTRACTS, 'provider.address') \
38+
else config.get(ConfigSections.KEEPER_CONTRACTS, 'provider.address')
4439
return {"address": account}
4540

4641

47-
ocn_for_filters = OceanContracts(config_path=config_file)
48-
ocn_for_filters.init_contracts()
49-
50-
filters = Filters(ocean_contracts_wrapper=ocn_for_filters, config_file=config_file, api_url=provider_url)
51-
filter_access_consent = ocn_for_filters.watch_event(OCEAN_ACL_CONTRACT,
52-
'AccessConsentRequested',
53-
filters.commit_access_request,
54-
0.2,
55-
fromBlock='latest',
56-
filters=get_provider_address_filter())
42+
filters = Filters(ocean_contracts_wrapper=ocn, config_file=config_file, api_url=provider_url)
43+
filter_access_consent = ocn.helper.watch_event(ocn.contracts.auth.contract,
44+
'AccessConsentRequested',
45+
filters.commit_access_request,
46+
0.2,
47+
fromBlock='latest',
48+
filters=get_provider_address_filter())
5749

58-
filter_payment = ocn_for_filters.watch_event(OCEAN_MARKET_CONTRACT,
59-
'PaymentReceived',
60-
filters.publish_encrypted_token,
61-
0.2,
62-
fromBlock='latest',
63-
filters=get_provider_address_filter())
50+
filter_payment = ocn.helper.watch_event(ocn.contracts.market.contract,
51+
'PaymentReceived',
52+
filters.publish_encrypted_token,
53+
0.2,
54+
fromBlock='latest',
55+
filters=get_provider_address_filter())
6456

6557

6658
@assets.route('', methods=['GET'])
@@ -642,27 +634,29 @@ def consume_resource(asset_id):
642634
logging.error('Consume failed: required attr %s missing.' % attr)
643635
return '"%s" is required for registering an asset.' % attr, 400
644636

645-
contract_instance = ocean_contracts.contracts[OCEAN_ACL_CONTRACT][0]
646-
sig = ocean_contracts.split_signature(ocean_contracts.web3.toBytes(hexstr=data['sigEncJWT']))
637+
contract_instance = ocn.contracts.auth.contract_concise
638+
sig = ocn.helper.split_signature(ocn.web3.toBytes(hexstr=data['sigEncJWT']))
647639
jwt = decode(data['jwt'])
648640

649641
if contract_instance.verifyAccessTokenDelivery(jwt['request_id'], # requestId
650-
ocean_contracts.web3.toChecksumAddress(data['consumerId']),
642+
ocn.web3.toChecksumAddress(data['consumerId']),
651643
# consumerId
652644
data['fixed_msg'],
653645
sig.v, # sig.v
654646
sig.r, # sig.r
655647
sig.s, # sig.s
656-
transact={'from': ocean_contracts.account,
648+
transact={'from': ocn.web3.eth.accounts[0] if config.get(
649+
ConfigSections.KEEPER_CONTRACTS, 'provider.account') is '' else config.get(
650+
ConfigSections.KEEPER_CONTRACTS, 'provider.account'),
657651
'gas': 4000000}):
658652
if jwt['resource_server_plugin'] == 'Azure':
659653
logging.info('reading asset from oceandb: %s' % asset_id)
660654
urls = dao.get(asset_id)['base']['contentUrls']
661655
url_list = []
662656
for url in urls:
663-
url_list.append(generate_sasurl(url, resources_config['azure.account.name'],
664-
resources_config['azure.account.key'],
665-
resources_config['azure.container']))
657+
url_list.append(generate_sasurl(url, config.get(ConfigSections.RESOURCES, 'azure.account.name'),
658+
config.get(ConfigSections.RESOURCES, 'azure.account.key'),
659+
config.get(ConfigSections.RESOURCES, 'azure.container')))
666660
return jsonify(url_list), 200
667661
else:
668662
logging.error('resource server plugin is not supported: %s' % jwt['resource_server_plugin'])

provider/app/filters.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from secrets import token_hex
33
from squid_py.acl import encrypt, encode, generate_encoding_pair
44
import time
5-
from squid_py.constants import OCEAN_ACL_CONTRACT
65
from provider.app.dao import Dao
76
from werkzeug.contrib.cache import SimpleCache
87
import logging
@@ -20,7 +19,7 @@ def __init__(self, ocean_contracts_wrapper, config_file, api_url):
2019
logging.info('Keeper filters: got api url = "%s"' % self.api_url)
2120

2221
def commit_access_request(self, event):
23-
contract_instance = self.contracts[OCEAN_ACL_CONTRACT][0]
22+
contract_instance = self.contracts.auth.contract_concise
2423
try:
2524
res_id = self.web3.toHex(event['args']['_resourceId'])
2625
request_id = self.web3.toHex(event['args']['_id'])
@@ -68,7 +67,7 @@ def commit_access_request(self, event):
6867
return e
6968

7069
def publish_encrypted_token(self, event):
71-
contract_instance = self.contracts[OCEAN_ACL_CONTRACT][0]
70+
contract_instance = self.contracts.auth.contract_concise
7271
try:
7372
request_id = self.web3.toHex(event['args']['_paymentId'])
7473
# check keeper for the status of this access request, if the status is not committed should be ignored.

provider/app/resource_constants.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

provider/run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from flask_swagger import swagger
44
from flask_swagger_ui import get_swaggerui_blueprint
55
from flask import jsonify
6-
from squid_py.config_parser import load_config_section
7-
from provider.constants import BaseURLs, ConfigSections
6+
# from squid_py.config_parser import load_config_section
7+
from squid_py.config import Config
8+
from provider.constants import BaseURLs
89

910

1011
@app.route("/spec")
@@ -15,8 +16,8 @@ def spec():
1516
return jsonify(swag)
1617

1718

18-
res_conf = load_config_section(app.config['CONFIG_FILE'], ConfigSections.RESOURCES)
19-
provider_url = '%s://%s:%s' % (res_conf['provider.scheme'], res_conf['provider.host'], res_conf['provider.port'])
19+
config = Config(filename=app.config['CONFIG_FILE'])
20+
provider_url = config.provider_url
2021
# Call factory function to create our blueprint
2122
swaggerui_blueprint = get_swaggerui_blueprint(
2223
BaseURLs.SWAGGER_URL,

requirements_dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ msrestazure==0.5.0
139139
multidict==4.3.1
140140
multipipes==0.1.0
141141
oauthlib==2.1.0
142-
squid-py==0.1.2
142+
squid-py==0.1.3
143143
oceandb-bigchaindb-driver==0.1.3
144144
oceandb-driver-interface==0.1.11
145-
oceandb-elasticsearch-driver==0.0.1
145+
oceandb-elasticsearch-driver==0.0.2
146146
oceandb-mongodb-driver==0.1.3
147147
parsimonious==0.8.0
148148
pathtools==0.1.2

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.0
2+
current_version = 0.1.1
33
commit = True
44
tag = True
55

0 commit comments

Comments
 (0)