# Path: doorman/api.py
# def node_required(f):
#     def decorated_function(*args, **kwargs):
# def index():
# def enroll():
# def configuration(node=None):
# def logger(node=None):
# def distributed_read(node=None):
# def distributed_write(node=None):
# 
# Path: doorman/assets.py

# 
# Path: doorman/extensions.py
# class LogTee(object):
# class RuleManager(object):
#     class ContextTask(TaskBase):
#     def __init__(self, app=None):
#     def init_app(self, app):
#     def handle_status(self, data, **kwargs):
#     def handle_result(self, data, **kwargs):
#     def __init__(self, app=None):
#     def init_app(self, app):
#     def load_alerters(self):
#     def should_reload_rules(self):
#     def load_rules(self):
#     def handle_log_entry(self, entry, node):
# def make_celery(app, celery):
#         def __call__(self, *args, **kwargs):
# 
# Path: doorman/settings.py
# class ProdConfig(Config):
# 
#     ENV = 'prod'
#     DEBUG = False
#     DEBUG_TB_ENABLED = False
#     DEBUG_TB_INTERCEPT_REDIRECTS = False
# 
#     ENFORCE_SSL = True
# 
#     SQLALCHEMY_DATABASE_URI = ''
# 
#     DOORMAN_ENROLL_SECRET = [
# 
#     ]
#     DOORMAN_MINIMUM_OSQUERY_LOG_LEVEL = 1
# 
#     BROKER_URL = ''
#     CELERY_RESULT_BACKEND = ''
# 
# Path: doorman/tasks.py
# def analyze_result(result, node):
# def learn_from_result(result, node):
# def example_task(one, two):
# def notify_of_node_enrollment(node):
# def alert_when_node_goes_offline():
# 
# Path: doorman/utils.py
# def get_node_health(node):
#     checkin_interval = current_app.config['DOORMAN_CHECKIN_INTERVAL']
#     if isinstance(checkin_interval, (int, float)):
#         checkin_interval = dt.timedelta(seconds=checkin_interval)
#     if (dt.datetime.utcnow() - node.last_checkin) > checkin_interval:
#         return u'danger'
#     else:
#         return ''
# 
# def pretty_field(field):
#     return PRETTY_FIELDS.get(field, field)
# 
# def pretty_operator(cond):
#     return PRETTY_OPERATORS.get(cond, cond)
# 
# def render_column(value, column):
#     renders = current_app.config.get('DOORMAN_COLUMN_RENDER', {})
#     if column not in renders:
#         return value
# 
#     template = renders[column]
# 
#     try:
#         if callable(template):
#             return template(value)
#         else:
#             template = Template(template, autoescape=True)
#             rendered = template.render(value=value)
# 
#             # return a markup object so that the template where this is
#             # rendered is not escaped again
# 
#             return Markup(rendered)
#     except Exception:
#         current_app.logger.exception(
#             "Failed to render %s, returning original value",
#             column
#         )
#         return value


import os
    import logging
    import sys
from flask import Flask, render_template
from doorman.api import blueprint as api
from doorman.assets import assets
from doorman.manage import blueprint as backend
from doorman.extensions import (
    bcrypt, csrf, db, debug_toolbar, ldap_manager, log_tee, login_manager,
    mail, make_celery, migrate, rule_manager, sentry
)
from doorman.settings import ProdConfig
from doorman.tasks import celery
from doorman.utils import get_node_health, pretty_field, pretty_operator, render_column
        from flask_sslify import SSLify
    from logging.handlers import WatchedFileHandler
    from doorman.users import views
        from doorman.users.mixins import NoAuthUserMixin
        from doorman.users.oauth import OAuthLogin

    for errcode in [401, 403, 404, 500]:
        app.errorhandler(errcode)(render_error)


def register_filters(app):
    app.jinja_env.filters['health'] = get_node_health
    app.jinja_env.filters['pretty_field'] = pretty_field
    app.jinja_env.filters['pretty_operator'] = pretty_operator
    app.jinja_env.filters['render'] = render_column


def register_auth_method(app):
    app.register_blueprint(views.blueprint)

    if app.config['DOORMAN_AUTH_METHOD'] is None:
        login_manager.anonymous_user = NoAuthUserMixin
        return

    login_manager.login_view = 'users.login'
    login_manager.login_message_category = 'warning'

    if app.config['DOORMAN_AUTH_METHOD'] == 'ldap':
        ldap_manager.init_app(app)
        return

    # no other authentication methods left, falling back to OAuth

    if app.config['DOORMAN_AUTH_METHOD'] != 'doorman':
        login_manager.login_message = None

