Skip to content

Commit

Permalink
Merge pull request #72 from oceanprotocol/feature/integrate-new-squid
Browse files Browse the repository at this point in the history
Feature/integrate new squid
  • Loading branch information
eruizgar91 authored Oct 17, 2018
2 parents 8b0f2d9 + e67106e commit 70a78fd
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 164 deletions.
3 changes: 2 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[bumpversion]
current_version = 0.1.0
current_version = 0.1.1

[bumpversion:file:setup.cfg]

[bumpversion:file:setup.py]

4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ dependencies:
- multidict==4.3.1
- multipipes==0.1.0
- oauthlib==2.1.0
- squid-py==0.1.2
- squid-py==0.1.3
- oceandb-driver-interface==0.1.9
- oceandb-mongodb-driver==0.1.2
- oceandb-elasticsearch-driver==0.0.1
- oceandb-elasticsearch-driver==0.0.2
- parsimonious==0.8.0
- pathtools==0.1.2
- pkginfo==1.4.2
Expand Down
141 changes: 71 additions & 70 deletions oceandb.ini
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
[oceandb]

;enabled = true
;module = bigchaindb
;;location of plugin class
;;module.path=venv/lib/python3.6/site-packages/oceandb_bigchaindb_driver/plugin.py
;secret =
;db.namespace = namespace
;
;;--- local config ---
;db.scheme = http
;db.hostname = localhost
;db.port = 9984
;db.app_id =
;db.app_key =

;; Do before to run with mongo
;; mongo test --eval 'db.createUser({user:"travis",pwd:"test",roles:["readWrite"]});'

enabled = true
module = mongodb
db.hostname = localhost
db.port = 27017
;db.username=travis
;db.password=test
db.name = test
db.collection = protokeeper

# Elasticsearch configuration
;enabled = true
;module = elasticsearch
;db.hostname = localhost
;db.port = 9200
;db.username=elastic
;db.password=changeme
;db.index= oceandb
;db.ssl=False
;db.verify_certs=False
;db.ca_cert_path=
;db.client_key=
;db.client_cert_path=


;;--- remote config with access token ---
;db.scheme=https
;db.hostname=test.bigchaindb.com
;db.port=
;db.app_id=54ed26dd
;db.app_key=d068996d8d5b1a66cfc61dc3a83fa7ee

[keeper-contracts]
keeper.host = http://127.0.0.1
keeper.port = 8545
keeper.network = development

;contracts.folder=venv/contracts
market.address =
auth.address =
token.address =
provider.address =

[resources]
azure.account.name = testocnfiles
azure.account.key = k2Vk4yfb88WNlWW+W54a8ytJm8MYO1GW9IgiV7TNGKSdmKyVNXzyhiRZ3U1OHRotj/vTYdhJj+ho30HPyJpuYQ==
azure.container = testfiles

;; These consitute part of the provider url which is used in setting the `api_url` in the `OceanContractsWrapper`
provider.scheme = http
provider.host = localhost
provider.port = 5000
[oceandb]

;enabled = true
;module = bigchaindb
;;location of plugin class
;;module.path=venv/lib/python3.6/site-packages/oceandb_bigchaindb_driver/plugin.py
;secret =
;db.namespace = namespace
;
;;--- local config ---
;db.scheme = http
;db.hostname = localhost
;db.port = 9984
;db.app_id =
;db.app_key =

;; Do before to run with mongo
;; mongo test --eval 'db.createUser({user:"travis",pwd:"test",roles:["readWrite"]});'

enabled = true
module = mongodb
db.hostname = localhost
db.port = 27017
;db.username=travis
;db.password=test
db.name = test
db.collection = protokeeper

# Elasticsearch configuration
;enabled = true
;module = elasticsearch
;db.hostname = localhost
;db.port = 9200
;db.username=elastic
;db.password=changeme
;db.index= oceandb
;db.ssl=False
;db.verify_certs=False
;db.ca_cert_path=
;db.client_key=
;db.client_cert_path=


;;--- remote config with access token ---
;db.scheme=https
;db.hostname=test.bigchaindb.com
;db.port=
;db.app_id=54ed26dd
;db.app_key=d068996d8d5b1a66cfc61dc3a83fa7ee

[keeper-contracts]
keeper.host = http://127.0.0.1
keeper.port = 8545
keeper.network = development

;contracts.folder=venv/contracts
market.address =
auth.address =
token.address =
provider.address =
provider.account =

