def create_ocean_request(self, query) -> None: ConfigProvider.set_config(Config('../../ocean/config.ini')) # Make a new instance of Ocean ocean = Ocean() # or Ocean(Config('config.ini')) config = ocean.config # make account instance, assuming the ethereum account and password are set # in the config file `config.ini` account = ocean.accounts.list()[0] filename = '../../ocean/bitcoin_2017.csv' did = query['did'] my_data = genfromtxt(filename, delimiter=',') #print('data at', filename, my_data) return my_data #did = 'did:op:71fae96b1d9a4651ba0d3946603fb4c11deb724685f64780985ce32ea2dfe517' service_agreement_id = ocean.assets.order(did, 0, account) # after a short wait (seconds to minutes) the asset data files should be available in the `downloads.path` defined in config # wait a bit to let things happen print(service_agreement_id) time.sleep(20) # Asset files are saved in a folder named after the asset id dataset_dir = os.path.join(ocean.config.downloads_path, f'datafile.{asset_ddo.asset_id}.0') if os.path.exists(dataset_dir): print('asset files downloaded: {}'.format(os.listdir(dataset_dir)))
def get_ocean(config_file): ConfigProvider.set_config(Config(filename=config_file)) ocn = Ocean() ocn.account = get_default_account(ConfigProvider.get_config()) ocn.balance = partial(ocn.accounts.balance, ocn.account) from ocean_cli.api.assets import ( authorize, consume, decrypt, list_assets, order, publish, search ) ocn.authorize = partial(authorize, ocean=ocn) ocn.consume = partial(consume, ocean=ocn) ocn.decrypt = partial(decrypt, ocean=ocn) ocn.order = partial(order, ocean=ocn) ocn.assets.list = partial(list_assets, ocean=ocn) ocn.publish = partial(publish, ocean=ocn) ocn.search = partial(search, ocean=ocn) from ocean_cli.api.conditions import ( check_permissions ) ocn.check_permissions = partial(check_permissions, ocean=ocn) return ocn
def search_assets(): ConfigProvider.set_config(ExampleConfig.get_config()) ocn = Ocean() account = get_account(0) ddo = ocn.assets.create( example_metadata.metadata, account, ) sleep(ASYNC_DELAY) logging.info(f'Registered asset: did={ddo.did}, ddo={ddo.as_text()}') resolved_ddo = ocn.assets.resolve(ddo.did) logging.info( f'resolved asset ddo: did={resolved_ddo.did}, ddo={resolved_ddo.as_text()}' ) ddo_list = ocn.assets.search('bonding curve') logging.info( f'found {len(ddo_list)} assets that contain `bonding curve` in their metadata.' ) ddo_list = ocn.assets.query( {"query": { "text": ['Ocean protocol white paper'] }}) logging.info( f'found {len(ddo_list)} assets with name that contains `Ocean protocol white paper`' )
def buy_asset(): """ Requires all ocean services running. """ ConfigProvider.set_config(ExampleConfig.get_config()) config = ConfigProvider.get_config() # make ocean instance ocn = Ocean() acc = get_publisher_account(config) if not acc: acc = ([acc for acc in ocn.accounts.list() if acc.password] or ocn.accounts.list())[0] # Register ddo ddo = ocn.assets.create(Metadata.get_example(), acc, providers=[acc.address]) logging.info(f'registered ddo: {ddo.did}') # ocn here will be used only to publish the asset. Handling the asset by the publisher # will be performed by the Brizo server running locally keeper = Keeper.get_instance() if 'TEST_LOCAL_NILE' in os.environ and os.environ['TEST_LOCAL_NILE'] == '1': provider = keeper.did_registry.to_checksum_address( '0x413c9ba0a05b8a600899b41b0c62dd661e689354' ) keeper.did_registry.add_provider(ddo.asset_id, provider, acc) logging.debug(f'is did provider: ' f'{keeper.did_registry.is_did_provider(ddo.asset_id, provider)}') cons_ocn = Ocean() consumer_account = get_account_from_config(config, 'parity.address1', 'parity.password1') # sign agreement using the registered asset did above service = ddo.get_service(service_type=ServiceTypes.ASSET_ACCESS) # This will send the purchase request to Brizo which in turn will execute the agreement on-chain cons_ocn.accounts.request_tokens(consumer_account, 100) sa = ServiceAgreement.from_service_dict(service.as_dictionary()) agreement_id = cons_ocn.assets.order( ddo.did, sa.service_definition_id, consumer_account) logging.info('placed order: %s, %s', ddo.did, agreement_id) i = 0 while ocn.agreements.is_access_granted( agreement_id, ddo.did, consumer_account.address) is not True and i < 30: time.sleep(1) i += 1 assert ocn.agreements.is_access_granted(agreement_id, ddo.did, consumer_account.address) ocn.assets.consume( agreement_id, ddo.did, sa.service_definition_id, consumer_account, config.downloads_path) logging.info('Success buying asset.')
def test_consume(client, publisher_ocean_instance, consumer_ocean_instance): Brizo.set_http_client(client) endpoint = BaseURLs.ASSETS_URL + '/consume' pub_acc = get_publisher_account(ConfigProvider.get_config()) cons_acc = get_consumer_account(ConfigProvider.get_config()) asset = get_registered_ddo(publisher_ocean_instance, pub_acc, providers=[pub_acc.address]) metadata = Metadata.get_example() files = metadata['base']['files'] urls = [_file_dict['url'] for _file_dict in files] # This is a trick to give access to provider through the secretstore publisher_ocean_instance.assets.order(asset.did, 'Access', pub_acc, auto_consume=False) # initialize an agreement agreement_id = consumer_ocean_instance.assets.order(asset.did, 'Access', cons_acc, auto_consume=False) payload = dict({ 'serviceAgreementId': agreement_id, 'consumerAddress': cons_acc.address }) signature = Keeper.get_instance().sign_hash(agreement_id, cons_acc) index = 2 # Consume using decrypted url payload['url'] = urls[index] request_url = endpoint + '?' + '&'.join( [f'{k}={v}' for k, v in payload.items()]) i = 0 while i < 30 and not consumer_ocean_instance.agreements.is_access_granted( agreement_id, asset.did, cons_acc.address): time.sleep(1) i += 1 response = client.get(request_url) assert response.status == '200 OK' # Consume using url index and signature (let brizo do the decryption) payload.pop('url') payload['signature'] = signature payload['index'] = index request_url = endpoint + '?' + '&'.join( [f'{k}={v}' for k, v in payload.items()]) response = client.get(request_url) assert response.status == '200 OK'
def resolve_asset(): ConfigProvider.set_config(ExampleConfig.get_config()) ocn = Ocean() account = ([acc for acc in ocn.accounts.list() if acc.password] or ocn.accounts.list())[0] ddo = ocn.assets.create( Metadata.get_example(), account, ) sleep(ASYNC_DELAY) logging.info(f'Registered asset: did={ddo.did}, ddo={ddo.as_text()}') resolved_ddo = ocn.assets.resolve(ddo.did) logging.info(f'resolved asset ddo: did={resolved_ddo.did}, ddo={resolved_ddo.as_text()}')
def resolve_asset(): ConfigProvider.set_config(ExampleConfig.get_config()) ocn = Ocean() account = get_account(0) ddo = ocn.assets.create( example_metadata.metadata, account, ) sleep(ASYNC_DELAY) logging.info(f'Registered asset: did={ddo.did}, ddo={ddo.as_text()}') resolved_ddo = ocn.assets.resolve(ddo.did) logging.info(f'resolved asset ddo: did={resolved_ddo.did}, ddo={resolved_ddo.as_text()}')
def sign_service_agreement(): ConfigProvider.set_config(ExampleConfig.get_config()) # make ocean instance and register an asset ocn = Ocean() acc = get_account(0) ddo = ocn.assets.create(example_metadata.metadata, acc) consumer_account = get_account(1) agreement_id, signature = ocn.agreements.prepare(ddo.did, consumer_account) sleep(ASYNC_DELAY) logging.info(f'service agreement signed: ' f'\nservice agreement id: {agreement_id}, ' f'\nsignature: {signature}')
def get_provider_account(ocean_instance): address = ConfigProvider.get_config().parity_address logger.info( f'address: {address}, {ocean_instance.accounts.accounts_addresses}') for acc in ocean_instance.accounts.list(): if acc.address.lower() == address.lower(): return acc
def __init__(self, ocean_instance=None, account=None): self.ocean_instance = ocean_instance if not ocean_instance: from tests.resources.helper_functions import get_publisher_ocean_instance self.ocean_instance = get_publisher_ocean_instance( init_tokens=False, use_ss_mock=False, use_brizo_mock=False) self.account = account if not account: from tests.resources.helper_functions import get_publisher_account self.account = get_publisher_account(ConfigProvider.get_config())
def sign_service_agreement(): ConfigProvider.set_config(ExampleConfig.get_config()) config = ConfigProvider.get_config() # make ocean instance and register an asset ocn = Ocean() acc = ([acc for acc in ocn.accounts.list() if acc.password] or ocn.accounts.list())[0] ddo = ocn.assets.create(Metadata.get_example(), acc) consumer_account = get_account_from_config(config, 'parity.address1', 'parity.password1') service = ddo.get_service(service_type=ServiceTypes.ASSET_ACCESS) agreement_id, signature = ocn.agreements.prepare( ddo.did, service.service_definition_id, consumer_account) sleep(ASYNC_DELAY) logging.info(f'service agreement signed: ' f'\nservice agreement id: {agreement_id}, ' f'\nsignature: {signature}')
def create_compute_service_descriptor(self, attributes): """ :param attributes: """ brizo = BrizoProvider.get_brizo() config = ConfigProvider.get_config() compute_endpoint = brizo.get_compute_endpoint(config) template_id = self._keeper.get_agreement_template_id( ServiceTypes.CLOUD_COMPUTE) return ServiceDescriptor.compute_service_descriptor( attributes=attributes, service_endpoint=compute_endpoint, template_id=template_id)
def ocean_agreements(): keeper = Keeper.get_instance() w3 = Web3Provider.get_web3() did_resolver = Mock() ddo = get_ddo_sample() service = ddo.get_service(ServiceTypes.ASSET_ACCESS) service.update_value( ServiceAgreementTemplate.TEMPLATE_ID_KEY, w3.toChecksumAddress("0x00bd138abd70e2f00903268f3db08f2d25677c9e")) did_resolver.resolve = MagicMock(return_value=ddo) # consumer_class = Mock # consumer_class.download = MagicMock(return_value='') return OceanAgreements(keeper, did_resolver, AssetConsumer, AssetExecutor, ConfigProvider.get_config())
def consume_asset(event, agreement_id, did, service_agreement, consumer_account, consume_callback): """ Consumption of an asset after get the event call. :param event: AttributeDict with the event data. :param agreement_id: id of the agreement, hex str :param did: DID, str :param service_agreement: ServiceAgreement instance :param consumer_account: Account instance of the consumer :param consume_callback: """ logger.debug(f"consuming asset after event {event}.") if consume_callback: config = ConfigProvider.get_config() secret_store = SecretStoreProvider.get_secret_store( config.secret_store_url, config.parity_url, consumer_account) brizo = BrizoProvider.get_brizo() consume_callback( agreement_id, service_agreement.service_definition_id, DIDResolver(Keeper.get_instance().did_registry).resolve(did), consumer_account, ConfigProvider.get_config().downloads_path, brizo, secret_store)
def check_output_dict(output_def, consumer_account): config = ConfigProvider.get_config() default_output_def = { 'nodeUri': config.keeper_url, 'brizoUri': BrizoProvider.get_brizo().get_brizo_url(config), 'brizoAddress': config.provider_address, 'metadata': dict(), 'metadataUri': config.aquarius_url, 'secretStoreUri': config.secret_store_url, 'owner': consumer_account.address, 'publishOutput': 0, 'publishAlgorithmLog': 0, 'whitelist': [], } output_def = output_def if isinstance(output_def, dict) else dict() default_output_def.update(output_def) return default_output_def
def get_consumer_ocean_instance(init_tokens=True, use_ss_mock=True, use_brizo_mock=True): ocn = make_ocean_instance(CONSUMER_INDEX) account = get_consumer_account(ConfigProvider.get_config()) if account.address in ocn.accounts.accounts_addresses: ocn.main_account = account else: ocn.main_account = ocn.accounts.list()[1] if init_tokens: init_ocn_tokens(ocn, ocn.main_account) if use_ss_mock: SecretStoreProvider.set_secret_store_class(SecretStoreMock) if use_brizo_mock: BrizoProvider.set_brizo_class(BrizoMock) return ocn
def test_secret_store_encrypt_decrypt(): test_document = get_resource_path('ddo', 'ddo_sample1.json') with open(test_document, 'r') as file_handle: metadata = json.load(file_handle) metadata_json = json.dumps(metadata) document_id = hashlib.sha256( (metadata_json + secrets.token_hex(32)).encode()).hexdigest() print(document_id) config = ConfigProvider.get_config() ss_client = Mock ss_client.publish_document = MagicMock(return_value='!!document!!') ss_client.decrypt_document = MagicMock(return_value=metadata_json) SecretStore.set_client(ss_client) ss_args = (config.secret_store_url, config.parity_url, Account('0x0000', 'aaa')) result = SecretStore(*ss_args).encrypt_document(document_id, metadata_json) print(result) assert SecretStore(*ss_args).decrypt_document(document_id, result) == metadata_json
def consume_brizo(ocean, account, did, agreement_id, token): service_endpoint = get_service_endpoint(ocean, did) destination = ConfigProvider.get_config().downloads_path if not os.path.isabs(destination): destination = os.path.abspath(destination) if not os.path.exists(destination): os.mkdir(destination) asset_folder = os.path.join(destination, f'datafile.{did_to_id(did)}') if not os.path.exists(asset_folder): os.mkdir(asset_folder) BrizoProvider.get_brizo().consume_service(agreement_id, service_endpoint, account, token, asset_folder, None) files = os.listdir(asset_folder) return { 'agreement': agreement_id, 'path': asset_folder.split('tuna/')[-1] + '/', 'files': files }
def __init__(self, name=None, store=None, options=None): self.name = name if name else conf['slack']['name'] self.ocean = Ocean(Config(filename=conf['ocean']['config'])) self.account = get_default_account(ConfigProvider.get_config()) balance = self.ocean.accounts.balance(self.account) print(balance) self.store = store if store else {} self.options = options if options else \ { 'slack': { 'token': conf['slack']['token.bot'], # bot's user ID in Slack: # value is assigned after the bot starts up 'user_id': None, # 1 second delay between reading from RTM 'rtm_read_delay': 1, }, } self.connections = { 'slack': SlackClient(self.options['slack']['token']), }
def ocean(ctx, config_file, as_json, verbose): """ Simple CLI for registering and consuming assets in Ocean Protocol \b O , .</ , ____ _______ ____ ,aT&/t ,</ / __ \_______ ___ ____ / ___/ / / _/ o o:\:::::95/b/ / /_/ / __/ -_) _ `/ _ \ / /__/ /___/ / ' >::7:::::U2/)( \____/\__/\__/\_,_/_//_/ \___/____/___/ '*qf/P '</ '<) ' """ if not verbose: logging.getLogger().setLevel(logging.ERROR) ocean = Ocean(Config(filename=config_file)) account = get_default_account(ConfigProvider.get_config()) ctx.obj = { 'account': account, 'ocean': ocean, 'json': as_json }
def setup_things(): config = ConfigProvider.get_config() consumer_acc = get_consumer_account(config) publisher_acc = get_publisher_account(config) keeper = Keeper.get_instance() service_definition_id = 'Access' ddo = get_ddo_sample() ddo._did = DID.did() keeper.did_registry.register(ddo.did, checksum=Web3Provider.get_web3().sha3( text=ddo.metadata['base']['checksum']), url='aquarius:5000', account=publisher_acc, providers=None) registered_ddo = ddo asset_id = registered_ddo.asset_id service_agreement = ServiceAgreement.from_ddo(service_definition_id, ddo) agreement_id = ServiceAgreement.create_new_agreement_id() price = service_agreement.get_price() access_cond_id, lock_cond_id, escrow_cond_id = \ service_agreement.generate_agreement_condition_ids( agreement_id, asset_id, consumer_acc.address, publisher_acc.address, keeper ) return ( keeper, publisher_acc, consumer_acc, agreement_id, asset_id, price, service_agreement, (lock_cond_id, access_cond_id, escrow_cond_id), )
import os import time from squid_py import ( Ocean, ConfigProvider, Config ) ConfigProvider.set_config(Config('config.ini')) # Make a new instance of Ocean ocean = Ocean() # or Ocean(Config('config.ini')) config = ocean.config # make account instance, assuming the ethereum account and password are set # in the config file `config.ini` account = ocean.accounts.list()[0] print('account', account) did = 'did:op:71fae96b1d9a4651ba0d3946603fb4c11deb724685f64780985ce32ea2dfe517' service_agreement_id = ocean.assets.order(did, 0, account) # after a short wait (seconds to minutes) the asset data files should be available in the `downloads.path` defined in config # wait a bit to let things happen print(service_agreement_id) time.sleep(20) # Asset files are saved in a folder named after the asset id dataset_dir = os.path.join(ocean.config.downloads_path, f'datafile.{asset_ddo.asset_id}.0') if os.path.exists(dataset_dir):
from squid_py.did import id_to_did from squid_py.exceptions import OceanDIDNotFound from squid_py.http_requests.requests_session import get_requests_session from squid_py.keeper import Keeper from squid_py.ocean.ocean import Ocean from brizo.log import setup_logging from brizo.myapp import app from brizo.util import (check_required_attributes, get_provider_account) setup_logging() services = Blueprint('services', __name__) config_file = app.config['CONFIG_FILE'] config = Config(filename=config_file) ConfigProvider.set_config(config) # Prepare keeper contracts for on-chain access control # Prepare OceanDB ocn = Ocean() requests_session = get_requests_session() logger = logging.getLogger('brizo') # TODO run in cases of brizo crash or you restart # ocn.execute_pending_service_agreements() @services.route('/publish', methods=['POST']) def publish(): """Encrypt document using the SecretStore and keyed by the given documentId.
def buy_asset(): """ Requires all ocean services running. """ setup_logging(default_level=logging.INFO) ConfigProvider.set_config(ExampleConfig.get_config()) config = ConfigProvider.get_config() providers = { 'duero': '0xfEF2d5e1670342b9EF22eeeDcb287EC526B48095', 'nile': '0x4aaab179035dc57b35e2ce066919048686f82972' } # make ocean instance ocn = Ocean() acc = get_account(1) if not acc: acc = ([acc for acc in ocn.accounts.list() if acc.password] or ocn.accounts.list())[0] Diagnostics.verify_contracts() metadata = example_metadata.metadata.copy() metadata['main']['dateCreated'] = get_timestamp() keeper = Keeper.get_instance() # Register ddo did = '' if did: ddo = ocn.assets.resolve(did) logging.info(f'using ddo: {did}') else: ddo = ocn.assets.create(metadata, acc, providers=[], use_secret_store=True) assert ddo is not None, f'Registering asset on-chain failed.' did = ddo.did logging.info(f'registered ddo: {did}') # ocn here will be used only to publish the asset. Handling the asset by the publisher # will be performed by the Brizo server running locally test_net = os.environ.get('TEST_NET', '') if test_net.startswith('nile'): provider = keeper.did_registry.to_checksum_address(providers['nile']) elif test_net.startswith('duero'): provider = keeper.did_registry.to_checksum_address(providers['duero']) else: provider = '0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0' # Wait for did registry event event = keeper.did_registry.subscribe_to_event( keeper.did_registry.DID_REGISTRY_EVENT_NAME, 30, event_filter={ '_did': Web3Provider.get_web3().toBytes(hexstr=ddo.asset_id), '_owner': acc.address}, wait=True ) if not event: logging.warning(f'Failed to get the did registry event for asset with did {did}.') assert keeper.did_registry.get_block_number_updated(ddo.asset_id) > 0, \ f'There is an issue in registering asset {did} on-chain.' keeper.did_registry.add_provider(ddo.asset_id, provider, acc) logging.info(f'is {provider} set as did provider: ' f'{keeper.did_registry.is_did_provider(ddo.asset_id, provider)}') _providers = keeper.did_registry.get_did_providers(ddo.asset_id) access_template_name = keeper.template_manager.SERVICE_TO_TEMPLATE_NAME['access'] template_id = keeper.template_manager.create_template_id(access_template_name) approved = keeper.template_manager.is_template_approved(template_id) print(f'agreement template approved: {approved}') template_data = keeper.template_manager.get_template(template_id) print(f'access agreement template: {template_data}') cons_ocn = Ocean() consumer_account = get_account(0) # sign agreement using the registered asset did above service = ddo.get_service(service_type=ServiceTypes.ASSET_ACCESS) # This will send the order request to Brizo which in turn will execute the agreement on-chain cons_ocn.accounts.request_tokens(consumer_account, 10) sa = ServiceAgreement.from_json(service.as_dictionary()) agreement_id = '' if not agreement_id: agreement_id = cons_ocn.assets.order( did, sa.index, consumer_account) logging.info('placed order: %s, %s', did, agreement_id) event = keeper.agreement_manager.subscribe_agreement_created( agreement_id, 60, None, (), wait=True ) assert event, "Agreement event is not found, check the keeper node's logs" logging.info(f'Got agreement event, next: lock reward condition') event = keeper.lock_reward_condition.subscribe_condition_fulfilled( agreement_id, 60, None, (), wait=True ) assert event, "Lock reward condition fulfilled event is not found, check the keeper node's logs" logging.info('Got lock reward event, next: wait for the access condition..') event = keeper.access_secret_store_condition.subscribe_condition_fulfilled( agreement_id, 15, None, (), wait=True ) logging.info(f'Got access event {event}') i = 0 while ocn.agreements.is_access_granted( agreement_id, did, consumer_account.address) is not True and i < 30: time.sleep(1) i += 1 assert ocn.agreements.is_access_granted(agreement_id, did, consumer_account.address) ocn.assets.consume( agreement_id, did, sa.index, consumer_account, config.downloads_path) logging.info('Success buying asset.') event = keeper.escrow_reward_condition.subscribe_condition_fulfilled( agreement_id, 30, None, (), wait=True ) assert event, 'no event for EscrowReward.Fulfilled' logging.info(f'got EscrowReward.FULFILLED event: {event}') logging.info('Done buy asset.')
def test_buy_asset(consumer_ocean_instance, publisher_ocean_instance): config = ExampleConfig.get_config() ConfigProvider.set_config(config) keeper = Keeper.get_instance() # :TODO: enable the actual SecretStore # SecretStoreProvider.set_secret_store_class(SecretStore) w3 = Web3Provider.get_web3() pub_acc = get_publisher_account() # Register ddo ddo = get_registered_ddo(publisher_ocean_instance, pub_acc) assert isinstance(ddo, DDO) # ocn here will be used only to publish the asset. Handling the asset by the publisher # will be performed by the Brizo server running locally cons_ocn = consumer_ocean_instance # restore the http client because we want the actual Brizo server to do the work # not the BrizoMock. # Brizo.set_http_client(requests) consumer_account = get_consumer_account() downloads_path_elements = len( os.listdir( consumer_ocean_instance._config.downloads_path)) if os.path.exists( consumer_ocean_instance._config.downloads_path) else 0 # sign agreement using the registered asset did above service = ddo.get_service(service_type=ServiceTypes.ASSET_ACCESS) sa = ServiceAgreement.from_json(service.as_dictionary()) # This will send the consume request to Brizo which in turn will execute the agreement on-chain cons_ocn.accounts.request_tokens(consumer_account, 100) agreement_id = cons_ocn.assets.order(ddo.did, sa.index, consumer_account, auto_consume=False) event_wait_time = 10 event = keeper.escrow_access_secretstore_template.subscribe_agreement_created( agreement_id, event_wait_time, log_event( keeper.escrow_access_secretstore_template.AGREEMENT_CREATED_EVENT), (), wait=True) assert event, 'no event for EscrowAccessSecretStoreTemplate.AgreementCreated' event = keeper.lock_reward_condition.subscribe_condition_fulfilled( agreement_id, event_wait_time, log_event(keeper.lock_reward_condition.FULFILLED_EVENT), (), wait=True) assert event, 'no event for LockRewardCondition.Fulfilled' # give access publisher_ocean_instance.agreements.conditions.grant_access( agreement_id, ddo.did, consumer_account.address, pub_acc) event = keeper.access_secret_store_condition.subscribe_condition_fulfilled( agreement_id, event_wait_time, log_event(keeper.access_secret_store_condition.FULFILLED_EVENT), (), wait=True) assert event, 'no event for AccessSecretStoreCondition.Fulfilled' assert cons_ocn.agreements.is_access_granted(agreement_id, ddo.did, consumer_account.address) assert cons_ocn.assets.consume(agreement_id, ddo.did, sa.index, consumer_account, config.downloads_path) assert len(os.listdir( config.downloads_path)) == downloads_path_elements + 1 # Check that we can consume only an specific file in passing the index. assert cons_ocn.assets.consume(agreement_id, ddo.did, sa.index, consumer_account, config.downloads_path, 2) assert len(os.listdir( config.downloads_path)) == downloads_path_elements + 1 with pytest.raises(AssertionError): cons_ocn.assets.consume(agreement_id, ddo.did, sa.index, consumer_account, config.downloads_path, -2) with pytest.raises(AssertionError): cons_ocn.assets.consume(agreement_id, ddo.did, sa.index, consumer_account, config.downloads_path, 3) # decrypt the contentUrls using the publisher account instead of consumer account. # if the secret store is working and ACL check is enabled, this should fail # since SecretStore decrypt will fail the checkPermissions check try: cons_ocn.assets.consume(agreement_id, ddo.did, sa.index, pub_acc, config.downloads_path) except RPCError: print('hooray, secret store is working as expected.') publisher_ocean_instance.agreements.conditions.release_reward( agreement_id, sa.get_price(), pub_acc) event = keeper.escrow_reward_condition.subscribe_condition_fulfilled( agreement_id, event_wait_time + 20, log_event(keeper.escrow_reward_condition.FULFILLED_EVENT), (), wait=True) assert event, 'no event for EscrowReward.Fulfilled' assert w3.toHex(event.args['_agreementId']) == agreement_id
def get_consumer_ocean_instance(): ocn = make_ocean_instance() account = get_consumer_account(ConfigProvider.get_config()) init_ocn_tokens(ocn, account) ocn.main_account = account return ocn
def make_ocean_instance(): path_config = 'config_local.ini' os.environ['CONFIG_FILE'] = path_config ConfigProvider.set_config(Config(path_config)) ocn = Ocean() return ocn
def get_env_property(env_variable, property_name): return getenv( env_variable, ConfigProvider.get_config().get(ConfigSections.OSMOSIS, property_name))
from ocean_keeper.web3_provider import Web3Provider from ocean_utils.aquarius import AquariusProvider from examples import ExampleConfig from squid_py import ConfigProvider from squid_py.ocean.keeper import SquidKeeper as Keeper from tests.resources.helper_functions import ( get_consumer_ocean_instance, get_metadata, get_publisher_account, get_publisher_ocean_instance, get_registered_ddo, setup_logging) from tests.resources.mocks.secret_store_mock import SecretStoreMock from tests.resources.tiers import should_run_test setup_logging() if should_run_test('e2e'): ConfigProvider.set_config(ExampleConfig.get_config()) @pytest.fixture def setup_all(): config = ExampleConfig.get_config() Web3Provider.init_web3(config.keeper_url) ContractHandler.set_artifacts_path(config.keeper_path) Keeper.get_instance() @pytest.fixture def secret_store(): return SecretStoreMock
data = {} response = jsonify(data) response.status_code = status_code abort(response) # Asset files are saved in a folder named after the asset id def find_csv(asset_id): path = os.path.join(ocean.config.downloads_path, f'datafile.{asset_id}.0') csv_files = [f for f in os.listdir(path) if f.endswith('.csv')] return os.path.join(path, csv_files[0]) if csv_files else None app = Flask(__name__) CORS(app) ConfigProvider.set_config(demo_config) # ocean = Ocean() ocean = Ocean( Config('config_local.ini') ) # use local or regular config for production pacific network usage. config = ocean.config accounts = ocean.accounts.list() if accounts: account = accounts[0] # take first account as primary source. @app.route('/', methods=['GET']) def hello(): return "Welcome to Oceanapi"