Ejemplo n.º 1
0
Archivo: cimi.py Proyecto: zhexuan/cimi
    def __call__(self, env, start_response):

        LOG.info(env)
        if env.get('SCRIPT_NAME', '').startswith(self.request_prefix):
            self._process_config_header(env)
            path = unquote(env.get('PATH_INFO', ''))
            response, controller, tenant_id, parts = self.get_controller(path)

            if response:
                return response(env, start_response)
            elif controller:
                req = Request(env)
                ctrler = controller(self.conf, self.app, req,
                                    tenant_id, *parts)
                method = env.get('REQUEST_METHOD').upper()
                if hasattr(ctrler, method) and not method.startswith('_'):
                    res = getattr(ctrler, method)(req, *parts)
                    return res(env, start_response)
                else:
                    res = get_err_response('NotImplemented')
                    return res(env, start_response)
            else:
                res = get_err_response('NotImplemented')
                return res(env, start_response)
        else:
            return self.app(env, start_response)
Ejemplo n.º 2
0
    def __call__(self, env, start_response):

        LOG.info(env)
        if env.get('SCRIPT_NAME', '').startswith(self.request_prefix):
            self._process_config_header(env)
            path = unquote(env.get('PATH_INFO', ''))
            response, controller, tenant_id, parts = self.get_controller(path)

            if response:
                return response(env, start_response)
            elif controller:
                req = Request(env)
                ctrler = controller(self.conf, self.app, req, tenant_id,
                                    *parts)
                method = env.get('REQUEST_METHOD').upper()
                if hasattr(ctrler, method) and not method.startswith('_'):
                    res = getattr(ctrler, method)(req, *parts)
                    return res(env, start_response)
                else:
                    res = get_err_response('NotImplemented')
                    return res(env, start_response)
            else:
                res = get_err_response('NotImplemented')
                return res(env, start_response)
        else:
            return self.app(env, start_response)
Ejemplo n.º 3
0
Archivo: cimi.py Proyecto: zhexuan/cimi
    def get_controller(self, path):
        """Get the request controller according to the request path

        this method returns a response, a controller and tenant id and parsed
        list of path.
        if the path starts with cimiv1, then this is CIMI request, the next
        segment in the path should indicate the controller. if the controller
        does not exist, then the response will indicate the error. if the
        controller is found, then the response will be None.
        if the path does not start with cimiv1, then this is not CIMI request,
        the controller and response will be none. the request should be
        forwarded to the next filter in the pipeline.

        """

        parts = path.strip('/').split('/')

        # each request should have /cimiv1/tenant_id/controller_key
        # in its url pattern.
        if len(parts) >= 2:
            controller_key = parts[1].lower()
            controller = self.CONTROLLERS.get(controller_key)
            return None, controller, parts[0], parts[2:]
        else:
            resp = get_err_response('BadRequest')
            return resp, None, None, None
Ejemplo n.º 4
0
    def get_controller(self, path):
        """Get the request controller according to the request path

        this method returns a response, a controller and tenant id and parsed
        list of path.
        if the path starts with cimiv1, then this is CIMI request, the next
        segment in the path should indicate the controller. if the controller
        does not exist, then the response will indicate the error. if the
        controller is found, then the response will be None.
        if the path does not start with cimiv1, then this is not CIMI request,
        the controller and response will be none. the request should be
        forwarded to the next filter in the pipeline.

        """

        parts = path.strip('/').split('/')

        # each request should have /cimiv1/tenant_id/controller_key
        # in its url pattern.
        if len(parts) >= 2:
            controller_key = parts[1].lower()
            controller = self.CONTROLLERS.get(controller_key)
            return None, controller, parts[0], parts[2:]
        else:
            resp = get_err_response('BadRequest')
            return resp, None, None, None