Example #1
0
    def __init__(self, error=None, status=500, exception=False):

        # Configuration / logger
        self.conf = config.parse()
        self.log  = logger.create(__name__, self.conf.server.log)

        # Store the response status code
        self.status = status

        # Construct the JSON error object
        self.error_object = {
            'message': ERR_MESSAGE.get(self.status, 'An unknown error has occurred, please contact your administrator'),
            'code':    self.status,
            'error':   error if not isinstance(error, (list, dict)) else json.dumps(error)
        }
        
        # If an error message is provided
        if error and isinstance(error, (str, unicode, basestring)):
            self.log.error(error)
        
        # If providing a stack trace for debugging and debugging is enabled
        if exception and self.conf.server.debug:
            self.error_object.update({
                'debug': self._extract_trace()
            })
Example #2
0
 def __init__(self):
     self.feedback = Feedback()
 
     # Configuration / logger
     self.conf   = config.parse()
     self.log    = logger.create('bootstrap', '{}/bootstrap.log'.format(LOG_DIR))
 
     # Bootstrap parameters
     self.params = BootstrapParams()
 
     # Server configuration file
     self.server_conf = self.params.file['config']['server_conf'][1]
     
     # Database connection
     self._connection = None
Example #3
0
    def __init__(self, child):
        """
        Class constructor.
        
        :param child: Child class object
        :type child: class object
        """
    
        # Define the logger name
        log_name  = '{}.{}'.format(__name__, child.__class__.__name__)

        # Running utilities on the server
        if os.path.isfile(LENSE_CONFIG.SERVER):
            self.conf = config.parse('SERVER')
            self.log  = logger.create(log_name, self.conf.utils.log)
            
        # Raise an exception if neither the server nor agent configuration is found
        else:
            raise Exception('Could not locate the server configuration')
Example #4
0
import re

# Django Libraries
from django_auth_ldap.backend import LDAPBackend
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth import get_backends, get_user_model

# Lense Libraries
from lense.common import config
from lense.common import logger
from lense.common.utils import rstring
from lense.common.auth.utils import AuthGroupsLDAP

# Configuration / logger
CONFIG = config.parse('SERVER')
LOG    = logger.create(__name__, CONFIG.utils.log)
                
class AuthBackendLDAP(LDAPBackend):
    """
    Class wrapper for querying the LDAP server for authentication.
    """ 
    def __init__(self):
        super(AuthBackendLDAP, self).__init__()
    
        # Get the LDAP JSON map object
        self.map = AuthGroupsLDAP.get_map()
    
    def _map_user_attrs(self, ldap_attrs, group_attrs):
        """
        Map LDAP user attributes to database user attributes.
        """