Example #1
0
    def invokeMethod(self, method, params):
        result = None

        try:
            fossilize.clearCache()
            GenericMailer.flushQueue(False)
            try:
                try:
                    result = processRequest(method, copy.deepcopy(params))
                    signals.after_process.send()
                except NoReportError as e:
                    raise ServiceNoReportError(e.getMessage())
                except NoReportIndicoError as e:
                    raise ServiceNoReportError(e.getMessage(),
                                               title=_("Error"))
                db.session.commit()
            except DatabaseError:
                handle_sqlalchemy_database_error()
            GenericMailer.flushQueue(True)
        except Exception as e:
            db.session.rollback()
            if isinstance(e, CausedError):
                raise
            elif isinstance(e, ConstraintViolated):
                raise ProcessError, ('ERR-P0', e.message), sys.exc_info()[2]
            else:
                raise ProcessError('ERR-P0', 'Error processing method.')

        return result
Example #2
0
    def __call__(self, aw):
        """Perform the actual exporting"""
        if self.HTTP_POST != (request.method == 'POST'):
            raise HTTPAPIError('This action requires %s' % ('POST' if self.HTTP_POST else 'GET'), 405)
        if not self.GUEST_ALLOWED and not aw.getUser():
            raise HTTPAPIError('Guest access to this resource is forbidden.', 403)

        method_name = self._getMethodName()
        func = getattr(self, method_name, None)
        extra_func = getattr(self, method_name + '_extra', None)
        if not func:
            raise NotImplementedError(method_name)

        if not self.COMMIT:
            is_response, resultList, complete, extra = self._perform(aw, func, extra_func)
            db.session.rollback()
        else:
            try:
                GenericMailer.flushQueue(False)
                is_response, resultList, complete, extra = self._perform(aw, func, extra_func)
                db.session.commit()
                GenericMailer.flushQueue(True)
            except Exception:
                db.session.rollback()
                raise
        if is_response:
            return resultList
        return resultList, extra, complete, self.SERIALIZER_TYPE_MAP
Example #3
0
    def __call__(self, user):
        """Perform the actual exporting"""
        if self.HTTP_POST != (request.method == 'POST'):
            raise HTTPAPIError('This action requires %s' % ('POST' if self.HTTP_POST else 'GET'), 405)
        if not self.GUEST_ALLOWED and not user:
            raise HTTPAPIError('Guest access to this resource is forbidden.', 403)

        method_name = self._getMethodName()
        func = getattr(self, method_name, None)
        extra_func = getattr(self, method_name + '_extra', None)
        if not func:
            raise NotImplementedError(method_name)

        if not self.COMMIT:
            is_response, resultList, complete, extra = self._perform(user, func, extra_func)
            db.session.rollback()
        else:
            try:
                GenericMailer.flushQueue(False)
                is_response, resultList, complete, extra = self._perform(user, func, extra_func)
                db.session.commit()
                GenericMailer.flushQueue(True)
            except Exception:
                db.session.rollback()
                raise
        if is_response:
            return resultList
        return resultList, extra, complete, self.SERIALIZER_TYPE_MAP
Example #4
0
 def _process_success(self):
     Logger.get('requestHandler').info('Request successful')
     # request is succesfull, now, doing tasks that must be done only once
     try:
         GenericMailer.flushQueue(True)  # send emails
         self._deleteTempFiles()
     except:
         Logger.get('mail').exception('Mail sending operation failed')
Example #5
0
def invoke_method(method, params):
    result = None
    fossilize.clearCache()
    GenericMailer.flushQueue(False)
    try:
        result = _process_request(method, copy.deepcopy(params))
        signals.after_process.send()
        db.session.commit()
    except DatabaseError:
        db.session.rollback()
        handle_sqlalchemy_database_error()
    GenericMailer.flushQueue(True)
    return result
Example #6
0
def invoke_method(method, params):
    result = None
    fossilize.clearCache()
    GenericMailer.flushQueue(False)
    try:
        result = _process_request(method, copy.deepcopy(params))
        signals.after_process.send()
        db.session.commit()
    except DatabaseError:
        db.session.rollback()
        handle_sqlalchemy_database_error()
    GenericMailer.flushQueue(True)
    return result
