def _trace_user_action(action_name, auth_user, client_user, client_token, description, async_process):
    ip_address = get_user_ip()
    try:
        auth_user = auth_user or client_user or "UNKNOWN"
        action = UserTracedAction("REST", action_name, ip_address, auth_user,
                                  anonymous_user_token=client_token,
                                  description=description)
        register_user_action(action, async_process=async_process)
    except Exception as e:
        logger.warning("Error saving user trace: %s" % e)
Ejemplo n.º 2
0
 def _check_banned(self):
     '''Check if the ip is banned'''
     ip_address = get_user_ip()
     info = self._read_info(ip_address)
     if self._is_banned(info) and not self._ban_expired(info):
         logger.error(" BANNED IP BLOCKED! " + str(ip_address)
                      + " Count: " + str(info.counter)
                      + " Time left: " + str(self._ban_time_left(info)) + " s.")
         raise self.banned_http_response
     elif self._is_banned(info) and self._ban_expired(info):
         info = _reset_info()
     logger.debug("IP: %s, Time: %s Count: %s" % (ip_address, info.time, info.counter))
     return info, ip_address
def _trace_user_action(action_name, auth_user, client_user, client_token,
                       description, async_process):
    ip_address = get_user_ip()
    try:
        auth_user = auth_user or client_user or "UNKNOWN"
        action = UserTracedAction("REST",
                                  action_name,
                                  ip_address,
                                  auth_user,
                                  anonymous_user_token=client_token,
                                  description=description)
        register_user_action(action, async_process=async_process)
    except Exception as e:
        logger.warning("Error saving user trace: %s" % e)