def process(self): """ Processes the request, analyzing the parameters, and feeding them to the _getAnswer() method (implemented by derived classes) """ g.rh = self sentry_set_tags({'rh': self.__class__.__name__}) self._process_args() self._check_access() return self._getAnswer()
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() init_email_queue() self._check_csrf() res = self._do_process() signals.after_process.send() if self.commit: db.session.commit() flush_email_queue() else: db.session.rollback() except DatabaseError: db.session.rollback() handle_sqlalchemy_database_error( ) # this will re-raise an exception except Exception: # rollback to avoid errors as rendering the error page # within the indico layout may trigger an auto-flush db.session.rollback() raise logger.debug('Request successful') if res is None: # flask doesn't accept None but we might be returning it in some places... res = '' response = current_app.make_response(res) if self.DENY_FRAMES: response.headers['X-Frame-Options'] = 'DENY' return response
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
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
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() init_email_queue() self._check_csrf() res = self._do_process() signals.after_process.send() if self.commit: db.session.commit() flush_email_queue() else: db.session.rollback() except DatabaseError: db.session.rollback() handle_sqlalchemy_database_error() # this will re-raise an exception except Exception: # rollback to avoid errors as rendering the error page # within the indico layout may trigger an auto-flush db.session.rollback() raise 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
def process(self): """ Processes the request, analyzing the parameters, and feeding them to the _getAnswer() method (implemented by derived classes) """ g.rh = self sentry_set_tags({'rh': self.__class__.__name__}) self._process_args() self._check_access() if self.CHECK_HTML: try: security.Sanitization.sanitizationCheck( self._params, ['requestInfo']) except HtmlForbiddenTag as e: raise HTMLSecurityError('ERR-X0', 'HTML Security problem. {}'.format(e)) if self._doProcess: if config.PROFILE: import profile, pstats, random proffilename = os.path.join(config.TEMP_DIR, "service%s.prof" % random.random()) result = [None] profile.runctx("result[0] = self._getAnswer()", globals(), locals(), proffilename) answer = result[0] stats = pstats.Stats(proffilename) stats.sort_stats('cumulative', 'time', 'calls') stats.dump_stats( os.path.join(config.TEMP_DIR, "IndicoServiceRequestProfile.log")) os.remove(proffilename) else: answer = self._getAnswer() return answer
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