Example #7
0
    def process(self):
        if request.method not in HTTP_VERBS:
            # Just to be sure that we don't get some crappy http verb we don't expect
            raise BadRequest

        res = ''
        g.rh = self
        sentry_set_tags({'rh': self.__class__.__name__})

        if self.EVENT_FEATURE is not None:
            self._check_event_feature()

        logger.info('%s %s [IP=%s] [PID=%s] [UID=%r]', request.method,
                    request.relative_url, request.remote_addr, os.getpid(),
                    session.get('_user_id'))

        try:
            fossilize.clearCache()
            GenericMailer.flushQueue(False)
            self._check_csrf()
            res = self._do_process()
            signals.after_process.send()

            if self.commit:
                if GenericMailer.has_queue():
                    # ensure we fail early (before sending out e-mails)
                    # in case there are DB constraint violations, etc...
                    db.enforce_constraints()
                    GenericMailer.flushQueue(True)

                db.session.commit()
            else:
                db.session.rollback()
        except DatabaseError:
            db.session.rollback()
            handle_sqlalchemy_database_error(
            )  # this will re-raise an exception
        logger.debug('Request successful')

        if res is None:
            return self._responseUtil.make_empty()

        response = self._responseUtil.make_response(res)
        if self.DENY_FRAMES:
            response.headers['X-Frame-Options'] = 'DENY'
        return response
Example #8
0
    def process(self):
        if request.method not in HTTP_VERBS:
            # Just to be sure that we don't get some crappy http verb we don't expect
            raise BadRequest

        res = ''
        g.rh = self
        sentry_set_tags({'rh': self.__class__.__name__})

        if self.EVENT_FEATURE is not None:
            self._check_event_feature()

        logger.info('%s %s [IP=%s] [PID=%s] [UID=%r]',
                    request.method, request.relative_url, request.remote_addr, os.getpid(), session.get('_user_id'))

        try:
            fossilize.clearCache()
            GenericMailer.flushQueue(False)
            self._check_csrf()
            res = self._do_process()
            signals.after_process.send()

            if self.commit:
                if GenericMailer.has_queue():
                    # ensure we fail early (before sending out e-mails)
                    # in case there are DB constraint violations, etc...
                    db.enforce_constraints()
                    GenericMailer.flushQueue(True)

                db.session.commit()
            else:
                db.session.rollback()
        except DatabaseError:
            db.session.rollback()
            handle_sqlalchemy_database_error()  # this will re-raise an exception
        logger.debug('Request successful')

        if res is None:
            return self._responseUtil.make_empty()

        response = self._responseUtil.make_response(res)
        if self.DENY_FRAMES:
            response.headers['X-Frame-Options'] = 'DENY'
        return response
