Ejemplo n.º 1
0
 def __init__(self, hadoop_dir, cluster=None):
     self.hadoop_dir = hadoop_dir
     # need mapred-site.xml
     self.config = ConfigFactory.get_config( \
             "%s/conf/mapred-site.xml" % hadoop_dir)
     self.cluster = cluster
     self.running = False
     self._jtpid = None
     self._ttpid = None
Ejemplo n.º 2
0
 def __init__(self, hadoop_dir, cluster=None):
     self.hadoop_dir = hadoop_dir
     # need mapred-site.xml
     self.config = ConfigFactory.get_config( \
             "%s/conf/mapred-site.xml" % hadoop_dir)
     self.cluster = cluster
     self.running = False
     self._jtpid = None
     self._ttpid = None
Ejemplo n.º 3
0
    def run(cls, eth_passphrase, eth_auth_token, sol_file):
        """
        Runs the backend
        """
        # Note: except for stream_logger, every other import
        # to a subpackage of qsp_prototol_node must be
        # performed at this point

        from audit import QSPAuditNode
        from config import ConfigFactory
        from utils.stop import Stop

        cfg = ConfigFactory.create_from_dictionary(
            Program.__yaml_config,
            Program.__env,
            account_passwd=eth_passphrase,
            auth_token=eth_auth_token,
        )

        logger.info("Initializing QSP Audit Node")
        logger.debug("account: {0}".format(cfg.account))
        logger.debug("analyzers: {0}".format(cfg.analyzers))
        logger.debug("audit contract address: {0}".format(
            cfg.audit_contract_address))

        logger.debug("min_price_in_qsp: {0}".format(cfg.min_price_in_qsp))
        logger.debug("evt_polling: {0}".format(cfg.evt_polling))
        logger.debug("audit contract address: {0}".format(
            cfg.audit_contract_address))

        # Based on the provided configuration, instantiates a new
        # QSP audit node
        audit_node = QSPAuditNode(cfg)
        Stop.register(audit_node)

        if QSPAuditNode.is_police_officer(cfg):
            logger.info("Running QSP node (performs audits and police checks)")
        else:
            logger.info("Running QSP node (performs audits only)")

        # If a sol file is given, produce the audit report for that file and exit
        if sol_file:
            _, audit_report = audit_node.get_full_report(requestor=cfg.account,
                                                         uri=sol_file,
                                                         request_id=1)
            pprint(audit_report)
        # Runs the QSP audit node in a busy loop fashion
        else:
            try:
                audit_node.start()
            except Exception as error:
                if audit_node is not None:
                    audit_node.stop()
                    raise error
Ejemplo n.º 4
0
 def test_create_analyzers(self):
     analyzers_config = "config list"
     logger = "logger"
     return_value = "value"
     config = ConfigFactory.create_empty_config()
     config._Config__analyzers_config = analyzers_config
     config._Config__logger = logger
     utils = ConfigUtilsMock()
     utils.expect('create_analyzers',
                  {'analyzers_config': analyzers_config, 'logger': logger},
                  return_value)
     result = config._Config__create_analyzers(utils)
     self.assertEqual(return_value, result)
     utils.verify()
Ejemplo n.º 5
0
 def test_create_eth_provider(self):
     name = "provider name"
     args = "arguments"
     return_value = "value"
     config = ConfigFactory.create_empty_config()
     config._Config__eth_provider_name = name
     config._Config__eth_provider_args = args
     utils = ConfigUtilsMock()
     utils.expect('create_eth_provider',
                  {'provider': name, 'args': args},
                  return_value)
     result = config._Config__create_eth_provider(utils)
     self.assertEqual(return_value, result)
     utils.verify()