# Path: doorman/api.py
# def node_required(f):
#     def decorated_function(*args, **kwargs):
# def index():
# def enroll():
# def configuration(node=None):
# def logger(node=None):
# def distributed_read(node=None):
# def distributed_write(node=None):
# 
# Path: doorman/assets.py

# 
# Path: doorman/extensions.py
# class LogTee(object):
# class RuleManager(object):
#     class ContextTask(TaskBase):
#     def __init__(self, app=None):
#     def init_app(self, app):
#     def handle_status(self, data, **kwargs):
#     def handle_result(self, data, **kwargs):
#     def __init__(self, app=None):
#     def init_app(self, app):
#     def load_alerters(self):
#     def should_reload_rules(self):
#     def load_rules(self):
#     def handle_log_entry(self, entry, node):
# def make_celery(app, celery):
#         def __call__(self, *args, **kwargs):
# 
# Path: doorman/settings.py
# class ProdConfig(Config):
# 
#     ENV = 'prod'
#     DEBUG = False
#     DEBUG_TB_ENABLED = False
#     DEBUG_TB_INTERCEPT_REDIRECTS = False
# 
#     ENFORCE_SSL = True
# 
#     SQLALCHEMY_DATABASE_URI = ''
# 
#     DOORMAN_ENROLL_SECRET = [
# 
#     ]
#     DOORMAN_MINIMUM_OSQUERY_LOG_LEVEL = 1
# 
#     BROKER_URL = ''
#     CELERY_RESULT_BACKEND = ''
# 
# Path: doorman/tasks.py
# def analyze_result(result, node):
# def learn_from_result(result, node):
# def example_task(one, two):
# def notify_of_node_enrollment(node):
# def alert_when_node_goes_offline():
# 
# Path: doorman/utils.py
# def get_node_health(node):
#     checkin_interval = current_app.config['DOORMAN_CHECKIN_INTERVAL']
#     if isinstance(checkin_interval, (int, float)):
#         checkin_interval = dt.timedelta(seconds=checkin_interval)
#     if (dt.datetime.utcnow() - node.last_checkin) > checkin_interval:
#         return u'danger'
#     else:
#         return ''
# 
# def pretty_field(field):
#     return PRETTY_FIELDS.get(field, field)
# 
# def pretty_operator(cond):
#     return PRETTY_OPERATORS.get(cond, cond)
# 
# def render_column(value, column):
#     renders = current_app.config.get('DOORMAN_COLUMN_RENDER', {})
#     if column not in renders:
#         return value
# 
#     template = renders[column]
# 
#     try:
#         if callable(template):
#             return template(value)
#         else:
#             template = Template(template, autoescape=True)
#             rendered = template.render(value=value)
# 
#             # return a markup object so that the template where this is
#             # rendered is not escaped again
# 
#             return Markup(rendered)
#     except Exception:
#         current_app.logger.exception(
#             "Failed to render %s, returning original value",
#             column
#         )
#         return value


# Path: doorman/application.py
import os
    import logging
    import sys
from flask import Flask, render_template
from doorman.api import blueprint as api
from doorman.assets import assets
from doorman.manage import blueprint as backend
from doorman.extensions import (
    bcrypt, csrf, db, debug_toolbar, ldap_manager, log_tee, login_manager,
    mail, make_celery, migrate, rule_manager, sentry
)
from doorman.settings import ProdConfig
from doorman.tasks import celery
from doorman.utils import get_node_health, pretty_field, pretty_operator, render_column
        from flask_sslify import SSLify
    from logging.handlers import WatchedFileHandler
    from doorman.users import views
        from doorman.users.mixins import NoAuthUserMixin
        from doorman.users.oauth import OAuthLogin


    for errcode in [401, 403, 404, 500]:
        app.errorhandler(errcode)(render_error)


def register_filters(app):
    app.jinja_env.filters['health'] = get_node_health
    app.jinja_env.filters['pretty_field'] = pretty_field
    app.jinja_env.filters['pretty_operator'] = pretty_operator
    app.jinja_env.filters['render'] = render_column


def register_auth_method(app):
    app.register_blueprint(views.blueprint)

    if app.config['DOORMAN_AUTH_METHOD'] is None:
        login_manager.anonymous_user = NoAuthUserMixin
        return

    login_manager.login_view = 'users.login'
    login_manager.login_message_category = 'warning'

    if app.config['DOORMAN_AUTH_METHOD'] == 'ldap':
        ldap_manager.init_app(app)
        return

    # no other authentication methods left, falling back to OAuth

    if app.config['DOORMAN_AUTH_METHOD'] != 'doorman':
        login_manager.login_message = None

        login_manager.needs_refresh_message = None