Make sure we always tag on limit_react
Done by moving the tagging into limit_react ...
Should fix
@@ -24,7 +24,14 @@ fn is_banned(cnx: &mut redis::Connection, key: &str) -> bool {
q.unwrap_or(None).is_some()
}
-fn limit_react(logs: &mut Logs, cnx: &mut redis::Connection, limit: &Limit, key: String) -> SimpleDecision {
+fn limit_react(
+ logs: &mut Logs,
+ tags: &mut Tags,
+ cnx: &mut redis::Connection,
+ limit: &Limit,
+ key: String,
+) -> SimpleDecision {
+ tags.insert(&limit.name);
let action = if let SimpleActionT::Ban(subaction, ttl) = &limit.action.atype {
logs.info(format!("Banned key {} for {}s", key, ttl));
let ban_key = get_ban_key(&key);
@@ -43,11 +50,14 @@ fn limit_react(logs: &mut Logs, cnx: &mut redis::Connection, limit: &Limit, key:
} else {
limit.action.clone()
};
- SimpleDecision::Action(action, serde_json::json!({
+ SimpleDecision::Action(
+ action,
+ serde_json::json!({
"initiator": "limit",
"limitname": limit.name,
"key": key
- }))
+ }),
+ )
}
fn redis_check_limit(
@@ -127,12 +137,13 @@ pub fn limit_check(
if limit.limit == 0 {
logs.debug("limit=0");
- return limit_react(logs, &mut redis, limit, key);
+ return limit_react(logs, tags, &mut redis, limit, key);
}
if is_banned(&mut redis, &key) {
logs.debug("is banned!");
- return limit_react(logs, &mut redis, limit, key);
+ tags.insert(&limit.name);
+ return limit_react(logs, tags, &mut redis, limit, key);
}
let pairvalue = limit.pairwith.as_ref().and_then(|sel| select_string(reqinfo, sel));
@@ -140,8 +151,7 @@ pub fn limit_check(
match redis_check_limit(&mut redis, &key, limit.limit, limit.ttl, pairvalue) {
Err(rr) => logs.error(rr),
Ok(true) => {
- tags.insert(&limit.name);
- return limit_react(logs, &mut redis, limit, key);
+ return limit_react(logs, tags, &mut redis, limit, key);
}
Ok(false) => (),
}
