示例#1
0
 def __init__(self, portal):
     """
     Initialize the portal template class.
     """
     self.portal = portal
     
     # Shared modules
     self.json        = json
     self.base64      = base64
     self.OrderedDict = OrderedDict  
     
     # Configuration / logger
     self.conf        = config.parse()
     self.log         = logger.create(__name__, self.conf.portal.log)
  
     # URL panel
     self.panel       = self.get_query_key('panel')
     
     # Threaded API responses
     self._response   = {}
     
     # Template data
     self._tdata      = {}
  
     # Response filter
     self.filter      = APIFilter()
示例#2
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()
            })
示例#3
0
    def __init__(self, transport, buff_size=16384, socket_timeout=5.0,
                 progress=None, sanitize=_sh_quote):
        
        # Config / logger
        self.conf = config.parse()
        self.log  = logger.create(__name__, self.conf.server.log)
        """
        Create an scp1 client.

        @param transport: an existing paramiko L{Transport}
        @type transport: L{Transport}
        @param buff_size: size of the scp send buffer.
        @type buff_size: int
        @param socket_timeout: channel socket timeout in seconds
        @type socket_timeout: float
        @param progress: callback - called with (filename, size, sent) during
            transfers
        @param sanitize: function - called with filename, should return
            safe or escaped string.  Uses _sh_quote by default.
        @type progress: function(string, int, int)
        """
        self.transport = transport
        self.buff_size = buff_size
        self.socket_timeout = socket_timeout
        self.channel = None
        self.preserve_times = False
        self._progress = progress
        self._recv_dir = ''
        self._rename = False
        self._utime = None
        self.sanitize = sanitize
        self._dirtimes = {}
示例#4
0
 def __init__(self):
     
     # Target filter object / filter map
     self._object = None
 
     # Configuration / logger
     self.conf    = config.parse()
     self.log     = logger.create(__name__, self.conf.portal.log)
示例#5
0
 def __init__(self, user=None, group=None, api_key=None, api_token=None):
     self.api_user  = user       # API user
     self.api_group = group      # API group
     self.api_key   = api_key    # API key
     self.api_token = api_token  # API token
     
     # Configuration
     self.conf      = config.parse()
示例#6
0
 def __init__(self):
     
     # Configuration / logger objects
     self.conf  = config.parse()
     self.log   = logger.create(__name__, self.conf.utils.log)
     
     # Cache manager
     self.cache = CacheManager()
示例#7
0
 def __init__(self, params, sys, pkg):
     self.conf       = config.parse()
     self.params     = params
     self.sys        = sys
     self.pkg        = pkg
 
     # Create a collection class
     self.collection = Collection()
示例#8
0
 def __init__(self):
     
     # Configuration / logger
     self.conf       = config.parse()
     self.log        = logger.create(__name__, self.conf.server.log)
     
     # SocketIO client / web socket parameters
     self.socket_io  = None
     self.web_socket = None
示例#9
0
 def __init__(self, args):
     
     # Configuration / logger / feedback handler
     self.conf     = config.parse()
     self.log      = logger.create(__name__, self.conf.server.log)
     self.fb       = Feedback()
     
     # Actions mapper
     self.actions  = {
         'start': self._start,
         'stop': self._stop,
         'restart': self._restart,
         'status': self._status
     }
     
     # Services mapper
     self.services = {
         'portal':    {
             'apache': True,
             'label':  'portal'
         },
         'api': {
             'apache': True,
             'label':  'API server'
         },
         'socket':    {
             'apache': False,
             'pid':    self.conf.socket.pid,
             'label':  'API socket proxy',
             'start':  ['nohup', 'node', 
                 self.conf.socket.exe,
                 self.conf.socket.host, 
                 self.conf.socket.port, 
                 self.conf.socket.proto
             ]
         },
         'scheduler': {
             'apache': False,    
             'pid':    self.conf.scheduler.pid,
             'label':  'API scheduler',
             'start':  ['nohup', 'python',
                 self.conf.scheduler.exe 
             ]
         }
     }
     
     # Target action / service
     self.action   = None
     self.service  = None
     
     # Argument parser
     self.ap       = self._parse_args(args)
     
     # Server distribution and Apache service name
     self.distro   = platform.linux_distribution()[0]
示例#10
0
 def __init__(self):
     self.feedback = Feedback()
 
     # Configuration / logger
     self.conf   = config.parse()
     self.log    = logger.create('bootstrap', '%s/log/bootstrap.log' % L_BASE)
 
     # Bootstrap parameters
     self.params = BootstrapParams()
 
     # Server configuration file
     self.server_conf = self.params.file['config']['server_conf'][1]
     
     # Database connection
     self._connection = None
示例#11
0
 def __init__(self, args):
     """
     Initialize the schedule manager and store any command line arguments.
     """
     
     # Configuration / logger
     self.conf     = config.parse()
     self.log      = logger.create(__name__, self.conf.scheduler.log)
     
     # Modules / threads
     self.modules  = {}
     self.threads  = []
     
     # Load all scheduler modules
     self._load_modules()
示例#12
0
    def __init__(self, child):
        """
        Class constructor.
        
        :param child: Child class object
        :type child: class object
        """
    
        # Define the logger name
        log_name  = '%s.%s' % (__name__, child.__class__.__name__)

        # Running utilities on the server
        if os.path.isfile(S_CONF):
            self.conf = config.parse()
            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 or agent configuration')
