# Path: djangolg/events.py
# EVENT_START = 0
# EVENT_QUERY_ACCEPT = 1
# EVENT_QUERY_REJECT = 2
# EVENT_QUERY_INVALID = 3
# EVENT_QUERY_FAILED = 4
# EVENT_QUERY_ERROR = 5
# EVENT_CHOICES = (
#     (EVENT_START, "Session Started"),
#     (EVENT_QUERY_ACCEPT, "Query Authorised"),
#     (EVENT_QUERY_REJECT, "Query Rejected"),
#     (EVENT_QUERY_INVALID, "Invalid Query"),
#     (EVENT_QUERY_FAILED, "Query Execution Failed"),
#     (EVENT_QUERY_ERROR, "Unhandled Error")
# )
# 
# Path: djangolg/exceptions.py
# DEFAULT_EVENT = events.EVENT_QUERY_ERROR
# DEFAULT_STATUS = 500
# DEFAULT_REASON = "An unhandled error occured. \
#                   Please try again or contact support."
# class LookingGlassError(Exception):
# class TypeCheckError(TypeError):
#     def log_error(self):
# def check_type(instance=None, classinfo=None):
# def default_error_message(e=None):
# 
# Path: djangolg/settings.py
# NETNAME = getattr(settings, 'DJANGOLG_NETNAME', "Example Network")
# GENERAL_EMAIL = getattr(settings, 'DJANGOLG_GENERAL_EMAIL',
#                         "contact@example.com")
# SUPPORT_EMAIL = getattr(settings, 'DJANGOLG_SUPPORT_EMAIL', None)
# NOC_EMAIL = getattr(settings, 'DJANGOLG_NOC_EMAIL', None)
# PEERING_EMAIL = getattr(settings, 'DJANGOLG_PEERING_EMAIL', None)
# ROUTER_LABEL = getattr(
#     settings, 'DJANGOLG_ROUTER_LABEL',
#     lambda router:
#         router.location.name if router.location else str(router)
# )
# LIFETIME = getattr(settings, 'DJANGOLG_LIFETIME', 300)
# MAX_REQUESTS = getattr(settings, 'DJANGOLG_MAX_REQUESTS', 20)
# AUP_LINK = getattr(settings, 'DJANGOLG_AUP_LINK', None)
# RECAPTCHA_ON = getattr(settings, 'DJANGOLG_RECAPTCHA_ON', False)
# RECAPTCHA_URL = getattr(settings, 'DJANGOLG_RECAPTCHA_URL',
#                         'https://www.google.com/recaptcha/api/siteverify')
# RECAPTCHA_SITE_KEY = getattr(settings, 'DJANGOLG_RECAPTCHA_SITE_KEY', None)
# RECAPTCHA_SECRET_KEY = getattr(settings, 'DJANGOLG_RECAPTCHA_SECRET_KEY', None)
# BASE_TEMPLATE = getattr(settings, 'DJANGOLG_BASE_TEMPLATE',
#                         'djangolg/base.html')
# LOGO = getattr(settings, 'DJANGOLG_LOGO', 'djangolg/img/logo.jpg')
# SMALL_LOGO = getattr(settings, 'DJANGOLG_SMALL_LOGO',
#                      'djangolg/img/small_logo.jpg')
# FAVICON = getattr(settings, 'DJANGOLG_FAVICON', 'djangolg/img/favicon.ico')
# NAV_IMG = getattr(settings, 'DJANGOLG_NAV_IMG', None)
# FORMATTED_OUTPUT = getattr(settings, 'DJANGOLG_FORMATTED_OUTPUT', False)
# DEBUG = getattr(settings, 'DJANGOLG_DEBUG', False)
# _DEFAULT_METHODS = [
#     'djangolg.methods.bgp_prefix.BGPPrefixMethod',
#     'djangolg.methods.bgp_as_path.BGPASPathMethod',
#     'djangolg.methods.bgp_community.BGPCommunityMethod',
#     'djangolg.methods.ping.PingMethod',
#     'djangolg.methods.traceroute.TracerouteMethod',
# ]
# CUSTOM_METHODS = getattr(settings, 'DJANGOLG_CUSTOM_METHODS', [])
# METHODS = getattr(settings, 'DJANGOLG_METHODS',
#                   _DEFAULT_METHODS + CUSTOM_METHODS)
# _DEFAULT_DIALECTS = [
#     'djangolg.dialects.cisco_ios.CiscoIOSDialect',
# ]
# CUSTOM_DIALECTS = getattr(settings, 'DJANGOLG_CUSTOM_DIALECTS', [])
# DIALECTS = getattr(settings, 'DJANGOLG_DIALECTS',
#                    _DEFAULT_DIALECTS + CUSTOM_DIALECTS)


from django.core.signing import SignatureExpired, TimestampSigner
from djangolg import events, exceptions, settings
from __future__ import print_function
from __future__ import unicode_literals




class AuthKey(object):
    """Command authorisation key class."""

    def __init__(self, value=None):
        """Initialise new AuthKey instance."""
        self.signer = TimestampSigner(salt="auth")
        self._data = {
            'clear': value,
            'signed': self.signer.sign(value)
        }

    @property
    def clear(self):
        """Get cleartext key value."""
        return self._data['clear']

    @property
    def signed(self):
        """Get cyphertext key value."""
        return self._data['signed']

    def validate(self, key, life=None):
        """Validate key value."""
        if not life and settings.LIFETIME:

