Ejemplo n.º 1
0
def test_config():
    test_config = os.path.join(
        pathlib.Path(__file__).parent, "resources/test-config.txt")
    _config = Config(filename=test_config)

    assert _config.storage_path == "ocean-provider.db"

    for i, envname in enumerate(environ_names.keys()):
        os.environ[envname] = f"some-value-{i}"

    os.environ[environ_names[NAME_STORAGE_PATH][0]] = "new-storage.db"
    _config = Config(test_config)
    assert _config.storage_path == "new-storage.db"
Ejemplo n.º 2
0
def setup_network(config_file=None):
    config = Config(filename=config_file) if config_file else get_config()
    network_url = config.network_url
    artifacts_path = get_artifacts_path(config)

    ContractHandler.set_artifacts_path(artifacts_path)

    if network_url.startswith('http'):
        provider = CustomHTTPProvider
    elif network_url.startswith('wss'):
        provider = WebsocketProvider
    else:
        raise AssertionError(f'Unsupported network url {network_url}. Must start with http or wss.')

    Web3Provider.init_web3(provider=provider(network_url))
    if network_url.startswith('wss'):
        from web3.middleware import geth_poa_middleware
        Web3Provider.get_web3().middleware_stack.inject(geth_poa_middleware, layer=0)

    init_account_envvars()

    wallet = get_provider_wallet()
    if wallet is None:
        raise AssertionError(f'Ocean Provider cannot run without a valid '
                             f'ethereum account. `PROVIDER_PRIVATE_KEY` was not found in the environment '
                             f'variables. \nENV WAS: {sorted(os.environ.items())}')

    if not wallet.private_key:
        raise AssertionError(f'Ocean Provider cannot run without a valid '
                             f'ethereum private key..')
Ejemplo n.º 3
0
def setup_network(config_file=None):
    config = Config(filename=config_file) if config_file else get_config()
    network_url = config.network_url
    artifacts_path = get_artifacts_path(config)

    ContractHandler.set_artifacts_path(artifacts_path)
    w3_connection_provider = get_web3_connection_provider(network_url)
    Web3Provider.init_web3(provider=w3_connection_provider)
    if network_url.startswith("wss"):
        from web3.middleware import geth_poa_middleware

        Web3Provider.get_web3().middleware_stack.inject(geth_poa_middleware,
                                                        layer=0)

    init_account_envvars()

    wallet = get_provider_wallet()
    if wallet is None:
        raise AssertionError(
            f"Ocean Provider cannot run without a valid "
            f"ethereum account. `PROVIDER_PRIVATE_KEY` was not found in the environment "
            f"variables. \nENV WAS: {sorted(os.environ.items())}")

    if not wallet.private_key:
        raise AssertionError(
            "Ocean Provider cannot run without a valid ethereum private key.")
Ejemplo n.º 4
0
def setup_network(config_file=None):
    config = Config(filename=config_file) if config_file else get_config()
    keeper_url = config.keeper_url
    artifacts_path = get_keeper_path(config)

    ContractHandler.set_artifacts_path(artifacts_path)
    if keeper_url.startswith('http'):
        provider = CustomHTTPProvider
    elif keeper_url.startswith('wss'):
        provider = WebsocketProvider
    else:
        raise AssertionError(f'Unsupported network url {keeper_url}. Must start with http or wss.')

    Web3Provider.init_web3(provider=provider(keeper_url))
    from web3.middleware import geth_poa_middleware
    Web3Provider.get_web3().middleware_stack.inject(geth_poa_middleware, layer=0)

    init_account_envvars()

    account = get_account(0)
    if account is None:
        raise AssertionError(f'Ocean Provider cannot run without a valid '
                             f'ethereum account. Account address was not found in the environment'
                             f'variable `PROVIDER_ADDRESS`. Please set the following environment '
                             f'variables and try again: `PROVIDER_ADDRESS`, [`PROVIDER_PASSWORD`, '
                             f'and `PROVIDER_KEYFILE` or `PROVIDER_ENCRYPTED_KEY`] or `PROVIDER_KEY`.')

    if not account._private_key and not (account.password and account._encrypted_key):
        raise AssertionError(f'Ocean Provider cannot run without a valid '
                             f'ethereum account with either a `PROVIDER_PASSWORD` '
                             f'and `PROVIDER_KEYFILE`/`PROVIDER_ENCRYPTED_KEY` '
                             f'or private key `PROVIDER_KEY`. Current account has password {account.password}, '
                             f'keyfile {account.key_file}, encrypted-key {account._encrypted_key} '
                             f'and private-key {account._private_key}.')
Ejemplo n.º 5
0
def get_config():
    config_file = os.getenv('CONFIG_FILE', 'config.ini')
    return Config(filename=config_file)
Ejemplo n.º 6
0
#  SPDX-License-Identifier: Apache-2.0

import configparser

from flask import jsonify
from flask_swagger import swagger
from flask_swagger_ui import get_swaggerui_blueprint

from ocean_provider.config import Config
from ocean_provider.constants import BaseURLs, ConfigSections, Metadata
from ocean_provider.myapp import app
from ocean_provider.routes import services
from ocean_provider.utils.accounts import get_provider_account

get_provider_account()
config = Config(filename=app.config['CONFIG_FILE'])
provider_url = config.get(ConfigSections.RESOURCES, 'ocean_provider.url')


def get_version():
    conf = configparser.ConfigParser()
    conf.read('.bumpversion.cfg')
    return conf['bumpversion']['current_version']


@app.route("/")
def version():
    info = dict()
    info['software'] = Metadata.TITLE
    info['version'] = get_version()
    info['network-url'] = config.network_url
Ejemplo n.º 7
0
# SPDX-License-Identifier: Apache-2.0
#

import configparser

from flask import jsonify
from flask_swagger import swagger
from flask_swagger_ui import get_swaggerui_blueprint
from ocean_provider.config import Config
from ocean_provider.constants import BaseURLs, ConfigSections, Metadata
from ocean_provider.myapp import app
from ocean_provider.routes import services
from ocean_provider.util import get_compute_address
from ocean_provider.utils.basics import get_provider_wallet

config = Config(filename=app.config["CONFIG_FILE"])
provider_url = config.get(ConfigSections.RESOURCES, "ocean_provider.url")
# not included URLs
blocked_url = ["services.simple_flow_consume"]


def get_services_endpoints():
    services_endpoints = dict(
        map(
            lambda url: (url.endpoint.replace("services.", ""), url),
            filter(
                lambda url: url.endpoint.startswith("services.") and url.
                endpoint not in blocked_url,
                app.url_map.iter_rules(),
            ),
        ))
Ejemplo n.º 8
0
def get_config():
    config_file = os.getenv("CONFIG_FILE", "config.ini")
    return Config(filename=config_file)