def main():
    from inbox.config import config, secrets_path

    maybe_enable_rollbar()

    # If the config contains encryption keys, don't override.
    if config.get("SECRET_ENCRYPTION_KEY"):
        raise Exception("Encryption keys already present in secrets config "
                        "file {0}".format(secrets_path))

    # Generate keys
    data = {
        "SECRET_ENCRYPTION_KEY":
        binascii.hexlify(nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE)),
        "BLOCK_ENCRYPTION_KEY":
        binascii.hexlify(nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE)),
    }

    # Our secrets config file contains our database credentials etc.,
    # so it better exist.
    # Update it
    try:
        with open(secrets_path, "a") as f:
            print(
                "Writing keys to secrets config file {0}".format(secrets_path))
            yaml.dump(data, f, default_flow_style=False)
    except IOError:
        raise Exception(
            "Check file write permissions on config file {0}".format(
                secrets_path))

    # Update the config dict
    config.update(data)
Beispiel #2
0
def config():
    from inbox.config import config

    filename = absolute_path('config-test.json')
    try:
        f = open(filename)
    except IOError:
        sys.exit('Missing test config at {0}'.format(filename))
    else:
        with f:
            test_config = json.load(f)
            config.update(test_config)
            if not config.get('MYSQL_HOSTNAME') == 'localhost':
                sys.exit('Tests should only be run on localhost DB!')

    return config
Beispiel #3
0
def config():
    from inbox.config import config

    filename = absolute_path('config-test.json')
    try:
        f = open(filename)
    except IOError:
        sys.exit('Missing test config at {0}'.format(filename))
    else:
        with f:
            test_config = json.load(f)
            config.update(test_config)
            if not config.get('MYSQL_HOSTNAME') == 'localhost':
                sys.exit('Tests should only be run on localhost DB!')

    return config
Beispiel #4
0
def load_overrides(file_path):
    """
    Convenience function for overriding default configuration.

    file_path : <string> the full path to a file containing valid
                JSON for configuration overrides
    """
    with open(file_path) as data_file:
        try:
            overrides = json.load(data_file)
        except ValueError:
            sys.exit(
                'Failed parsing configuration file at {}'.format(file_path))
        if not overrides:
            log.debug('No config overrides found.')
            return
        assert isinstance(overrides, dict), \
            'overrides must be dictionary'
        config.update(overrides)
        log.debug('Imported config overrides {}'.format(overrides.keys()))
Beispiel #5
0
def load_overrides(file_path):
    """
    Convenience function for overriding default configuration.

    file_path : <string> the full path to a file containing valid
                JSON for configuration overrides
    """
    with open(file_path) as data_file:
        try:
            overrides = json.load(data_file)
        except ValueError:
            sys.exit('Failed parsing configuration file at {}'
                     .format(file_path))
        if not overrides:
            log.debug('No config overrides found.')
            return
        assert isinstance(overrides, dict), \
            'overrides must be dictionary'
        config.update(overrides)
        log.debug('Imported config overrides {}'.format(
            overrides.keys()))
Beispiel #6
0
from alembic import context

from logging.config import fileConfig

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
alembic_config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(alembic_config.config_file_name)

# If alembic was invoked with --tag=test, override these main config values
if context.get_tag_argument() == 'test':
    from inbox.config import config
    with open('../etc/config-test.json') as f:
        config.update(json.load(f))
        if not config.get('MYSQL_HOSTNAME') == "localhost":
            sys.exit("Tests should only be run on localhost DB!")


# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
from inbox.models.base import MailSyncBase
target_metadata = MailSyncBase.metadata

from inbox.ignition import main_engine

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
Beispiel #7
0
from alembic import context

from logging.config import fileConfig

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
alembic_config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(alembic_config.config_file_name)

# If alembic was invoked with --tag=test, override these main config values
if context.get_tag_argument() == 'test':
    from inbox.config import config
    with open('./tests/config-test.json') as f:
        config.update(json.load(f))
        if not config.get('MYSQL_HOSTNAME') == "localhost":
            sys.exit("Tests should only be run on localhost DB!")


# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
from inbox.models.base import MailSyncBase
target_metadata = MailSyncBase.metadata

from inbox.ignition import main_engine

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")