Ejemplo n.º 6
0
 def test_load_config(self):
     config_file_uri = resource_uri("test_config.yaml")
     config = ConfigFactory.create_from_file(config_file_uri, "dev", validate_contract_settings=False)
     self.assertIsNotNone(config.eth_provider)
     self.assertIsNotNone(config.web3_client)
     self.assertIsNotNone(config.account)
     self.assertIsNotNone(config.analyzers)
     self.assertIsNotNone(config.upload_provider)
     self.assertIsNotNone(config.metric_collection_destination_endpoint)
     self.assertEqual(5, config.min_price_in_qsp)
     self.assertEqual(0, config.gas_price_wei)
     self.assertEqual(5, config.evt_polling)
     self.assertEqual(2, len(config.analyzers))
     self.assertEqual(5, config.start_n_blocks_in_the_past)
     self.assertEqual(1, config.block_discard_on_restart)
     self.assertFalse(config.enable_police_audit_polling)
Ejemplo n.º 7
0
 def test_create_web3_client(self):
     eth_provider = "eth_provider"
     account_passwd = "account password"
     account_keystore_file = "./mykey.json"
     created_web3_provider = "created provider"
     config = ConfigFactory.create_empty_config()
     config._Config__eth_provider = eth_provider
     config._Config__account_passwd = account_passwd
     config._Config__account_keystore_file = account_keystore_file
     utils = ConfigUtilsMock()
     utils.expect('create_web3_client',
                  {'eth_provider': eth_provider, 'account_passwd': account_passwd,
                   'keystore_file': account_keystore_file, 'max_attempts': 30},
                  created_web3_provider)
     result = config._Config__create_web3_client(utils)
     self.assertEqual(created_web3_provider, result)
     utils.verify()
Ejemplo n.º 8
0
 def test_initialize(self):
     config_file_uri = resource_uri("test_config.yaml")
     config = ConfigFactory.create_from_file(
         config_file_uri, "dev", validate_contract_settings=False)
     log_streaming.initialize("account",
                              config_value(config, "/logging/streaming",
                                           {}),
                              force=True)
     self.assertEqual(get_config(), {})
     self.assertEqual(get_account(), "account")
     self.assertEqual(get_loggers(), {})
     try:
         log_streaming.initialize("account", {})
         self.fail("An exception was expected")
     except Exception:
         # expected
         pass
Ejemplo n.º 9
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(ConfigFactory.factory().__class__)

    # # init extensions
    db.init_app(app)
    migrate.init_app(app, db)
    ma.init_app(app)

    # # add custom commands
    app.cli.add_command(sync_teams)
    app.cli.add_command(sync_players)
    app.cli.add_command(sync_seasons)
    app.cli.add_command(sync_games)
    app.cli.add_command(sync_new_games)

    with app.app_context():

        # import database models
        from app.database.models.season import SeasonModel
        from app.database.models.team import TeamModel
        from app.database.models.player import PlayerModel
        from app.database.models.game import GameModel
        from app.database.models.player_team_season import PlayerSeasonTeamModel
        from app.database.models.teams_stats import TeamsStatsModel
        from app.database.models.players_stats import PlayersStatsModel

        # # import blueprints
        # views
        from app.views.home import home_bp
        from app.views.season import season_bp
        from app.views.team import team_bp
        from app.views.player import player_bp
        from app.views.game import game_bp
        
        # register blueprints
        # views
        app.register_blueprint(home_bp, url_prefix="/home")
        app.register_blueprint(season_bp, url_prefix="/api/season")
        app.register_blueprint(team_bp, url_prefix="/api/team")
        app.register_blueprint(player_bp, url_prefix="/api/player")
        app.register_blueprint(game_bp, url_prefix="/api/game")
        # # end import blueprints

        return app
Ejemplo n.º 10
0
    def test_inject_token_auth(self):
        auth_token = "abc123456"
        endpoint = "https://test.com/?token={0}".format(auth_token)
        target_env = "dev"

        # Sets the dictionary to be returned by a call to load_config
        config_file = fetch_file(resource_uri("test_config_with_auth_token.yaml"))
        config_yaml = load_yaml(config_file)
        dummy_utils = ConfigUtilsDummy({'load_config': config_yaml[target_env]})

        config = ConfigFactory.create_from_file(
            environment=target_env,
            config_file_uri="some dummy uri",
            auth_token=auth_token,
            validate_contract_settings=False,
            config_utils=dummy_utils,
        )
        self.assertEqual(config.auth_token, auth_token)
        self.assertEqual(config.eth_provider_args['endpoint_uri'], endpoint)