[resources]
azure.account.name = testocnfiles
azure.account.key = k2Vk4yfb88WNlWW+W54a8ytJm8MYO1GW9IgiV7TNGKSdmKyVNXzyhiRZ3U1OHRotj/vTYdhJj+ho30HPyJpuYQ==
azure.container = testfiles

;; These consitute part of the provider url which is used in setting the `api_url` in the `OceanContractsWrapper`
provider.scheme = http
provider.host = localhost
provider.port = 5000
2 changes: 1 addition & 1 deletion provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
in collaboration with the keeper-contracts."""

__author__ = """OceanProtocol"""
__version__ = '0.1.0'
__version__ = '0.1.1'
74 changes: 34 additions & 40 deletions provider/app/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,52 @@
from flask import Blueprint, jsonify, request
from oceandb_driver_interface.search_model import QueryModel, FullTextModel
from squid_py.acl import decode
from squid_py.config_parser import load_config_section
from squid_py.constants import OCEAN_ACL_CONTRACT, OCEAN_MARKET_CONTRACT
from squid_py.ocean_contracts import OceanContracts
from squid_py.config import Config
from squid_py.ocean import Ocean

from provider.app.dao import Dao
from provider.app.filters import Filters
from provider.app.osmosis import generate_sasurl
from provider.constants import ConfigSections, BaseURLs
from provider.constants import BaseURLs
from provider.log import setup_logging
from provider.myapp import app
from provider.constants import ConfigSections

setup_logging()
assets = Blueprint('assets', __name__)

config_file = app.config['CONFIG_FILE']
config = Config(filename=config_file)
# Prepare keeper contracts for on-chain access control
keeper_config = load_config_section(config_file, ConfigSections.KEEPER_CONTRACTS)
res_conf = load_config_section(config_file, ConfigSections.RESOURCES)
# Prepare OceanDB
dao = Dao(config_file)

provider_url = '%s://%s:%s' % (res_conf['provider.scheme'], res_conf['provider.host'], res_conf['provider.port'])
dao = Dao(config_file=config_file)
provider_url = config.provider_url
provider_url += BaseURLs.ASSETS_URL
provider_address = None if not keeper_config['provider.address'] else keeper_config['provider.address']
ocean_contracts = OceanContracts(config_path=config_file)

ocean_contracts.init_contracts()
# Prepare resources access configuration to download assets
resources_config = load_config_section(config_file, ConfigSections.RESOURCES)
provider_address = None if not config.get(ConfigSections.KEEPER_CONTRACTS, 'provider.address') else config.get(ConfigSections.KEEPER_CONTRACTS,
'provider.address')
ocn = Ocean(config_file=config_file)


def get_provider_address_filter():
account = ocean_contracts.web3.eth.accounts[0] if not keeper_config['provider.address'] \
else keeper_config['provider.address']
account = ocn.web3.eth.accounts[0] if not config.get(ConfigSections.KEEPER_CONTRACTS, 'provider.address') \
else config.get(ConfigSections.KEEPER_CONTRACTS, 'provider.address')
return {"address": account}


ocn_for_filters = OceanContracts(config_path=config_file)
ocn_for_filters.init_contracts()

filters = Filters(ocean_contracts_wrapper=ocn_for_filters, config_file=config_file, api_url=provider_url)
filter_access_consent = ocn_for_filters.watch_event(OCEAN_ACL_CONTRACT,
'AccessConsentRequested',
filters.commit_access_request,
0.2,
fromBlock='latest',
filters=get_provider_address_filter())
filters = Filters(ocean_contracts_wrapper=ocn, config_file=config_file, api_url=provider_url)
filter_access_consent = ocn.helper.watch_event(ocn.contracts.auth.contract,
'AccessConsentRequested',
filters.commit_access_request,
0.2,
fromBlock='latest',
filters=get_provider_address_filter())

filter_payment = ocn_for_filters.watch_event(OCEAN_MARKET_CONTRACT,
'PaymentReceived',
filters.publish_encrypted_token,
0.2,
fromBlock='latest',
filters=get_provider_address_filter())
filter_payment = ocn.helper.watch_event(ocn.contracts.market.contract,
'PaymentReceived',
filters.publish_encrypted_token,
0.2,
fromBlock='latest',
filters=get_provider_address_filter())


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

contract_instance = ocean_contracts.contracts[OCEAN_ACL_CONTRACT][0]
sig = ocean_contracts.split_signature(ocean_contracts.web3.toBytes(hexstr=data['sigEncJWT']))
contract_instance = ocn.contracts.auth.contract_concise
sig = ocn.helper.split_signature(ocn.web3.toBytes(hexstr=data['sigEncJWT']))
jwt = decode(data['jwt'])

if contract_instance.verifyAccessTokenDelivery(jwt['request_id'], # requestId
ocean_contracts.web3.toChecksumAddress(data['consumerId']),
ocn.web3.toChecksumAddress(data['consumerId']),
# consumerId
data['fixed_msg'],
sig.v, # sig.v
sig.r, # sig.r
sig.s, # sig.s
transact={'from': ocean_contracts.account,
transact={'from': ocn.web3.eth.accounts[0] if config.get(
ConfigSections.KEEPER_CONTRACTS, 'provider.account') is '' else config.get(
ConfigSections.KEEPER_CONTRACTS, 'provider.account'),
'gas': 4000000}):
if jwt['resource_server_plugin'] == 'Azure':
logging.info('reading asset from oceandb: %s' % asset_id)
urls = dao.get(asset_id)['base']['contentUrls']
url_list = []
for url in urls:
url_list.append(generate_sasurl(url, resources_config['azure.account.name'],
resources_config['azure.account.key'],
resources_config['azure.container']))
url_list.append(generate_sasurl(url, config.get(ConfigSections.RESOURCES, 'azure.account.name'),
config.get(ConfigSections.RESOURCES, 'azure.account.key'),
config.get(ConfigSections.RESOURCES, 'azure.container')))
return jsonify(url_list), 200
else:
logging.error('resource server plugin is not supported: %s' % jwt['resource_server_plugin'])
Expand Down
5 changes: 2 additions & 3 deletions provider/app/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from secrets import token_hex
from squid_py.acl import encrypt, encode, generate_encoding_pair
import time
from squid_py.constants import OCEAN_ACL_CONTRACT
from provider.app.dao import Dao
from werkzeug.contrib.cache import SimpleCache
import logging
Expand All @@ -20,7 +19,7 @@ def __init__(self, ocean_contracts_wrapper, config_file, api_url):
logging.info('Keeper filters: got api url = "%s"' % self.api_url)

def commit_access_request(self, event):
contract_instance = self.contracts[OCEAN_ACL_CONTRACT][0]
contract_instance = self.contracts.auth.contract_concise
try:
res_id = self.web3.toHex(event['args']['_resourceId'])
request_id = self.web3.toHex(event['args']['_id'])
Expand Down Expand Up @@ -68,7 +67,7 @@ def commit_access_request(self, event):
return e

def publish_encrypted_token(self, event):
contract_instance = self.contracts[OCEAN_ACL_CONTRACT][0]
contract_instance = self.contracts.auth.contract_concise
try:
request_id = self.web3.toHex(event['args']['_paymentId'])
# check keeper for the status of this access request, if the status is not committed should be ignored.
Expand Down
13 changes: 0 additions & 13 deletions provider/app/resource_constants.py

This file was deleted.

9 changes: 5 additions & 4 deletions provider/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from flask_swagger import swagger
from flask_swagger_ui import get_swaggerui_blueprint
from flask import jsonify
from squid_py.config_parser import load_config_section
from provider.constants import BaseURLs, ConfigSections
# from squid_py.config_parser import load_config_section
from squid_py.config import Config
from provider.constants import BaseURLs


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


res_conf = load_config_section(app.config['CONFIG_FILE'], ConfigSections.RESOURCES)
provider_url = '%s://%s:%s' % (res_conf['provider.scheme'], res_conf['provider.host'], res_conf['provider.port'])
config = Config(filename=app.config['CONFIG_FILE'])
provider_url = config.provider_url
# Call factory function to create our blueprint
swaggerui_blueprint = get_swaggerui_blueprint(
BaseURLs.SWAGGER_URL,
Expand Down
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ msrestazure==0.5.0
multidict==4.3.1
multipipes==0.1.0
oauthlib==2.1.0
squid-py==0.1.2
squid-py==0.1.3
oceandb-bigchaindb-driver==0.1.3
oceandb-driver-interface==0.1.11
oceandb-elasticsearch-driver==0.0.1
oceandb-elasticsearch-driver==0.0.2
oceandb-mongodb-driver==0.1.3
parsimonious==0.8.0
pathtools==0.1.2
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.0
current_version = 0.1.1
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/oceanprotocol/provider',
version='0.1.0',
version='0.1.1',
zip_safe=False,
)
Loading

0 comments on commit 70a78fd

Please sign in to comment.