Example #1
0
def load_config():
    """
    Loads the config files merging the defaults
    with the file defined in environ.LINTREVIEW_SETTINGS if it exists.
    """
    config = Config(os.getcwd())

    if 'LINTREVIEW_SETTINGS' in os.environ:
        config.from_envvar('LINTREVIEW_SETTINGS')
    elif os.path.exists(os.path.join(os.getcwd(), 'settings.py')):
        config.from_pyfile('settings.py')
    else:
        msg = ("Unable to load configuration file. Please "
               "either create ./settings.py or set LINTREVIEW_SETTINGS "
               "in your environment before running.")
        raise ImportError(msg)
    if config.get('LOGGING_CONFIG'):
        logging.config.fileConfig(
            config.get('LOGGING_CONFIG'),
            disable_existing_loggers=False)

    if config.get('SSL_CA_BUNDLE'):
        os.environ['REQUESTS_CA_BUNDLE'] = config.get('SSL_CA_BUNDLE')

    return config
Example #2
0
    def make_config(self, instance_relative=False):
        config = Flask.make_config(self, instance_relative)
        if not config.get('SESSION_COOKIE_NAME'):
            config['SESSION_COOKIE_NAME'] = self.name + '-session'

        # during testing DATA_DIR is not created by instance app, but we still need
        # this attribute to be set
        self.DATA_DIR = Path(self.instance_path, 'data')

        if self._ABILIAN_INIT_TESTING_FLAG:
            # testing: don't load any config file!
            return config

        if instance_relative:
            self.check_instance_folder(create=True)

        cfg_path = os.path.join(config.root_path, 'config.py')
        logger.info('Try to load config: "%s"', cfg_path)
        try:
            config.from_pyfile(cfg_path, silent=False)
        except IOError:
            return config

        config.from_envvar(self.CONFIG_ENVVAR, silent=True)

        if 'WTF_CSRF_ENABLED' not in config:
            config['WTF_CSRF_ENABLED'] = config.get('CSRF_ENABLED', True)

        return config
Example #3
0
def load_config(settings_file='./test_settings.py'):
    """
    Loads the config files merging the defaults
    with the file defined in environ.PULLSBURY_SETTINGS if it exists.
    """
    config = Config(os.getcwd())

    if 'PULLSBURY_SETTINGS' in os.environ:
        config.from_envvar('PULLSBURY_SETTINGS')
    else:
        config.from_pyfile(settings_file)

    if config.get('LOGGING_CONFIG'):
        logging.config.fileConfig(
            config.get('LOGGING_CONFIG'),
            disable_existing_loggers=False)

    json_values = [
        'TEAMS',
        'HAPPY_SLACK_EMOJIS',
        'REPO_BLACKLIST',
        'SLACK_CUSTOM_EMOJI_MAPPING'
    ]

    for value in json_values:
        config.update({
            value: json.loads(config.get(value, '{}'))
        })

    return config
Example #4
0
    def make_config(self, instance_relative=False):
        config = Flask.make_config(self, instance_relative)
        if not config.get('SESSION_COOKIE_NAME'):
            config['SESSION_COOKIE_NAME'] = self.name + '-session'

        # during testing DATA_DIR is not created by instance app, but we still need
        # this attribute to be set
        self.DATA_DIR = Path(self.instance_path, 'data')

        if self._ABILIAN_INIT_TESTING_FLAG:
            # testing: don't load any config file!
            return config

        if instance_relative:
            self.check_instance_folder(create=True)

        cfg_path = os.path.join(config.root_path, 'config.py')
        logger.info('Try to load config: "%s"', cfg_path)
        try:
            config.from_pyfile(cfg_path, silent=False)
        except IOError:
            return config

        # If the env var specifies a configuration file, it must exist
        # (and execute with no exceptions) - we don't want the application
        # to run with an unprecised or insecure configuration.
        if self.CONFIG_ENVVAR in os.environ:
            config.from_envvar(self.CONFIG_ENVVAR, silent=False)

        if 'WTF_CSRF_ENABLED' not in config:
            config['WTF_CSRF_ENABLED'] = config.get('CSRF_ENABLED', True)

        return config
Example #5
0
  def make_config(self, instance_relative=False):
    config = Flask.make_config(self, instance_relative)
    if not config.get('SESSION_COOKIE_NAME'):
      config['SESSION_COOKIE_NAME'] = self.name + '-session'

    # during testing DATA_DIR is not created by instance app, but we still need
    # this attribute to be set
    self.DATA_DIR = Path(self.instance_path, 'data')

    if self._ABILIAN_INIT_TESTING_FLAG:
      # testing: don't load any config file!
      return config

    if instance_relative:
      self.check_instance_folder(create=True)

    cfg_path = os.path.join(config.root_path, 'config.py')
    logger.info('Try to load config: "%s"', cfg_path)
    try:
      config.from_pyfile(cfg_path, silent=False)
    except IOError:
      return config

    config.from_envvar(self.CONFIG_ENVVAR, silent=True)

    if 'WTF_CSRF_ENABLED' not in config:
      config['WTF_CSRF_ENABLED'] = config.get('CSRF_ENABLED', True)

    return config