Ejemplo n.º 11
0
 def test_create_upload_provider(self):
     account = "account"
     upload_provider_name = "provider name"
     upload_provider_args = "arguments"
     upload_provider = "value"
     config = ConfigFactory.create_empty_config()
     config._Config__account = account
     config._Config__upload_provider_name = upload_provider_name
     config._Config__upload_provider_is_enabled = True
     config._Config__upload_provider_args = upload_provider_args
     utils = ConfigUtilsMock()
     utils.expect('create_upload_provider',
                  {'account': account,
                   'upload_provider_name': upload_provider_name,
                   'upload_provider_args': upload_provider_args,
                   'upload_provider_is_enabled': True},
                  upload_provider)
     result = config._Config__create_upload_provider(utils)
     self.assertEqual(upload_provider, result)
     utils.verify()
Ejemplo n.º 12
0
def fetch_config(inject_contract=False):
    # create config from file, the contract is not provided and will be injected separately
    config_file_uri = resource_uri("test_config.yaml")
    config = ConfigFactory.create_from_file(config_file_uri,
                                            os.getenv("QSP_ENV",
                                                      default="dev"),
                                            validate_contract_settings=False)
    if inject_contract:
        contract_source_uri = "./tests/resources/QuantstampAuditMock.sol"
        contract_metadata_uri = "./tests/resources/QuantstampAudit-metadata.json"
        audit_contract_metadata = load_json(fetch_file(contract_metadata_uri))
        audit_contract_name = get(audit_contract_metadata, '/contractName')

        addr, contract = __load_audit_contract_from_src(
            config.web3_client, contract_source_uri, audit_contract_name,
            config.account)

        config._Config__audit_contract_address = addr
        config._Config__audit_contract = contract

        config_utils = ConfigUtils(config.node_version)
        config_utils.check_configuration_settings(config)

    return config
Ejemplo n.º 13
0
 def test_create_components(self):
     eth_provider_name = "eth provider name"
     eth_provider_args = "eth provider arguments"
     created_eth_provider = "created_eth_provider"
     new_account = "0xc1220b0bA0760817A9E8166C114D3eb2741F5949"
     account_passwd = "account password"
     account_keystore_file = "./mykey.json"
     new_private_key = "abcdefg"
     account = "0x12345"
     analyzers_config = "config list"
     created_analyzers = "analyzers"
     upload_provider_name = "upload provider name"
     upload_provider_args = "upload provider arguments"
     upload_provider = "created upload provier"
     audit_contract_abi_uri = "some uri"
     audit_contract_address = "0xc1220b0bA0760817A9E8166C114D3eb2741F5949"
     created_audit_contract = "contract"
     created_web3_client = Web3Mock()
     config = ConfigFactory.create_empty_config()
     config._Config__eth_provider_name = eth_provider_name
     config._Config__eth_provider_args = eth_provider_args
     config._Config__account = account
     config._Config__account_passwd = account_passwd
     config._Config__account_keystore_file = account_keystore_file
     config._Config__analyzers_config = analyzers_config
     config._Config__evt_db_path = "/tmp/evts.test"
     config._Config__upload_provider_name = upload_provider_name
     config._Config__upload_provider_args = upload_provider_args
     config._Config__upload_provider_is_enabled = True
     config._Config__audit_contract_abi_uri = audit_contract_abi_uri
     config._Config__audit_contract_address = audit_contract_address
     utils = ConfigUtilsMock()
     utils.expect('create_eth_provider',
                 {'provider': eth_provider_name, 'args': eth_provider_args},
                 created_eth_provider)
     utils.expect('create_web3_client',
                  {'eth_provider': created_eth_provider, 'account_passwd': account_passwd,
                   'keystore_file': account_keystore_file, 'max_attempts': 30},
                  (created_web3_client, new_account, new_private_key))
     utils.expect('check_audit_contract_settings',
                  {'config': config},
                  None)
     utils.expect('create_contract',
                  {'web3_client': created_web3_client, 'audit_contract_abi_uri': audit_contract_abi_uri,
                   'audit_contract_address': audit_contract_address},
                  created_audit_contract)
     utils.expect('check_configuration_settings',
                  {'config': config},
                  None)
     utils.expect('create_analyzers',
                  {'analyzers_config': analyzers_config},
                  created_analyzers)
     utils.expect('create_upload_provider',
                  {'account': new_account,
                   'upload_provider_name': upload_provider_name,
                   'upload_provider_args': upload_provider_args,
                   'upload_provider_is_enabled': True},
                  upload_provider)
     config._Config__create_components(utils)
     self.assertEqual(created_eth_provider, config.eth_provider)
     self.assertEqual(created_web3_client, config.web3_client)
     self.assertEqual(new_account, config.account)
     self.assertEqual(created_analyzers, config.analyzers)
     self.assertEqual(upload_provider, config.upload_provider)
     self.assertEqual(created_audit_contract, config.audit_contract)
     utils.verify()
