config.py 10.13 KiB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Mentat system (https://mentat.cesnet.cz/).
#
# Copyright (C) since 2011 CESNET, z.s.p.o (http://www.ces.net/)
# Use of this source is governed by the MIT license, see LICENSE file.
#-------------------------------------------------------------------------------
"""
This module contains default configurations for Hawat application. One of the
classes defined in this module may be passed as argument to :py:func:`hawat.app.create_app`
factory function to bootstrap Hawat default configurations. These values may be
then optionally overwritten by external configuration file and/or additional
configuration file defined indirrectly via environment variable. Please refer to
the documentation of :py:func:`hawat.app.create_app` factory function for more
details on this process.
There are following predefined configuration classess available:
:py:class:`hawat.config.ProductionConfig`
Default configuration suite for production environments.
:py:class:`hawat.config.DevelopmentConfig`
Default configuration suite for development environments.
:py:class:`hawat.config.TestingConfig`
Default configuration suite for testing environments.
"""
__author__ = "Jan Mach <jan.mach@cesnet.cz>"
__credits__ = "Pavel Kácha <pavel.kacha@cesnet.cz>, Andrea Kropáčová <andrea.kropacova@cesnet.cz>"
import socket
import collections
#
# Flask related modules.
#
from flask_babel import lazy_gettext
#
# Custom modules.
#
import pyzenkit.jsonconf
import hawat.const
class Config: # pylint: disable=locally-disabled,too-few-public-methods
"""
Base class for default Hawat application configurations. You are free to
extend and customize contents of this class to provide better default values
for your particular environment.
The configuration keys must be a valid Flask configuration and so they must
be written in UPPERCASE to be correctly recognized
"""
#---------------------------------------------------------------------------
#
# Flask internal configurations. Please refer to Flask documentation for
# more information about each confiuration key.
#
DEBUG = False
TESTING = False
SECRET_KEY = 'default-secret-key'
#---------------------------------------------------------------------------
#
# Flask extension configurations.
#
# WTForms configurations.
WTF_CSRF_ENABLED = True
# Mail server settings for logging framework.
MAIL_SERVER = 'localhost'
MAIL_PORT = 25
MAIL_USERNAME = None
MAIL_PASSWORD = None
MAIL_DEFAULT_SENDER = 'mentat@{}'.format(socket.getfqdn())
MAIL_SUBJECT_PREFIX = '[MyDojo]'
# Babel configurations for application localization.
BABEL_DEFAULT_LOCALE = hawat.const.HAWAT_DEFAULT_LOCALE
BABEL_DEFAULT_TIMEZONE = hawat.const.HAWAT_DEFAULT_TIMEZONE
# SQLAlchemy configurations.
# Note: do not put 'SQLALCHEMY_DATABASE_URI' and 'SQLALCHEMY_ECHO' here.
# These will be overwritten with the values in Mentat core database configurations.
#
SQLALCHEMY_TRACK_MODIFICATIONS = False
#---------------------------------------------------------------------------
#
# Hawat custom configurations.
#
ROLES = hawat.const.HAWAT_ROLES
"""List of all user roles supported by the Hawat application."""
SUPPORTED_LOCALES = collections.OrderedDict([('en', 'English'), ('cs', 'Česky')])
"""List of all languages (locales) supported by the Hawat application."""
ENABLED_BLUEPRINTS = [
'hawat.blueprints.auth_api',
'hawat.blueprints.auth_env',
'hawat.blueprints.design',
'hawat.blueprints.home',
'hawat.blueprints.reports',
'hawat.blueprints.events',
'hawat.blueprints.timeline',
'hawat.blueprints.geoip',
'hawat.blueprints.whois',
'hawat.blueprints.performance',
'hawat.blueprints.status',
'hawat.blueprints.dbstatus',
'hawat.blueprints.devtools',
'hawat.blueprints.users',
'hawat.blueprints.groups',
'hawat.blueprints.settings_reporting',
'hawat.blueprints.filters',
'hawat.blueprints.networks',
'hawat.blueprints.changelogs',
'hawat.blueprints.help',
]
"""List of requested application blueprints to be loaded during setup."""
HAWAT_LOGIN_VIEW = 'auth_env.login'
"""Default login view."""
HAWAT_LOGIN_MSGCAT = 'info'
"""Default login message category."""
HAWAT_ENDPOINT_HOME = 'home.index'
"""Homepage endpoint."""
HAWAT_LOGIN_REDIRECT = 'home.index'
"""Default redirection endpoint after login."""
HAWAT_LOGOUT_REDIRECT = 'home.index'
"""Default redirection endpoint after logout."""
HAWAT_MENU_SKELETON = [
{
'entry_type': 'submenu',
'ident': 'dashboards',
'position': 100,
'title': lazy_gettext('Dashboards'),
'resptitle': True,
'icon': 'section-dashboards'
},
{
'entry_type': 'submenu',
'ident': 'more',
'position': 200,
'title': lazy_gettext('More'),
'resptitle': True,
'icon': 'section-more',
},
{
'entry_type': 'submenu',
'ident': 'admin',
'position': 300,
'authentication': True,
'authorization': ['power'],
'title': lazy_gettext('Administration'),
'resptitle': True,
'icon': 'section-administration'
},
{
'entry_type': 'submenu',
'ident': 'developer',
'position': 400,
'authentication': True,
'authorization': ['developer'],
'title': lazy_gettext('Development'),
'resptitle': True,
'icon': 'section-development'
}
]
"""Configuration of application menu skeleton."""
MENTAT_CORE = pyzenkit.jsonconf.config_load_dir('/etc/mentat/core')
"""Mentat core system configurations."""
MENTAT_PATHS = {
'path_bin': '/usr/local/bin',
'path_cfg': '/etc/mentat',
'path_log': '/var/mentat/log',
'path_run': '/var/mentat/run',
'path_tmp': '/tmp',
'path_crn': '/etc/cron.d'
}
"""Paths to various directories."""
MENTAT_CACHE_DIR = '/var/mentat/cache'
"""Path to Mentat cache directory."""
MENTAT_CONTROLLER_CFG = '/etc/mentat/mentat-controller.py.conf'
"""path to configuration file of mentat-controller.py module."""
HAWAT_ADMINS = ['root@{}'.format(socket.getfqdn())]
"""List of system administrator emails."""
HAWAT_LOG_DEFAULT_LEVEL = 'info'
"""Default logging level, case insensitive. One of the values ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, ``CRITICAL``."""
HAWAT_LOG_FILE = '/var/mentat/log/mentat-hawat.py.log'
"""Log file settings for logging framework."""
HAWAT_LOG_FILE_LEVEL = 'info'
"""File logging level, case insensitive. One of the values ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, ``CRITICAL``."""
HAWAT_LOG_EMAIL_LEVEL = 'error'
"""File logging level, case insensitive. One of the values ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, ``CRITICAL``."""
HAWAT_LOCAL_DEVELOPER_LOGIN = 'account@local'
"""Developer account for local development login."""
HAWAT_CHART_TIMELINE_MAXSTEPS = 200
"""Maximal number of steps (bars) displayed in timeline chart."""
class ProductionConfig(Config): # pylint: disable=locally-disabled,too-few-public-methods
"""
Class containing *production* Hawat applications` configurations.
"""
class DevelopmentConfig(Config): # pylint: disable=locally-disabled,too-few-public-methods
"""
Class containing *development* Hawat applications` configurations.
"""
#---------------------------------------------------------------------------
#
# Flask internal configurations. Please refer to Flask documentation for
# more information about each confiuration key.
#
DEBUG = True
"""Overwritten default value from :py:const:`hawat.config.Config.DEBUG`"""
#---------------------------------------------------------------------------
#
# Hawat custom configurations.
#
ENABLED_BLUEPRINTS = [
'hawat.blueprints.auth_api',
'hawat.blueprints.auth_dev',
'hawat.blueprints.auth_env',
'hawat.blueprints.design',
'hawat.blueprints.home',
'hawat.blueprints.reports',
'hawat.blueprints.events',
'hawat.blueprints.timeline',
'hawat.blueprints.geoip',
'hawat.blueprints.whois',
'hawat.blueprints.performance',
'hawat.blueprints.status',
'hawat.blueprints.dbstatus',
'hawat.blueprints.devtools',
'hawat.blueprints.users',
'hawat.blueprints.groups',
'hawat.blueprints.settings_reporting',
'hawat.blueprints.filters',
'hawat.blueprints.networks',
'hawat.blueprints.changelogs',
'hawat.blueprints.help',
]
"""Overwritten default value from :py:const:`hawat.config.Config.ENABLED_BLUEPRINTS`"""
HAWAT_LOGIN_VIEW = 'auth_dev.login'
"""Overwritten default value from :py:const:`hawat.config.Config.HAWAT_LOGIN_VIEW`"""
HAWAT_LOG_FILE = '/var/tmp/mentat-hawat.py.log'
"""Overwritten default value from :py:const:`hawat.config.Config.HAWAT_LOG_FILE`"""
class TestingConfig(Config): # pylint: disable=locally-disabled,too-few-public-methods
"""
Class containing *testing* Hawat applications` configurations.
"""
#---------------------------------------------------------------------------
#
# Flask internal configurations. Please refer to Flask documentation for
# more information about each confiuration key.
#
TESTING = True
"""Overwritten default value from :py:const:`hawat.config.Config.TESTING`"""
CONFIG_MAP = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig,
'default': ProductionConfig
}
"""Configuration map for easy mapping of configuration aliases to config objects."""