# Path: doorman/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, record_id):
# def reference_col(tablename, nullable=False, pk_name='id', **kwargs):
# 
# 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):


import datetime as dt
import string
import uuid
from flask_login import UserMixin
from doorman.database import (
    Column,
    Table,
    ForeignKey,
    Index,
    Model,
    SurrogatePK,
    db,
    reference_col,
    relationship,
    ARRAY,
    JSONB,
    INET,
    declared_attr,
)
from doorman.extensions import bcrypt
        from doorman.utils import assemble_configuration
        from doorman.utils import assemble_distributed_queries
        back_populates='nodes',
        lazy='joined',
    )

    def __init__(self, host_identifier, node_key=None,
                 enroll_secret=None, enrolled_on=None, last_checkin=None,
                 is_active=True, last_ip=None,
                 **kwargs):
        self.node_key = node_key or str(uuid.uuid4())
        self.host_identifier = host_identifier
        self.enroll_secret = enroll_secret
        self.enrolled_on = enrolled_on
        self.last_checkin = last_checkin
        self.is_active = is_active
        self.last_ip = last_ip

    def __repr__(self):
        return '<Node-{0.id}: node_key={0.node_key}, host_identifier={0.host_identifier}>'.format(self)

    def get_config(self, **kwargs):
        return assemble_configuration(self)

    def get_new_queries(self, **kwargs):
        return assemble_distributed_queries(self)

    @property
    def display_name(self):
        if 'display_name' in self.node_info and self.node_info['display_name']:
            return self.node_info['display_name']
        elif 'hostname' in self.node_info and self.node_info['hostname']:

# Path: doorman/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, record_id):
# def reference_col(tablename, nullable=False, pk_name='id', **kwargs):
# 
# 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/models.py
import datetime as dt
import string
import uuid
from flask_login import UserMixin
from doorman.database import (
    Column,
    Table,
    ForeignKey,
    Index,
    Model,
    SurrogatePK,
    db,
    reference_col,
    relationship,
    ARRAY,
    JSONB,
    INET,
    declared_attr,
)
from doorman.extensions import bcrypt
        from doorman.utils import assemble_configuration
        from doorman.utils import assemble_distributed_queries

        back_populates='nodes',
        lazy='joined',
    )

    def __init__(self, host_identifier, node_key=None,
                 enroll_secret=None, enrolled_on=None, last_checkin=None,
                 is_active=True, last_ip=None,
                 **kwargs):
        self.node_key = node_key or str(uuid.uuid4())
        self.host_identifier = host_identifier
        self.enroll_secret = enroll_secret
        self.enrolled_on = enrolled_on
        self.last_checkin = last_checkin
        self.is_active = is_active
        self.last_ip = last_ip

    def __repr__(self):
        return '<Node-{0.id}: node_key={0.node_key}, host_identifier={0.host_identifier}>'.format(self)

    def get_config(self, **kwargs):
        return assemble_configuration(self)

    def get_new_queries(self, **kwargs):
        return assemble_distributed_queries(self)

    @property
    def display_name(self):
        if 'display_name' in self.node_info and self.node_info['display_name']:
            return self.node_info['display_name']
        elif 'hostname' in self.node_info and self.node_info['hostname']:

            return self.node_info['hostname']