Ejemplo n.º 14
0
def read_config(config_file_name):
    try:
        config = ConfigFactory.from_yaml_file(config_file_name)
    except ConfigException, e:
        print e.message
        sys.exit(2)
Ejemplo n.º 15
0
import logging
import traceback

from flask import Flask
from flask_restful import Api
from flask_sqlalchemy import SQLAlchemy
from flask.ext.socketio import SocketIO

from config import ConfigFactory
from common import errors

config = ConfigFactory.build_config()

app = Flask(__name__)
app.config.from_object(config)

api = Api(app, '/v1')
database = SQLAlchemy(app)
socketio = SocketIO(app)


def initialize():
    _initialize_logging()
    _initialize_resources()
    _initialize_socketio()

    socketio.run(app, host=config.HOST, port=config.PORT)


def _initialize_logging():
    # TODO: add more specific configuration parameters
Ejemplo n.º 16
0
import logging
import traceback

from flask import Flask
from flask_restful import Api
from flask_sqlalchemy import SQLAlchemy
from flask.ext.socketio import SocketIO

from config import ConfigFactory
from common import errors

config = ConfigFactory.build_config()

app = Flask(__name__)
app.config.from_object(config)

api = Api(app, "/v1")
database = SQLAlchemy(app)
socketio = SocketIO(app)


def initialize():
    _initialize_logging()
    _initialize_resources()
    _initialize_socketio()

    socketio.run(app, host=config.HOST, port=config.PORT)


def _initialize_logging():
    # TODO: add more specific configuration parameters
Ejemplo n.º 17
0
from flask import Flask
from config import ConfigFactory
from core.routes import register_routes
from core.docs import register_swagger_routes
from storage import register_storage

app = Flask(__name__)

# load configuration
configuration = ConfigFactory().get(app.config['ENV'])
app.config.from_object(configuration)

# define data source and create API endpoints
register_storage(app)
register_routes(app)

if app.config['ENV'] != 'testing':
    register_swagger_routes(app)

if __name__ == '__main__':
    app.run()
Ejemplo n.º 18
0
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
import os

from bot import SynthweetixBot
from config import ConfigType, ConfigFactory

if __name__ == '__main__':
    # Configuration
    app_settings = os.getenv('CONFIGURATION', default='development')
    type_ = ConfigType.reverse_lookup(app_settings)
    cfactory = ConfigFactory()
    config = cfactory.get(type_)

    # Logging
    logging.basicConfig(format='[%(asctime)s] [%(levelname)s] %(message)s',
                        level=config.LOG_LEVEL)

    logging.info(f'Initializing Synthweetix in {app_settings} environment')
    bot = SynthweetixBot(
        config.TWITTER_CONSUMER_KEY, config.TWITTER_CONSUMER_SECRET,
        config.TWITTER_ACCESS_TOKEN, config.TWITTER_ACCESS_SECRET,
        config.ETHERSCAN_API_KEY, config.TRADE_VALUE_THRESHOLD,
        config.EYE_CATCHER_THRESHOLD)

    # Run once on startup
    bot.execute()

    # Run the bot periodically
    if config.TRIGGER is not None:  # In case the bot is deployed as a Heroku or Docker cron job.
        scheduler = BlockingScheduler()