Пример #1
0
class Config(object):
    """Base configuration."""
    DEBUG = env_bool('IGL_DEBUG', default=True)
    TESTING = env_bool('IGL_TESTING', default=True)

    MESSAGE_LAKE_CONN = env_s3_config('MSGAPI_MESSAGE_LAKE')

    BC_INBOX_CONF = env_queue_config('MSG_RX_API_BC_INBOX')

    PUBLISH_NOTIFICATIONS_REPO_CONN = env_queue_config(
        'MSG_RX_API_OUTBOX_REPO')
Пример #2
0
class Config(object):
    """Base configuration."""
    DEBUG = env_bool('IGL_DEBUG', default=True)
    TESTING = env_bool('IGL_TESTING', default=True)

    BC_INBOX_CONF = env_queue_config('MSG_RX_API_BC_INBOX')
Пример #3
0
    },
    'root': {
        'handlers': ['console'],
        'level': 'DEBUG',
    },
    'loggers': {
        'botocore': {
            'level': 'INFO'
        },
        'urllib3': {
            'level': 'INFO'
        },
        '': {
            'handlers': ['console'],
            'level': 'DEBUG',
        },
    }
}

# JSON formatter for sending logs to ES
LOG_FORMATTER_JSON = env_bool('ICL_LOG_FORMATTER_JSON', default=False)
if LOG_FORMATTER_JSON:  # pragma: no cover
    LOGGING['formatters']['json'] = {
        '()': 'intergov.json_log_formatter.JsonFormatter',
    }
    LOGGING['handlers']['console']['formatter'] = 'json'

# Apply the config
dictConfig(LOGGING)
logger = logging.getLogger('intergov')
Пример #4
0
from sqlalchemy import create_engine, or_
from sqlalchemy.orm import sessionmaker

from intergov.conf import env_bool
from intergov.domain.wire_protocols import generic_discrete as message
from intergov.repos.api_outbox.postgres_objects import Base, Message
from intergov.loggers import logging

logger = logging.getLogger(__name__)

IGL_ALLOW_UNSAFE_REPO_CLEAR = env_bool('IGL_ALLOW_UNSAFE_REPO_CLEAR',
                                       default=False)
IGL_ALLOW_UNSAFE_REPO_IS_EMPTY = env_bool('IGL_ALLOW_UNSAFE_REPO_IS_EMPTY',
                                          default=False)


class PostgresRepo:
    """
    https://docs.sqlalchemy.org/en/13/orm/query.html
    http://www.leeladharan.com/sqlalchemy-query-with-or-and-like-common-filters
    """

    DEFAULT_DB = 'postgres'

    def __init__(self, connection_data):
        connection_string = "postgresql+psycopg2://{}:{}@{}/{}".format(
            connection_data['user'], connection_data['password'],
            connection_data['host'], connection_data['dbname']
            or self.DEFAULT_DB)
        self.engine = create_engine(connection_string, )
        # echo=True  # use this for debugging
Пример #5
0
def test_simple():
    # test env_none
    assert not os.environ.get(TEST_ENV_NONE_KEY)
    assert not conf.env_none(TEST_ENV_NONE_KEY)
    assert TEST_DEFAULT == conf.env_none(TEST_ENV_NONE_KEY,
                                         default=TEST_DEFAULT)
    os.environ[TEST_ENV_NONE_KEY] = TEST_NON_DEFAULT_VALUE
    assert TEST_NON_DEFAULT_VALUE == conf.env_none(TEST_ENV_NONE_KEY,
                                                   default=TEST_DEFAULT)
    os.environ[TEST_ENV_NONE_KEY] = ""
    assert conf.env_none(TEST_ENV_NONE_KEY) is None

    # test env_bool
    assert not os.environ.get(TEST_ENV_BOOL_VALUE_KEY)
    for env_value, value in TEST_ENV_BOOL_VALUES:
        os.environ[TEST_ENV_BOOL_VALUE_KEY] = env_value
        assert conf.env_bool(TEST_ENV_BOOL_VALUE_KEY) == value

    del os.environ[TEST_ENV_BOOL_VALUE_KEY]
    assert conf.env_bool(TEST_ENV_BOOL_VALUE_KEY, default=True)
    assert conf.env_bool(TEST_ENV_BOOL_VALUE_KEY, default=None,
                         nullable=True) is None

    os.environ[TEST_ENV_BOOL_VALUE_KEY] = 'False'
    assert conf.env_bool(TEST_ENV_BOOL_VALUE_KEY, default=True) is False

    # not none exception
    del os.environ[TEST_ENV_BOOL_VALUE_KEY]
    with pytest.raises(Exception) as e:
        conf.env_bool(TEST_ENV_BOOL_VALUE_KEY, nullable=False, default=None)

    assert str(
        e.value) == "Variable {} can't be None".format(TEST_ENV_BOOL_VALUE_KEY)
    # unknown string value
    os.environ[TEST_ENV_BOOL_VALUE_KEY] = "FalseFalseTrue"
    with pytest.raises(Exception) as e:
        conf.env_bool(TEST_ENV_BOOL_VALUE_KEY)

    assert str(e.value) == "Unknown value for variable {}: '{}'".format(
        TEST_ENV_BOOL_VALUE_KEY, os.environ[TEST_ENV_BOOL_VALUE_KEY])

    # invalid default value
    del os.environ[TEST_ENV_BOOL_VALUE_KEY]
    with pytest.raises(Exception) as e:
        conf.env_bool(TEST_ENV_BOOL_VALUE_KEY, default=dict(msg="Hello"))

    assert str(e.value) == "Unknown value type for variable {}: '{}'".format(
        TEST_ENV_BOOL_VALUE_KEY, dict)

    # test env_json
    assert not os.environ.get(TEST_ENV_JSON_KEY)
    os.environ[TEST_ENV_JSON_KEY] = json.dumps(TEST_ENV_JSON_DICT)
    assert conf.env_json(TEST_ENV_JSON_KEY) == TEST_ENV_JSON_DICT
    del os.environ[TEST_ENV_JSON_KEY]
    assert conf.env_json(
        TEST_ENV_JSON_KEY,
        default=TEST_ENV_JSON_DEFAULT) == TEST_ENV_JSON_DEFAULT

    os.environ[TEST_ENV_JSON_KEY] = TEST_ENV_INVALID_JSON_STR
    with pytest.raises(ValueError):
        conf.env_json(TEST_ENV_JSON_KEY)
Пример #6
0
class Config(object):
    """Base configuration."""
    DEBUG = env_bool('IGL_DEBUG', default=True)
    TESTING = env_bool('IGL_TESTING', default=True)
    OBJECT_LAKE_CONN = env_s3_config('DOCAPI_OBJ_LAKE')
    OBJECT_ACL_CONN = env_s3_config('DOCAPI_OBJ_ACL')
Пример #7
0
class Config(object):
    """Base configuration."""
    DEBUG = env_bool('IGL_DEBUG', default=True)
    TESTING = env_bool('IGL_TESTING', default=True)
    SUBSCR_REPO_CONF = env_s3_config('SUBSCR_API_REPO')