Skip to content

Commit

Permalink
save and parse agg rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushaga14 authored and ag060 committed Jan 15, 2025
1 parent 048dbf0 commit 6fce807
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ private void processRecord(HttpResponseParam record) throws Exception {
// we still push malicious requests to kafka

// todo: modify fetch yaml and read aggregate rules from it
List<Rule> rules = new ArrayList<>();
rules.add(new Rule("Lfi Rule 1", new Condition(10, 10)));
AggregationRules aggRules = new AggregationRules();
aggRules.setRule(rules);
// List<Rule> rules = new ArrayList<>();
// rules.add(new Rule("Lfi Rule 1", new Condition(10, 10)));
AggregationRules aggRules = apiFilter.getAggregationRules();
//aggRules.setRule(rules);

boolean isAggFilter = aggRules != null && !aggRules.getRule().isEmpty();

Expand Down
2 changes: 1 addition & 1 deletion libs/dao/src/main/java/com/akto/DaoInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,4 @@ public static void createIndices() {
VulnerableTestingRunResultDao.instance.createIndicesIfAbsent();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

public class AggregationLayerParser {

ObjectMapper objectMapper = new ObjectMapper();

public AggregationLayerParser() {
Expand All @@ -30,7 +30,6 @@ public AggregationRules parse(Map<String, Object> aggregationRules) throws Excep
} catch (Exception e) {
throw e;
}

return aggRules;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.util.List;
import java.util.Map;

import com.akto.dao.api_protection_parse_layer.AggregationLayerParser;
import com.akto.dao.test_editor.filter.ConfigParser;
import com.akto.dto.api_protection_parse_layer.AggregationRules;
import com.akto.dto.monitoring.FilterConfig;
import com.akto.dto.test_editor.ConfigParserResult;
import com.akto.dto.test_editor.ExecutorConfigParserResult;
Expand Down Expand Up @@ -36,15 +38,15 @@ public static FilterConfig parseConfig(Map<String, Object> config,boolean should
Object filterMap = config.get(FilterConfig.FILTER);
if (filterMap == null) {
isFilterError = true;
filterConfig = new FilterConfig(id, null, null);
filterConfig = new FilterConfig(id, null, null, null);
}

ConfigParser configParser = new ConfigParser();
ConfigParserResult filters = configParser.parse(filterMap);
if (filters == null) {
// todo: throw error
isFilterError = true;
filterConfig = new FilterConfig(id, null, null);
filterConfig = new FilterConfig(id, null, null, null);
}

Map<String, List<String>> wordListMap = new HashMap<>();
Expand All @@ -54,10 +56,10 @@ public static FilterConfig parseConfig(Map<String, Object> config,boolean should
}
} catch (Exception e) {
isFilterError = true;
filterConfig = new FilterConfig(id, filters, null);
filterConfig = new FilterConfig(id, filters, null, null);
}
if(!isFilterError){
filterConfig = new FilterConfig(id, filters, wordListMap);
filterConfig = new FilterConfig(id, filters, wordListMap, null);
}

if(shouldParseExecutor){
Expand All @@ -70,6 +72,18 @@ public static FilterConfig parseConfig(Map<String, Object> config,boolean should
filterConfig.setExecutor(executorConfigParserResult);
}

AggregationLayerParser parser = new AggregationLayerParser();
AggregationRules aggRules = null;
try {
aggRules = parser.parse(config);
} catch (Exception e) {
// TODO: handle exception
}

if (filterConfig != null) {
filterConfig.setAggregationRules(aggRules);
}

return filterConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Rule {

public Rule() {
}

public Rule(String name, Condition condition) {
this.name = name;
this.condition = condition;
Expand All @@ -25,7 +25,4 @@ public Condition getCondition() {
public void setCondition(Condition condition) {
this.condition = condition;
}



}
13 changes: 12 additions & 1 deletion libs/dao/src/main/java/com/akto/dto/monitoring/FilterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Map;

import com.akto.dto.api_protection_parse_layer.AggregationRules;
import com.akto.dto.test_editor.ConfigParserResult;
import com.akto.dto.test_editor.ExecutorConfigParserResult;

Expand All @@ -22,6 +23,7 @@ public class FilterConfig {
private String author;
public static final String _CONTENT = "content";
private String content;
private AggregationRules aggregationRules;

public static final String DEFAULT_ALLOW_FILTER = "DEFAULT_ALLOW_FILTER";
public static final String DEFAULT_BLOCK_FILTER = "DEFAULT_BLOCK_FILTER";
Expand All @@ -32,10 +34,11 @@ public enum FILTER_TYPE{

private ExecutorConfigParserResult executor;

public FilterConfig(String id, ConfigParserResult filter, Map<String, List<String>> wordLists) {
public FilterConfig(String id, ConfigParserResult filter, Map<String, List<String>> wordLists, AggregationRules aggregationRules) {
this.id = id;
this.filter = filter;
this.wordLists = wordLists;
this.aggregationRules = aggregationRules;
}

public FilterConfig() {
Expand Down Expand Up @@ -114,4 +117,12 @@ public ExecutorConfigParserResult getExecutor() {
public void setExecutor(ExecutorConfigParserResult executor) {
this.executor = executor;
}

public AggregationRules getAggregationRules() {
return aggregationRules;
}

public void setAggregationRules(AggregationRules aggregationRules) {
this.aggregationRules = aggregationRules;
}
}

0 comments on commit 6fce807

Please sign in to comment.