def __init__(self, public_key=None, private_key=None, api_endpoint=None, consensus_plugin=None): """Initialize the Client instance There are three ways in which the Client instance can get its parameters. The order by which the parameters are chosen are: 1. Setting them by passing them to the `__init__` method itself. 2. Setting them as environment variables 3. Reading them from the `config.json` file. Args: public_key (str): the base58 encoded public key for the ED25519 curve. private_key (str): the base58 encoded private key for the ED25519 curve. api_endpoint (str): a URL where rethinkdb is running. format: scheme://hostname:port consensus_plugin (str): the registered name of your installed consensus plugin. The `core` plugin is built into BigchainDB; others must be installed via pip. """ config_utils.autoconfigure() self.public_key = public_key or bigchaindb.config["keypair"]["public"] self.private_key = private_key or bigchaindb.config["keypair"]["private"] self.api_endpoint = api_endpoint or bigchaindb.config["api_endpoint"] self.consensus = config_utils.load_consensus_plugin(consensus_plugin) if not self.public_key or not self.private_key: raise exceptions.KeypairNotFoundException()
def __init__(self, connection=None): """Initialize the Bigchain instance A Bigchain instance has several configuration parameters (e.g. host). If a parameter value is passed as an argument to the Bigchain __init__ method, then that is the value it will have. Otherwise, the parameter value will come from an environment variable. If that environment variable isn't set, then the value will come from the local configuration file. And if that variable isn't in the local configuration file, then the parameter will have its default value (defined in bigchaindb.__init__). Args: connection (:class:`~bigchaindb.backend.connection.Connection`): A connection to the database. """ config_utils.autoconfigure() self.mode_list = ('broadcast_tx_async', 'broadcast_tx_sync', 'broadcast_tx_commit') self.tendermint_host = bigchaindb.config['tendermint']['host'] self.tendermint_port = bigchaindb.config['tendermint']['port'] self.endpoint = 'http://{}:{}/'.format(self.tendermint_host, self.tendermint_port) consensusPlugin = bigchaindb.config.get('consensus_plugin') if consensusPlugin: self.consensus = config_utils.load_consensus_plugin( consensusPlugin) else: self.consensus = BaseConsensusRules self.connection = connection if connection else backend.connect( **bigchaindb.config['database'])
def __init__(self, host=None, port=None, dbname=None, public_key=None, private_key=None, keyring=[], consensus_plugin=None): """Initialize the Bigchain instance There are three ways in which the Bigchain instance can get its parameters. The order by which the parameters are chosen are: 1. Setting them by passing them to the `__init__` method itself. 2. Setting them as environment variables 3. Reading them from the `config.json` file. Args: host (str): hostname where the rethinkdb is running. port (int): port in which rethinkb is running (usually 28015). dbname (str): the name of the database to connect to (usually bigchain). public_key (str): the base58 encoded public key for the ED25519 curve. private_key (str): the base58 encoded private key for the ED25519 curve. keyring (list[str]): list of base58 encoded public keys of the federation nodes. """ config_utils.autoconfigure() self.host = host or bigchaindb.config['database']['host'] self.port = port or bigchaindb.config['database']['port'] self.dbname = dbname or bigchaindb.config['database']['name'] self.me = public_key or bigchaindb.config['keypair']['public'] self.me_private = private_key or bigchaindb.config['keypair']['private'] self.federation_nodes = keyring or bigchaindb.config['keyring'] self.consensus = config_utils.load_consensus_plugin(consensus_plugin) if not self.me or not self.me_private: raise exceptions.KeypairNotFoundException() self._conn = None
def __init__(self, connection=None): """Initialize the Bigchain instance A Bigchain instance has several configuration parameters (e.g. host). If a parameter value is passed as an argument to the Bigchain __init__ method, then that is the value it will have. Otherwise, the parameter value will come from an environment variable. If that environment variable isn't set, then the value will come from the local configuration file. And if that variable isn't in the local configuration file, then the parameter will have its default value (defined in bigchaindb.__init__). Args: connection (:class:`~bigchaindb.backend.connection.Connection`): A connection to the database. """ config_utils.autoconfigure() consensusPlugin = bigchaindb.config.get('consensus_plugin') if consensusPlugin: self.consensus = config_utils.load_consensus_plugin( consensusPlugin) else: self.consensus = BaseConsensusRules self.connection = connection if connection else backend.connect( **bigchaindb.config['database'])
def __init__(self, connection=None): """Initialize the Bigchain instance A Bigchain instance has several configuration parameters (e.g. host). If a parameter value is passed as an argument to the Bigchain __init__ method, then that is the value it will have. Otherwise, the parameter value will come from an environment variable. If that environment variable isn't set, then the value will come from the local configuration file. And if that variable isn't in the local configuration file, then the parameter will have its default value (defined in bigchaindb.__init__). Args: connection (:class:`~bigchaindb.backend.connection.Connection`): A connection to the database. """ config_utils.autoconfigure() self.mode_commit = 'broadcast_tx_commit' self.mode_list = ('broadcast_tx_async', 'broadcast_tx_sync', self.mode_commit) self.tendermint_host = bigchaindb.config['tendermint']['host'] self.tendermint_port = bigchaindb.config['tendermint']['port'] self.endpoint = 'http://{}:{}/'.format(self.tendermint_host, self.tendermint_port) validationPlugin = bigchaindb.config.get('validation_plugin') if validationPlugin: self.validation = config_utils.load_validation_plugin(validationPlugin) else: self.validation = BaseValidationRules self.connection = connection if connection else backend.connect(**bigchaindb.config['database'])
def __init__(self, public_key=None, private_key=None, api_endpoint=None): """Initialize the Client instance There are three ways in which the Client instance can get its parameters. The order by which the parameters are chosen are: 1. Setting them by passing them to the `__init__` method itself. 2. Setting them as environment variables 3. Reading them from the `config.json` file. Args: public_key (str): the base58 encoded public key for the ECDSA secp256k1 curve. private_key (str): the base58 encoded private key for the ECDSA secp256k1 curve. host (str): hostname where the rethinkdb is running. port (int): port in which rethinkb is running (usually 28015). """ config_utils.autoconfigure() self.public_key = public_key or bigchaindb.config['keypair']['public'] self.private_key = private_key or bigchaindb.config['keypair'][ 'private'] self.api_endpoint = api_endpoint or bigchaindb.config['api_endpoint'] if not self.public_key or not self.private_key: raise exceptions.KeypairNotFoundException()
def test_autoconfigure_env_precedence(monkeypatch): file_config = { 'database': { 'host': 'test-host', 'name': 'bigchaindb', 'port': 28015 } } monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) monkeypatch.setattr( 'os.environ', { 'BIGCHAINDB_DATABASE_NAME': 'test-dbname', 'BIGCHAINDB_DATABASE_PORT': '4242', 'BIGCHAINDB_SERVER_BIND': 'localhost:9985' }) import bigchaindb from bigchaindb import config_utils config_utils.autoconfigure() assert bigchaindb.config['CONFIGURED'] assert bigchaindb.config['database']['host'] == 'test-host' assert bigchaindb.config['database']['name'] == 'test-dbname' assert bigchaindb.config['database']['port'] == 4242 assert bigchaindb.config['server']['bind'] == 'localhost:9985'
def __init__(self, public_key=None, private_key=None, api_endpoint=None, consensus_plugin=None): """Initialize the Client instance There are three ways in which the Client instance can get its parameters. The order by which the parameters are chosen are: 1. Setting them by passing them to the `__init__` method itself. 2. Setting them as environment variables 3. Reading them from the `config.json` file. Args: public_key (str): the base58 encoded public key for the ED25519 curve. private_key (str): the base58 encoded private key for the ED25519 curve. api_endpoint (str): a URL where rethinkdb is running. format: scheme://hostname:port consensus_plugin (str): the registered name of your installed consensus plugin. The `core` plugin is built into BigchainDB; others must be installed via pip. """ config_utils.autoconfigure() self.public_key = public_key or bigchaindb.config['keypair']['public'] self.private_key = private_key or bigchaindb.config['keypair']['private'] self.api_endpoint = api_endpoint or bigchaindb.config['api_endpoint'] self.consensus = config_utils.load_consensus_plugin(consensus_plugin) if not self.public_key or not self.private_key: raise exceptions.KeypairNotFoundException()
def __init__(self, public_key=None, private_key=None, keyring=[], connection=None, backlog_reassign_delay=None): """Initialize the Bigchain instance A Bigchain instance has several configuration parameters (e.g. host). If a parameter value is passed as an argument to the Bigchain __init__ method, then that is the value it will have. Otherwise, the parameter value will come from an environment variable. If that environment variable isn't set, then the value will come from the local configuration file. And if that variable isn't in the local configuration file, then the parameter will have its default value (defined in bigchaindb.__init__). Args: public_key (str): the base58 encoded public key for the ED25519 curve. private_key (str): the base58 encoded private key for the ED25519 curve. keyring (list[str]): list of base58 encoded public keys of the federation nodes. connection (:class:`~bigchaindb.backend.connection.Connection`): A connection to the database. """ config_utils.autoconfigure() self.me = public_key or bigchaindb.config['keypair']['public'] self.me_private = private_key or bigchaindb.config['keypair']['private'] self.nodes_except_me = keyring or bigchaindb.config['keyring'] self.backlog_reassign_delay = backlog_reassign_delay or bigchaindb.config['backlog_reassign_delay'] self.consensus = BaseConsensusRules self.connection = connection if connection else backend.connect(**bigchaindb.config['database']) if not self.me or not self.me_private: raise exceptions.KeypairNotFoundException()
def test_update_config(monkeypatch): import bigchaindb from bigchaindb import config_utils file_config = { 'database': { 'host': 'test-host', 'name': 'bigchaindb', 'port': 28015 } } monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) config_utils.autoconfigure(config=file_config) # update configuration, retaining previous changes config_utils.update_config( {'database': { 'port': 28016, 'name': 'bigchaindb_other' }}) assert bigchaindb.config['database']['host'] == 'test-host' assert bigchaindb.config['database']['name'] == 'bigchaindb_other' assert bigchaindb.config['database']['port'] == 28016
def test_autoconfigure_explicit_file(monkeypatch): from bigchaindb import config_utils def file_config(*args, **kwargs): raise FileNotFoundError() monkeypatch.setattr('bigchaindb.config_utils.file_config', file_config) with pytest.raises(FileNotFoundError): config_utils.autoconfigure(filename='autoexec.bat')
def __init__(self, connection=None, **kwargs): super().__init__(**kwargs) config_utils.autoconfigure() self.mode_list = ('broadcast_tx_async', 'broadcast_tx_sync', 'broadcast_tx_commit') self.tendermint_host = bigchaindb.config['tendermint']['host'] self.tendermint_port = bigchaindb.config['tendermint']['port'] self.endpoint = 'http://{}:{}/'.format(self.tendermint_host, self.tendermint_port) self.connection = connection if connection else backend.connect( **bigchaindb.config['database'])
def __init__(self, host=None, port=None, dbname=None, backend=None, public_key=None, private_key=None, keyring=[], backlog_reassign_delay=None): """Initialize the Bigchain instance A Bigchain instance has several configuration parameters (e.g. host). If a parameter value is passed as an argument to the Bigchain __init__ method, then that is the value it will have. Otherwise, the parameter value will come from an environment variable. If that environment variable isn't set, then the value will come from the local configuration file. And if that variable isn't in the local configuration file, then the parameter will have its default value (defined in bigchaindb.__init__). Args: host (str): hostname where RethinkDB is running. port (int): port in which RethinkDB is running (usually 28015). dbname (str): the name of the database to connect to (usually bigchain). backend (:class:`~bigchaindb.db.backends.rethinkdb.RehinkDBBackend`): the database backend to use. public_key (str): the base58 encoded public key for the ED25519 curve. private_key (str): the base58 encoded private key for the ED25519 curve. keyring (list[str]): list of base58 encoded public keys of the federation nodes. """ config_utils.autoconfigure() self.host = host or bigchaindb.config['database']['host'] self.port = port or bigchaindb.config['database']['port'] self.dbname = dbname or bigchaindb.config['database']['name'] self.backend = backend or get_backend(host, port, dbname) self.me = public_key or bigchaindb.config['keypair']['public'] self.me_private = private_key or bigchaindb.config['keypair']['private'] self.nodes_except_me = keyring or bigchaindb.config['keyring'] self.backlog_reassign_delay = backlog_reassign_delay or bigchaindb.config[ 'backlog_reassign_delay'] self.consensus = BaseConsensusRules # change RethinkDB read mode to majority. This ensures consistency in query results self.read_mode = 'majority' if not self.me or not self.me_private: raise exceptions.KeypairNotFoundException() self.connection = Connection(host=self.host, port=self.port, db=self.dbname)
def test_update_config(monkeypatch): import bigchaindb from bigchaindb import config_utils file_config = { 'database': {'host': 'test-host', 'name': 'bigchaindb', 'port': 28015} } monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) config_utils.autoconfigure(config=file_config) # update configuration, retaining previous changes config_utils.update_config({'database': {'port': 28016, 'name': 'bigchaindb_other'}}) assert bigchaindb.config['database']['host'] == 'test-host' assert bigchaindb.config['database']['name'] == 'bigchaindb_other' assert bigchaindb.config['database']['port'] == 28016
def test_autoconfigure_env_precedence(monkeypatch): file_config = { 'database': {'host': 'test-host', 'name': 'bigchaindb', 'port': 28015} } monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) monkeypatch.setattr('os.environ', {'BIGCHAINDB_DATABASE_NAME': 'test-dbname', 'BIGCHAINDB_DATABASE_PORT': '4242', 'BIGCHAINDB_SERVER_BIND': 'localhost:9985'}) import bigchaindb from bigchaindb import config_utils config_utils.autoconfigure() assert bigchaindb.config['CONFIGURED'] assert bigchaindb.config['database']['host'] == 'test-host' assert bigchaindb.config['database']['name'] == 'test-dbname' assert bigchaindb.config['database']['port'] == 4242 assert bigchaindb.config['server']['bind'] == 'localhost:9985'
def __init__(self, *args, **kwargs): """Overrides statsd client, fixing prefix to messages and loading configuration Args: *args: arguments (identical to Statsclient) **kwargs: keyword arguments (identical to Statsclient) """ config_utils.autoconfigure() if not kwargs: kwargs = {} # set prefix, parameters from configuration file if 'prefix' not in kwargs: kwargs['prefix'] = '{hostname}.'.format(hostname=node()) if 'host' not in kwargs: kwargs['host'] = bigchaindb.config['statsd']['host'] if 'port' not in kwargs: kwargs['port'] = bigchaindb.config['statsd']['port'] super().__init__(*args, **kwargs)
def __init__(self, host=None, port=None, dbname=None, public_key=None, private_key=None, keyring=[], consensus_plugin=None): """Initialize the Bigchain instance A Bigchain instance has several configuration parameters (e.g. host). If a parameter value is passed as an argument to the Bigchain __init__ method, then that is the value it will have. Otherwise, the parameter value will be the value from the local configuration file. If it's not set in that file, then the value will come from an environment variable. If that environment variable isn't set, then the parameter will have its default value (defined in bigchaindb.__init__). Args: host (str): hostname where RethinkDB is running. port (int): port in which RethinkDB is running (usually 28015). dbname (str): the name of the database to connect to (usually bigchain). public_key (str): the base58 encoded public key for the ED25519 curve. private_key (str): the base58 encoded private key for the ED25519 curve. keyring (list[str]): list of base58 encoded public keys of the federation nodes. """ config_utils.autoconfigure() self.host = host or bigchaindb.config['database']['host'] self.port = port or bigchaindb.config['database']['port'] self.dbname = dbname or bigchaindb.config['database']['name'] self.me = public_key or bigchaindb.config['keypair']['public'] self.me_private = private_key or bigchaindb.config['keypair']['private'] self.federation_nodes = keyring or bigchaindb.config['keyring'] self.consensus = config_utils.load_consensus_plugin(consensus_plugin) if not self.me or not self.me_private: raise exceptions.KeypairNotFoundException() self._conn = None
def test_autoconfigure_read_both_from_file_and_env(monkeypatch): file_config = {'database': {'host': 'test-host'}} monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) monkeypatch.setattr( 'os.environ', { 'BIGCHAINDB_DATABASE_NAME': 'test-dbname', 'BIGCHAINDB_DATABASE_PORT': '4242', 'BIGCHAINDB_KEYRING': 'pubkey_0:pubkey_1:pubkey_2' }) import bigchaindb from bigchaindb import config_utils config_utils.autoconfigure() assert bigchaindb.config == { 'CONFIGURED': True, 'server': { 'bind': '0.0.0.0:9984', 'workers': None, 'threads': None, }, 'database': { 'host': 'test-host', 'port': 4242, 'name': 'test-dbname', }, 'keypair': { 'public': None, 'private': None, }, 'keyring': ['pubkey_0', 'pubkey_1', 'pubkey_2'], 'statsd': { 'host': 'localhost', 'port': 8125, 'rate': 0.01, }, 'api_endpoint': 'http://localhost:9984/api/v1', 'consensus_plugin': 'default', }
def test_autoconfigure_read_both_from_file_and_env(monkeypatch): file_config = { 'database': {'host': 'test-host'} } monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) monkeypatch.setattr('os.environ', {'BIGCHAINDB_DATABASE_NAME': 'test-dbname', 'BIGCHAINDB_DATABASE_PORT': '4242', 'BIGCHAINDB_KEYRING': 'pubkey_0:pubkey_1:pubkey_2'}) import bigchaindb from bigchaindb import config_utils config_utils.autoconfigure() assert bigchaindb.config == { 'CONFIGURED': True, 'server': { 'bind': 'localhost:9984', 'workers': None, 'threads': None, }, 'database': { 'host': 'test-host', 'port': 4242, 'name': 'test-dbname', }, 'keypair': { 'public': None, 'private': None, }, 'keyring': ['pubkey_0', 'pubkey_1', 'pubkey_2'], 'statsd': { 'host': 'localhost', 'port': 8125, 'rate': 0.01, }, 'api_endpoint': 'http://localhost:9984/api/v1', 'consensus_plugin': 'default', }
def __init__(self, host=None, port=None, dbname=None, public_key=None, private_key=None, keyring=[], consensus_plugin=None): """Initialize the Bigchain instance A Bigchain instance has several configuration parameters (e.g. host). If a parameter value is passed as an argument to the Bigchain __init__ method, then that is the value it will have. Otherwise, the parameter value will come from an environment variable. If that environment variable isn't set, then the value will come from the local configuration file. And if that variable isn't in the local configuration file, then the parameter will have its default value (defined in bigchaindb.__init__). Args: host (str): hostname where RethinkDB is running. port (int): port in which RethinkDB is running (usually 28015). dbname (str): the name of the database to connect to (usually bigchain). public_key (str): the base58 encoded public key for the ED25519 curve. private_key (str): the base58 encoded private key for the ED25519 curve. keyring (list[str]): list of base58 encoded public keys of the federation nodes. """ config_utils.autoconfigure() self.host = host or bigchaindb.config['database']['host'] self.port = port or bigchaindb.config['database']['port'] self.dbname = dbname or bigchaindb.config['database']['name'] self.me = public_key or bigchaindb.config['keypair']['public'] self.me_private = private_key or bigchaindb.config['keypair']['private'] self.nodes_except_me = keyring or bigchaindb.config['keyring'] self.consensus = config_utils.load_consensus_plugin(consensus_plugin) if not self.me or not self.me_private: raise exceptions.KeypairNotFoundException() self._conn = None
def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request): # constants DATABASE_HOST = 'test-host' DATABASE_NAME = 'test-dbname' DATABASE_PORT = 4242 DATABASE_BACKEND = request.config.getoption('--database-backend') SERVER_BIND = '1.2.3.4:56' WSSERVER_SCHEME = 'ws' WSSERVER_HOST = '1.2.3.4' WSSERVER_PORT = 57 WSSERVER_ADVERTISED_SCHEME = 'wss' WSSERVER_ADVERTISED_HOST = 'a.b.c.d' WSSERVER_ADVERTISED_PORT = 89 LOG_FILE = '/somewhere/something.log' file_config = { 'database': { 'host': DATABASE_HOST }, 'log': { 'level_console': 'debug', }, } monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) monkeypatch.setattr('os.environ', { 'BIGCHAINDB_DATABASE_NAME': DATABASE_NAME, 'BIGCHAINDB_DATABASE_PORT': str(DATABASE_PORT), 'BIGCHAINDB_DATABASE_BACKEND': DATABASE_BACKEND, 'BIGCHAINDB_SERVER_BIND': SERVER_BIND, 'BIGCHAINDB_WSSERVER_SCHEME': WSSERVER_SCHEME, 'BIGCHAINDB_WSSERVER_HOST': WSSERVER_HOST, 'BIGCHAINDB_WSSERVER_PORT': WSSERVER_PORT, 'BIGCHAINDB_WSSERVER_ADVERTISED_SCHEME': WSSERVER_ADVERTISED_SCHEME, 'BIGCHAINDB_WSSERVER_ADVERTISED_HOST': WSSERVER_ADVERTISED_HOST, 'BIGCHAINDB_WSSERVER_ADVERTISED_PORT': WSSERVER_ADVERTISED_PORT, 'BIGCHAINDB_LOG_FILE': LOG_FILE, 'BIGCHAINDB_LOG_FILE': LOG_FILE, 'BIGCHAINDB_DATABASE_CA_CERT': 'ca_cert', 'BIGCHAINDB_DATABASE_CRLFILE': 'crlfile', 'BIGCHAINDB_DATABASE_CERTFILE': 'certfile', 'BIGCHAINDB_DATABASE_KEYFILE': 'keyfile', 'BIGCHAINDB_DATABASE_KEYFILE_PASSPHRASE': 'passphrase', }) import bigchaindb from bigchaindb import config_utils from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config config_utils.autoconfigure() database_mongodb = { 'backend': 'localmongodb', 'host': DATABASE_HOST, 'port': DATABASE_PORT, 'name': DATABASE_NAME, 'connection_timeout': 5000, 'max_tries': 3, 'replicaset': None, 'ssl': False, 'login': None, 'password': None, 'ca_cert': 'ca_cert', 'certfile': 'certfile', 'keyfile': 'keyfile', 'keyfile_passphrase': 'passphrase', 'crlfile': 'crlfile', } assert bigchaindb.config == { 'CONFIGURED': True, 'server': { 'bind': SERVER_BIND, 'loglevel': 'info', 'workers': None, }, 'wsserver': { 'scheme': WSSERVER_SCHEME, 'host': WSSERVER_HOST, 'port': WSSERVER_PORT, 'advertised_scheme': WSSERVER_ADVERTISED_SCHEME, 'advertised_host': WSSERVER_ADVERTISED_HOST, 'advertised_port': WSSERVER_ADVERTISED_PORT, }, 'database': database_mongodb, 'tendermint': { 'host': 'localhost', 'port': 26657, }, 'log': { 'file': LOG_FILE, 'level_console': 'debug', 'error_file': log_config['handlers']['errors']['filename'], 'level_console': 'debug', 'level_logfile': 'info', 'datefmt_console': log_config['formatters']['console']['datefmt'], 'datefmt_logfile': log_config['formatters']['file']['datefmt'], 'fmt_console': log_config['formatters']['console']['format'], 'fmt_logfile': log_config['formatters']['file']['format'], 'granular_levels': {}, }, }
def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request): # constants DATABASE_HOST = 'test-host' DATABASE_NAME = 'test-dbname' DATABASE_PORT = 4242 DATABASE_BACKEND = request.config.getoption('--database-backend') SERVER_BIND = '1.2.3.4:56' WSSERVER_SCHEME = 'ws' WSSERVER_HOST = '1.2.3.4' WSSERVER_PORT = 57 WSSERVER_ADVERTISED_SCHEME = 'wss' WSSERVER_ADVERTISED_HOST = 'a.b.c.d' WSSERVER_ADVERTISED_PORT = 89 LOG_FILE = '/somewhere/something.log' file_config = { 'database': { 'host': DATABASE_HOST }, 'log': { 'level_console': 'debug', }, } monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) monkeypatch.setattr( 'os.environ', { 'BIGCHAINDB_DATABASE_NAME': DATABASE_NAME, 'BIGCHAINDB_DATABASE_PORT': str(DATABASE_PORT), 'BIGCHAINDB_DATABASE_BACKEND': DATABASE_BACKEND, 'BIGCHAINDB_SERVER_BIND': SERVER_BIND, 'BIGCHAINDB_WSSERVER_SCHEME': WSSERVER_SCHEME, 'BIGCHAINDB_WSSERVER_HOST': WSSERVER_HOST, 'BIGCHAINDB_WSSERVER_PORT': WSSERVER_PORT, 'BIGCHAINDB_WSSERVER_ADVERTISED_SCHEME': WSSERVER_ADVERTISED_SCHEME, 'BIGCHAINDB_WSSERVER_ADVERTISED_HOST': WSSERVER_ADVERTISED_HOST, 'BIGCHAINDB_WSSERVER_ADVERTISED_PORT': WSSERVER_ADVERTISED_PORT, 'BIGCHAINDB_LOG_FILE': LOG_FILE, 'BIGCHAINDB_LOG_FILE': LOG_FILE, 'BIGCHAINDB_DATABASE_CA_CERT': 'ca_cert', 'BIGCHAINDB_DATABASE_CRLFILE': 'crlfile', 'BIGCHAINDB_DATABASE_CERTFILE': 'certfile', 'BIGCHAINDB_DATABASE_KEYFILE': 'keyfile', 'BIGCHAINDB_DATABASE_KEYFILE_PASSPHRASE': 'passphrase', }) import bigchaindb from bigchaindb import config_utils from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config config_utils.autoconfigure() database_mongodb = { 'backend': 'localmongodb', 'host': DATABASE_HOST, 'port': DATABASE_PORT, 'name': DATABASE_NAME, 'connection_timeout': 5000, 'max_tries': 3, 'replicaset': None, 'ssl': False, 'login': None, 'password': None, 'ca_cert': 'ca_cert', 'certfile': 'certfile', 'keyfile': 'keyfile', 'keyfile_passphrase': 'passphrase', 'crlfile': 'crlfile', } assert bigchaindb.config == { 'CONFIGURED': True, 'server': { 'bind': SERVER_BIND, 'loglevel': 'info', 'workers': None, }, 'wsserver': { 'scheme': WSSERVER_SCHEME, 'host': WSSERVER_HOST, 'port': WSSERVER_PORT, 'advertised_scheme': WSSERVER_ADVERTISED_SCHEME, 'advertised_host': WSSERVER_ADVERTISED_HOST, 'advertised_port': WSSERVER_ADVERTISED_PORT, }, 'database': database_mongodb, 'tendermint': { 'host': 'localhost', 'port': 26657, }, 'log': { 'file': LOG_FILE, 'level_console': 'debug', 'error_file': log_config['handlers']['errors']['filename'], 'level_console': 'debug', 'level_logfile': 'info', 'datefmt_console': log_config['formatters']['console']['datefmt'], 'datefmt_logfile': log_config['formatters']['file']['datefmt'], 'fmt_console': log_config['formatters']['console']['format'], 'fmt_logfile': log_config['formatters']['file']['format'], 'granular_levels': {}, }, }
def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request, ssl_context): # constants DATABASE_HOST = 'test-host' DATABASE_NAME = 'test-dbname' DATABASE_PORT = 4242 DATABASE_BACKEND = request.config.getoption('--database-backend') SERVER_BIND = '1.2.3.4:56' WSSERVER_SCHEME = 'ws' WSSERVER_HOST = '1.2.3.4' WSSERVER_PORT = 57 WSSERVER_ADVERTISED_SCHEME = 'wss' WSSERVER_ADVERTISED_HOST = 'a.b.c.d' WSSERVER_ADVERTISED_PORT = 89 KEYRING = 'pubkey_0:pubkey_1:pubkey_2' LOG_FILE = '/somewhere/something.log' file_config = { 'database': { 'host': DATABASE_HOST }, 'log': { 'level_console': 'debug', }, } monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) if DATABASE_BACKEND == 'mongodb-ssl': monkeypatch.setattr( 'os.environ', { 'BIGCHAINDB_DATABASE_NAME': DATABASE_NAME, 'BIGCHAINDB_DATABASE_PORT': str(DATABASE_PORT), 'BIGCHAINDB_DATABASE_BACKEND': 'mongodb', 'BIGCHAINDB_SERVER_BIND': SERVER_BIND, 'BIGCHAINDB_WSSERVER_SCHEME': WSSERVER_SCHEME, 'BIGCHAINDB_WSSERVER_HOST': WSSERVER_HOST, 'BIGCHAINDB_WSSERVER_PORT': WSSERVER_PORT, 'BIGCHAINDB_WSSERVER_ADVERTISED_SCHEME': WSSERVER_ADVERTISED_SCHEME, 'BIGCHAINDB_WSSERVER_ADVERTISED_HOST': WSSERVER_ADVERTISED_HOST, 'BIGCHAINDB_WSSERVER_ADVERTISED_PORT': WSSERVER_ADVERTISED_PORT, 'BIGCHAINDB_KEYRING': KEYRING, 'BIGCHAINDB_LOG_FILE': LOG_FILE, 'BIGCHAINDB_DATABASE_CA_CERT': ssl_context.ca, 'BIGCHAINDB_DATABASE_CRLFILE': ssl_context.crl, 'BIGCHAINDB_DATABASE_CERTFILE': ssl_context.cert, 'BIGCHAINDB_DATABASE_KEYFILE': ssl_context.key, 'BIGCHAINDB_DATABASE_KEYFILE_PASSPHRASE': None }) else: monkeypatch.setattr( 'os.environ', { 'BIGCHAINDB_DATABASE_NAME': DATABASE_NAME, 'BIGCHAINDB_DATABASE_PORT': str(DATABASE_PORT), 'BIGCHAINDB_DATABASE_BACKEND': DATABASE_BACKEND, 'BIGCHAINDB_SERVER_BIND': SERVER_BIND, 'BIGCHAINDB_WSSERVER_SCHEME': WSSERVER_SCHEME, 'BIGCHAINDB_WSSERVER_HOST': WSSERVER_HOST, 'BIGCHAINDB_WSSERVER_PORT': WSSERVER_PORT, 'BIGCHAINDB_WSSERVER_ADVERTISED_SCHEME': WSSERVER_ADVERTISED_SCHEME, 'BIGCHAINDB_WSSERVER_ADVERTISED_HOST': WSSERVER_ADVERTISED_HOST, 'BIGCHAINDB_WSSERVER_ADVERTISED_PORT': WSSERVER_ADVERTISED_PORT, 'BIGCHAINDB_KEYRING': KEYRING, 'BIGCHAINDB_LOG_FILE': LOG_FILE }) import bigchaindb from bigchaindb import config_utils from bigchaindb.log.configs import SUBSCRIBER_LOGGING_CONFIG as log_config config_utils.autoconfigure() database_mongodb = { 'backend': 'mongodb', 'host': DATABASE_HOST, 'port': DATABASE_PORT, 'name': DATABASE_NAME, 'connection_timeout': 5000, 'max_tries': 3, 'replicaset': 'bigchain-rs', 'ssl': False, 'login': None, 'password': None, 'ca_cert': None, 'certfile': None, 'keyfile': None, 'keyfile_passphrase': None, 'crlfile': None } database_mongodb_ssl = { 'backend': 'mongodb', 'host': DATABASE_HOST, 'port': DATABASE_PORT, 'name': DATABASE_NAME, 'connection_timeout': 5000, 'max_tries': 3, 'replicaset': 'bigchain-rs', 'ssl': True, 'login': None, 'password': None, 'ca_cert': ssl_context.ca, 'crlfile': ssl_context.crl, 'certfile': ssl_context.cert, 'keyfile': ssl_context.key, 'keyfile_passphrase': None } database = {} if DATABASE_BACKEND == 'mongodb': database = database_mongodb elif DATABASE_BACKEND == 'mongodb-ssl': database = database_mongodb_ssl assert bigchaindb.config == { 'CONFIGURED': True, 'server': { 'bind': SERVER_BIND, 'loglevel': logging.getLevelName( log_config['handlers']['console']['level']).lower(), 'workers': None, }, 'wsserver': { 'scheme': WSSERVER_SCHEME, 'host': WSSERVER_HOST, 'port': WSSERVER_PORT, 'advertised_scheme': WSSERVER_ADVERTISED_SCHEME, 'advertised_host': WSSERVER_ADVERTISED_HOST, 'advertised_port': WSSERVER_ADVERTISED_PORT, }, 'database': database, 'tendermint': { 'host': None, 'port': None, }, 'log': { 'file': LOG_FILE, 'error_file': log_config['handlers']['errors']['filename'], 'level_console': 'debug', 'level_logfile': logging.getLevelName( log_config['handlers']['file']['level']).lower(), 'datefmt_console': log_config['formatters']['console']['datefmt'], 'datefmt_logfile': log_config['formatters']['file']['datefmt'], 'fmt_console': log_config['formatters']['console']['format'], 'fmt_logfile': log_config['formatters']['file']['format'], 'granular_levels': {}, 'port': 9020 }, }