Example #6
0
def load_config():
    """
    Loads the config files merging the defaults
    with the file defined in environ.LINTREVIEW_SETTINGS if it exists.
    """
    config = Config(os.getcwd())

    if 'LINTREVIEW_SETTINGS' in os.environ:
        config.from_envvar('LINTREVIEW_SETTINGS')
    elif os.path.exists(os.path.join(os.getcwd(), 'settings.py')):
        config.from_pyfile('settings.py')
    else:
        msg = ("Unable to load configuration file. Please "
               "either create ./settings.py or set LINTREVIEW_SETTINGS "
               "in your environment before running.")
        raise ImportError(msg)
    if config.get('LOGGING_CONFIG'):
        logging.config.fileConfig(
            config.get('LOGGING_CONFIG'),
            disable_existing_loggers=False)

    if config.get('SSL_CA_BUNDLE'):
        os.environ['REQUESTS_CA_BUNDLE'] = config.get('SSL_CA_BUNDLE')

    return config
Example #7
0
def main():
    # Load the config
    config = Config(os.path.dirname(os.path.realpath(__file__)))
    config.from_object('cacahuate.settings')
    config.from_envvar('CACAHUATE_SETTINGS', silent=True)

    # Set the timezone
    os.environ['TZ'] = config['TIMEZONE']
    time.tzset()

    # Setup logging
    logging.config.dictConfig(config['LOGGING'])

    # Load the models
    eng = Engine(
        host=config['REDIS_HOST'],
        port=config['REDIS_PORT'],
        db=config['REDIS_DB'],
        id_function=yuid,
    )
    bind_models(eng)

    # Create mongo indexes
    create_indexes(config)

    # start the loop
    loop = Loop(config)
    loop.start()
Example #8
0
def main():
    # Load the config
    config = Config(os.path.dirname(os.path.realpath(__file__)))
    config.from_object('cacahuate.settings')

    if os.getenv('CACAHUATE_SETTINGS'):
        config.from_envvar('CACAHUATE_SETTINGS', silent=False)

    # Set the timezone
    os.environ['TZ'] = config['TIMEZONE']
    time.tzset()

    # Setup logging
    logging.config.dictConfig(config['LOGGING'])

    # Load the models
    eng = Engine(
        host=config['REDIS_HOST'],
        port=config['REDIS_PORT'],
        db=config['REDIS_DB'],
        id_function=getattr(
            import_module(config['DB_ID_FUNCTION'].rsplit('.', 1)[0]),
            config['DB_ID_FUNCTION'].rsplit('.', 1)[1],
        ),
    )
    bind_models(eng)

    # Create mongo indexes
    create_indexes(config)

    # Update celery config
    celery.conf.update(
        broker='amqp://{user}@{host}//'.format(
            user=config['RABBIT_USER'],
            host=config['RABBIT_HOST'],
        ),
        worker_concurrency=1,
        worker_hijack_root_logger=False,
        task_default_queue=config['RABBIT_QUEUE'],
    )
    worker = celery.Worker()
    worker.start()
Example #9
0
def init_config(config: Config) -> None:
    """Load config"""
    env_flask_config_name = os.getenv('FLASK_CONFIG') or 'development'
    flask_config_name = f'config.{env_flask_config_name}.json'
    config.from_object(DefaultConfig())
    config.from_json(
        os.path.normpath(
            os.path.join(os.path.dirname(__file__), flask_config_name)))
    config.from_envvar('SQLALCHEMY_DATABASE_URI', True)
    config.from_envvar('APP_VERSION', True)
    config.from_envvar('SERVER_NAME', True)
Example #10
0
from flask.config import Config
from requests.exceptions import ConnectionError
from zeep.exceptions import Fault as ZeepFault
import lxml

from ...service.app import SE_LEG_PROVIDER_SETTINGS_ENVVAR
from ...storage import OpStorageWrapper
from .license_service import LicenseService
from .config import NSTIC_VETTING_PROCESS_AUDIT_LOG_FILE, NSTIC_VETTING_PROCESS_AUDIT_LOGGING

__author__ = 'lundberg'


# Read conf
config = Config('')
config.from_envvar(SE_LEG_PROVIDER_SETTINGS_ENVVAR)
wsdl = config['MOBILE_VERIFY_WSDL']
username = config['MOBILE_VERIFY_USERNAME']
password = config['MOBILE_VERIFY_PASSWORD']
tenant_reference_number = config['MOBILE_VERIFY_TENANT_REF']

# Set up logging
logger = logging.getLogger(__name__)
out_handler = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
out_handler.setFormatter(formatter)
out_handler.setLevel(logging.DEBUG)
logger.addHandler(out_handler)

# Set up audit logging
audit_log_file = config.get('NSTIC_VETTING_PROCESS_AUDIT_LOG_FILE', NSTIC_VETTING_PROCESS_AUDIT_LOG_FILE)
Example #11
0
from flask import config as flask_conf
import os
import logging.config
import sys

# by laziness we use flask config manager since it is the best we know
config = flask_conf.Config(os.path.dirname(os.path.realpath(__file__)))

config.from_object('artemis.default_settings')
if 'CONFIG_FILE' in os.environ:
    config.from_envvar('CONFIG_FILE')

if 'LOGGER' in config:
    logging.config.dictConfig(config['LOGGER'])
else:  # Default is std out
    handler = logging.StreamHandler(stream=sys.stdout)
    log = logging.getLogger(__name__)
    log.setLevel('INFO')
    log.addHandler(handler)
Example #12
0
from flask import config as flask_conf
import os
import logging.config
import sys

# by laziness we use flask config manager since it is the best we know
config = flask_conf.Config(os.path.dirname(os.path.realpath(__file__)))

config.from_object("artemis.default_settings")
if "CONFIG_FILE" in os.environ:
    config.from_envvar("CONFIG_FILE")

if "LOGGER" in config:
    logging.config.dictConfig(config["LOGGER"])
else:  # Default is std out
    handler = logging.StreamHandler(stream=sys.stdout)
    log = logging.getLogger(__name__)
    log.setLevel("INFO")
    log.addHandler(handler)