Example #9
0
    def process(self, params):
        if request.method not in HTTP_VERBS:
            # Just to be sure that we don't get some crappy http verb we don't expect
            raise BadRequest

        cfg = Config.getInstance()
        profile = cfg.getProfile()
        profile_name, res, textLog = '', '', []

        self._startTime = datetime.now()

        g.rh = self

        if self.EVENT_FEATURE is not None:
            self._check_event_feature()

        textLog.append("%s : Database request started" % (datetime.now() - self._startTime))
        logger.info(u'Request started: %s %s [IP=%s] [PID=%s]',
                    request.method, request.relative_url, request.remote_addr, os.getpid())

        is_error_response = False
        try:
            try:
                fossilize.clearCache()
                GenericMailer.flushQueue(False)
                self._check_auth(params)
                profile_name, res = self._do_process(profile)
                signals.after_process.send()

                if self.commit:
                    if GenericMailer.has_queue():
                        # ensure we fail early (before sending out e-mails)
                        # in case there are DB constraint violations, etc...
                        db.enforce_constraints()
                        GenericMailer.flushQueue(True)

                    db.session.commit()
                else:
                    db.session.rollback()
            except DatabaseError:
                handle_sqlalchemy_database_error()  # this will re-raise an exception
            logger.info('Request successful')
        except Exception as e:
            db.session.rollback()
            res = self._getMethodByExceptionName(e)(e)
            if isinstance(e, HTTPException) and e.response is not None:
                res = e.response
            is_error_response = True

        totalTime = (datetime.now() - self._startTime)
        textLog.append('{} : Request ended'.format(totalTime))

        # log request timing
        if profile and os.path.isfile(profile_name):
            rep = Config.getInstance().getTempDir()
            stats = pstats.Stats(profile_name)
            stats.sort_stats('cumulative', 'time', 'calls')
            stats.dump_stats(os.path.join(rep, 'IndicoRequestProfile.log'))
            output = StringIO.StringIO()
            sys.stdout = output
            stats.print_stats(100)
            sys.stdout = sys.__stdout__
            s = output.getvalue()
            f = file(os.path.join(rep, 'IndicoRequest.log'), 'a+')
            f.write('--------------------------------\n')
            f.write('URL     : {}\n'.format(request.url))
            f.write('{} : start request\n'.format(self._startTime))
            f.write('params:{}'.format(params))
            f.write('\n'.join(textLog))
            f.write(s)
            f.write('--------------------------------\n\n')
            f.close()
        if profile and profile_name and os.path.exists(profile_name):
            os.remove(profile_name)

        if self._responseUtil.call:
            return self._responseUtil.make_call()

        if is_error_response and isinstance(res, (current_app.response_class, Response)):
            # if we went through error handling code, responseUtil._status has been changed
            # so make_response() would fail
            return res

        # In case of no process needed, we should return empty string to avoid erroneous output
        # specially with getVars breaking the JS files.
        if not self._doProcess or res is None:
            return self._responseUtil.make_empty()

        return self._responseUtil.make_response(res)
Example #10
0
    def process(self):
        if request.method not in HTTP_VERBS:
            # Just to be sure that we don't get some crappy http verb we don't expect
            raise BadRequest

        profile = config.PROFILE
        profile_name, res, textLog = '', '', []

        self._startTime = datetime.now()

        g.rh = self
        sentry_set_tags({'rh': self.__class__.__name__})

        if self.EVENT_FEATURE is not None:
            self._check_event_feature()

        textLog.append("%s : Database request started" %
                       (datetime.now() - self._startTime))
        logger.info(u'Request started: %s %s [IP=%s] [PID=%s]', request.method,
                    request.relative_url, request.remote_addr, os.getpid())

        is_error_response = False
        try:
            try:
                fossilize.clearCache()
                GenericMailer.flushQueue(False)
                self._check_auth()
                profile_name, res = self._do_process(profile)
                signals.after_process.send()

                if self.commit:
                    if GenericMailer.has_queue():
                        # ensure we fail early (before sending out e-mails)
                        # in case there are DB constraint violations, etc...
                        db.enforce_constraints()
                        GenericMailer.flushQueue(True)

                    db.session.commit()
                else:
                    db.session.rollback()
            except DatabaseError:
                handle_sqlalchemy_database_error(
                )  # this will re-raise an exception
            logger.info('Request successful')
        except Exception as e:
            db.session.rollback()
            res = self._get_error_handler(e)(e)
            if isinstance(e, HTTPException) and e.response is not None:
                res = e.response
            is_error_response = True

        totalTime = (datetime.now() - self._startTime)
        textLog.append('{} : Request ended'.format(totalTime))

        # log request timing
        if profile and os.path.isfile(profile_name):
            rep = config.TEMP_DIR
            stats = pstats.Stats(profile_name)
            stats.sort_stats('cumulative', 'time', 'calls')
            stats.dump_stats(os.path.join(rep, 'IndicoRequestProfile.log'))
            os.remove(profile_name)

        if is_error_response and isinstance(
                res, (current_app.response_class, Response)):
            # if we went through error handling code, responseUtil._status has been changed
            # so make_response() would fail
            return res

        # In case of no process needed, we should return empty string to avoid erroneous output
        # specially with getVars breaking the JS files.
        if not self._doProcess or res is None:
            return self._responseUtil.make_empty()

        response = self._responseUtil.make_response(res)
        if self.DENY_FRAMES:
            response.headers['X-Frame-Options'] = 'DENY'
        return response