示例#13
0
    def __init__(self, user, group, api_key=None, api_token=None, cli=False):
        
        # API connection attributes
        self.api_user  = user       # API user
        self.api_group = group      # API group
        self.api_key   = api_key    # API key
        self.api_token = api_token  # API token
        
        # Is this being run from the command line client
        self.cli       = cli
        
        # Token response
        self.token_rsp = None
        
        # Configuration
        self.conf      = config.parse()

        # Server URL
        self.api_url   = '%s://%s:%s' % (self.conf.server.proto, self.conf.server.host, self.conf.server.port)
示例#14
0
 def __init__(self, name):
     self.class_name    = 'cloudscape' if not name else name
     
     # Authentication flag
     self.authenticated = False
     
     # Raw request
     self.request_raw   = None
     
     # Request / API objects / application controllers
     self.request       = None
     self.api           = None
     self.controller    = {}
     
     # User object
     self.user          = {}
     
     # Initialize the configuration object and logger
     self.conf          = config.parse()
     self.log           = logger.create(self.class_name, self.conf.portal.log)
示例#15
0
 def __init__(self):
 
     # Load the configuration file
     self.conf_i = config.parse()
     
     # Supported configuration and default mappings
     self.conf_d = {
         'log':    CONFIG_LOG,
         'agent':  CONFIG_AGENT,
         'ssh':    CONFIG_SSHD,
         'sys':    CONFIG_SYS,
         'server': CONFIG_API
     } 
     
     # Linux doesn't use the SSH block
     if SYS_TYPE == 'linux':
         self.conf_d.pop('ssh', None)
     
     # Parsed and constructed configuration
     self.conf_p = self._parse()
示例#16
0
 def __init__(self, name):
     
     # Module name
     self.name       = name
     
     # Configuration and logger
     self.conf       = config.parse()
     self.log        = logger.create(name, self.conf.scheduler.log)
     
     # Internal API user / token
     self.api_user   = None
     self.api_group  = None
     self.api_token  = None
     
     # Time / datetime / JSON module
     self.time       = time
     self.datetime   = datetime
     self.json       = json
     
     # Endpoints
     self.endpoints  = self._load_endpoints()
     
     # Module initialized
     self.log.info('Initialized scheduler module: %s' % name)
示例#17
0
    def __init__(self, name=None, endpoint=None, utils=False, acl=None):
        """
        Initialize the APIBase class.
        
        @param name:     The module name used for the logger 
        @type  name:     str
        @param endpoint: The endpoint being accessed
        @type  endpoint: str
        @param utils:    Any external utilities required by this API endpoint
        @type  utils:    list
        @param acl:      The ACL gateway generated during request initialization
        @type  acl:      ACLGateway
        @param cache:    The CacheManager class instance
        @param cache:    CacheManager
        """
        
        # Class base / configuration / internal logger
        self.class_name   = __name__ if not name else name
        self.conf         = config.parse()
        self.log_int      = logger.create(self.class_name, self.conf.server.log)

        # External utilities / utilities object / cache manager / objects manager / ACL gateway
        self.utils        = utils
        self.util         = None
        self.cache        = CacheManager()
        self.objects      = ObjectsManager()
        self.acl          = acl

        # SocketIO client / Cache Manager
        self.socket       = SocketResponse().construct()

        # Request attributes
        self.request_raw  = None     # Raw request object
        self.action       = None     # Request action
        self.data         = None     # Any request data
        self.endpoint     = endpoint # Request endpoint
示例#18
0
import ldap
import json

# Django Libraries
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion

# CloudScape Libraries
import cloudscape.common.config as config

# Configuration
CONFIG = config.parse()

class AuthGroupsLDAP(object):
    """
    Construct an LDAPSearchUnion object for every LDAP search group defined.
    """
    
    @staticmethod
    def get_map():
        """
        Load the LDAP JSON map file.
        """
        try:
            return json.load(open(CONFIG.ldap.map))
        
        # Failed to parse JSON map file
        except Exception as e:
            raise Exception('Failed to load LDAP JSON map file [%s]: %s' % (CONFIG.ldap.map, str(e)))
    
    @staticmethod
    def construct():
示例#19
0
# CloudScape Libraries
from cloudscape.common import config
from cloudscape.common import logger
from cloudscape.common.vars import T_BASE
from cloudscape.engine.api.base import APIBase
from cloudscape.common.http import HEADER, PATH, JSONError, JSONException, HTTP_GET
from cloudscape.common.utils import JSONTemplate
from cloudscape.engine.api.auth.key import APIKey
from cloudscape.common.utils import valid, invalid, truncate
from cloudscape.engine.api.auth.acl import ACLGateway
from cloudscape.engine.api.auth.token import APIToken
from cloudscape.engine.api.app.user.models import DBUser
from cloudscape.engine.api.app.gateway.models import DBGatewayUtilities

# Configuration / Logger
CONF = config.parse()
LOG  = logger.create(__name__, CONF.server.log)

def dispatch(request):
    """
    The entry point for all API requests. Called for all endpoints from the Django
    URLs file. Creates a new instance of the EndpointManager class, and returns any
    HTTP response to the client that opened the API request.
    
    :param request: The Django request object
    :type request: object
    :rtype: object
    """
    try:
        
        # Return the response from the request manager
示例#20
0
 def __init__(self):
     
     # Configuration / logger objects
     self.conf = config.parse()
     self.log  = logger.create(__name__, self.conf.server.log)