# Path: djangolg/events.py
# EVENT_START = 0
# EVENT_QUERY_ACCEPT = 1
# EVENT_QUERY_REJECT = 2
# EVENT_QUERY_INVALID = 3
# EVENT_QUERY_FAILED = 4
# EVENT_QUERY_ERROR = 5
# EVENT_CHOICES = (
#     (EVENT_START, "Session Started"),
#     (EVENT_QUERY_ACCEPT, "Query Authorised"),
#     (EVENT_QUERY_REJECT, "Query Rejected"),
#     (EVENT_QUERY_INVALID, "Invalid Query"),
#     (EVENT_QUERY_FAILED, "Query Execution Failed"),
#     (EVENT_QUERY_ERROR, "Unhandled Error")
# )
# 
# Path: djangolg/exceptions.py
# DEFAULT_EVENT = events.EVENT_QUERY_ERROR
# DEFAULT_STATUS = 500
# DEFAULT_REASON = "An unhandled error occured. \
#                   Please try again or contact support."
# class LookingGlassError(Exception):
# class TypeCheckError(TypeError):
#     def log_error(self):
# def check_type(instance=None, classinfo=None):
# def default_error_message(e=None):
# 
# Path: djangolg/settings.py
# NETNAME = getattr(settings, 'DJANGOLG_NETNAME', "Example Network")
# GENERAL_EMAIL = getattr(settings, 'DJANGOLG_GENERAL_EMAIL',
#                         "contact@example.com")
# SUPPORT_EMAIL = getattr(settings, 'DJANGOLG_SUPPORT_EMAIL', None)
# NOC_EMAIL = getattr(settings, 'DJANGOLG_NOC_EMAIL', None)
# PEERING_EMAIL = getattr(settings, 'DJANGOLG_PEERING_EMAIL', None)
# ROUTER_LABEL = getattr(
#     settings, 'DJANGOLG_ROUTER_LABEL',
#     lambda router:
#         router.location.name if router.location else str(router)
# )
# LIFETIME = getattr(settings, 'DJANGOLG_LIFETIME', 300)
# MAX_REQUESTS = getattr(settings, 'DJANGOLG_MAX_REQUESTS', 20)
# AUP_LINK = getattr(settings, 'DJANGOLG_AUP_LINK', None)
# RECAPTCHA_ON = getattr(settings, 'DJANGOLG_RECAPTCHA_ON', False)
# RECAPTCHA_URL = getattr(settings, 'DJANGOLG_RECAPTCHA_URL',
#                         'https://www.google.com/recaptcha/api/siteverify')
# RECAPTCHA_SITE_KEY = getattr(settings, 'DJANGOLG_RECAPTCHA_SITE_KEY', None)
# RECAPTCHA_SECRET_KEY = getattr(settings, 'DJANGOLG_RECAPTCHA_SECRET_KEY', None)
# BASE_TEMPLATE = getattr(settings, 'DJANGOLG_BASE_TEMPLATE',
#                         'djangolg/base.html')
# LOGO = getattr(settings, 'DJANGOLG_LOGO', 'djangolg/img/logo.jpg')
# SMALL_LOGO = getattr(settings, 'DJANGOLG_SMALL_LOGO',
#                      'djangolg/img/small_logo.jpg')
# FAVICON = getattr(settings, 'DJANGOLG_FAVICON', 'djangolg/img/favicon.ico')
# NAV_IMG = getattr(settings, 'DJANGOLG_NAV_IMG', None)
# FORMATTED_OUTPUT = getattr(settings, 'DJANGOLG_FORMATTED_OUTPUT', False)
# DEBUG = getattr(settings, 'DJANGOLG_DEBUG', False)
# _DEFAULT_METHODS = [
#     'djangolg.methods.bgp_prefix.BGPPrefixMethod',
#     'djangolg.methods.bgp_as_path.BGPASPathMethod',
#     'djangolg.methods.bgp_community.BGPCommunityMethod',
#     'djangolg.methods.ping.PingMethod',
#     'djangolg.methods.traceroute.TracerouteMethod',
# ]
# CUSTOM_METHODS = getattr(settings, 'DJANGOLG_CUSTOM_METHODS', [])
# METHODS = getattr(settings, 'DJANGOLG_METHODS',
#                   _DEFAULT_METHODS + CUSTOM_METHODS)
# _DEFAULT_DIALECTS = [
#     'djangolg.dialects.cisco_ios.CiscoIOSDialect',
# ]
# CUSTOM_DIALECTS = getattr(settings, 'DJANGOLG_CUSTOM_DIALECTS', [])
# DIALECTS = getattr(settings, 'DJANGOLG_DIALECTS',
#                    _DEFAULT_DIALECTS + CUSTOM_DIALECTS)


# Path: djangolg/keys.py
from django.core.signing import SignatureExpired, TimestampSigner
from djangolg import events, exceptions, settings

from __future__ import print_function
from __future__ import unicode_literals




class AuthKey(object):
    """Command authorisation key class."""

    def __init__(self, value=None):
        """Initialise new AuthKey instance."""
        self.signer = TimestampSigner(salt="auth")
        self._data = {
            'clear': value,
            'signed': self.signer.sign(value)
        }

    @property
    def clear(self):
        """Get cleartext key value."""
        return self._data['clear']

    @property
    def signed(self):
        """Get cyphertext key value."""
        return self._data['signed']

    def validate(self, key, life=None):
        """Validate key value."""
        if not life and settings.LIFETIME:

            life = settings.LIFETIME