Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add clean up attribute #1891

Merged
merged 6 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,35 @@ public String countTestingRunResultSummaries() {
return Action.SUCCESS.toUpperCase();
}

List<DependencyNode> dependencyNodes;

public List<DependencyNode> getDependencyNodes() {
return dependencyNodes;
}

public void setDependencyNodes(List<DependencyNode> dependencyNodes) {
this.dependencyNodes = dependencyNodes;
}

String reqMethod;

public String getReqMethod() {
return reqMethod;
}

public void setReqMethod(String reqMethod) {
this.reqMethod = reqMethod;
}

public String findDependencyNodes() {
try {
dependencyNodes = DbLayer.findDependencyNodes(apiCollectionId, url, methodVal, reqMethod);
} catch(Exception e){
e.printStackTrace();
}
return Action.SUCCESS.toUpperCase();
}

public String fetchTestScript() {
try {
testScript = DbLayer.fetchTestScript();
Expand Down
11 changes: 11 additions & 0 deletions apps/database-abstractor/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,17 @@
</result>
</action>

<action name="api/findDependencyNodes" class="com.akto.action.DbAction" method="findDependencyNodes">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<result name="SUCCESS" type="json"/>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

<action name="api/fetchTestScript" class="com.akto.action.DbAction" method="fetchTestScript">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ public class TestingRunConfig {
private String overriddenTestAppUrl;

private List<TestConfigsAdvancedSettings> configsAdvancedSettings;
private boolean cleanUp;

public TestingRunConfig() {}

public TestingRunConfig(int id, Map<Integer, List<ApiInfo.ApiInfoKey>> collectionWiseApiInfoKey,
List<String> testSubCategoryList, ObjectId authMechanismId, String overriddenTestAppUrl,
String testRoleId) {
this(id, collectionWiseApiInfoKey, testSubCategoryList, authMechanismId, overriddenTestAppUrl, testRoleId, false);
}

public TestingRunConfig(int id, Map<Integer, List<ApiInfo.ApiInfoKey>> collectionWiseApiInfoKey,
List<String> testSubCategoryList,
ObjectId authMechanismId, String overriddenTestAppUrl, String testRoleId) {
ObjectId authMechanismId, String overriddenTestAppUrl, String testRoleId, boolean cleanUp) {
this.id = id;
this.collectionWiseApiInfoKey = collectionWiseApiInfoKey;
this.testSubCategoryList = testSubCategoryList;
this.authMechanismId = authMechanismId;
this.overriddenTestAppUrl = overriddenTestAppUrl;
this.testRoleId = testRoleId;
this.cleanUp = cleanUp;
}

public List<String> getTestSubCategoryList() {
Expand Down Expand Up @@ -101,6 +111,8 @@ public void rebaseOn(TestingRunConfig that) {
if(this.testRoleId == null) {
this.testRoleId = that.testRoleId;
}

this.cleanUp = that.cleanUp;
}

public String getTestRoleId() {
Expand Down Expand Up @@ -128,4 +140,12 @@ public void setConfigsAdvancedSettings(List<TestConfigsAdvancedSettings> configs
this.configsAdvancedSettings = configsAdvancedSettings;
}

public boolean getCleanUp() {
return this.cleanUp;
}

public void setCleanUp(boolean cleanUp) {
this.cleanUp = cleanUp;
}

}
34 changes: 34 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/ClientActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3544,4 +3544,38 @@ public TestScript fetchTestScript(){
return testScript;
}

public List<DependencyNode> findDependencyNodes(int apiCollectionId, String urlVar, String method, String reqMethod) {
BasicDBObject obj = new BasicDBObject();
obj.put("apiCollectionId", apiCollectionId);
obj.put("url", urlVar);
obj.put("methodVal", method);
obj.put("reqMethod", reqMethod);
Map<String, List<String>> headers = buildHeaders();
OriginalHttpRequest request = new OriginalHttpRequest(url + "/findDependencyNodes", "", "POST", obj.toString(), headers, "");
try {
OriginalHttpResponse response = ApiExecutor.sendRequest(request, true, null, false, null);
String responsePayload = response.getBody();
if (response.getStatusCode() != 200 || responsePayload == null) {
loggerMaker.errorAndAddToDb("non 2xx response in findDependencyNodes", LoggerMaker.LogDb.TESTING);
return new ArrayList<>();
}
BasicDBObject payloadObj;
try {
payloadObj = BasicDBObject.parse(responsePayload);
BasicDBList dependencyNodesObj = (BasicDBList) payloadObj.get("dependencyNodes");
List<DependencyNode> dependencyNodes = new ArrayList<>();
for (Object nodeObj : dependencyNodesObj) {
BasicDBObject obj2 = (BasicDBObject) nodeObj;
dependencyNodes.add(objectMapper.readValue(obj2.toJson(), DependencyNode.class));
}
return dependencyNodes;
} catch (Exception e) {
return new ArrayList<>();
}
} catch (Exception e) {
loggerMaker.errorAndAddToDb("error in findDependencyNodes" + e, LoggerMaker.LogDb.RUNTIME);
return new ArrayList<>();
}
}

}
2 changes: 2 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DataActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,6 @@ public abstract class DataActor {

public abstract TestScript fetchTestScript();

public abstract List<DependencyNode> findDependencyNodes(int apiCollectionId, String url, String method, String reqMethod);

}
4 changes: 4 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,8 @@ public TestScript fetchTestScript(){
return DbLayer.fetchTestScript();
}

public List<DependencyNode> findDependencyNodes(int apiCollectionId, String url, String method, String reqMethod){
return DbLayer.findDependencyNodes(apiCollectionId, url, method, reqMethod);
}

}
8 changes: 8 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.akto.dto.traffic_metrics.TrafficMetrics;
import com.akto.dto.type.SingleTypeInfo;
import com.akto.dto.type.URLMethods;
import com.akto.dto.type.URLMethods.Method;
import com.akto.dto.usage.MetricTypes;
import com.akto.log.LoggerMaker;
import com.akto.log.LoggerMaker.LogDb;
Expand Down Expand Up @@ -1066,4 +1067,11 @@ public static TestScript fetchTestScript(){
return TestScriptsDao.instance.fetchTestScript();
}

public static List<DependencyNode> findDependencyNodes(int apiCollectionId, String url, String method, String reqMethod) {
Bson filterQ = DependencyNodeDao.generateChildrenFilter(apiCollectionId, url, Method.valueOf(method));
// TODO: Handle cases where the delete API does not have the delete method
Bson delFilterQ = Filters.and(filterQ, Filters.eq(DependencyNode.METHOD_REQ, reqMethod));
return DependencyNodeDao.instance.findAll(delFilterQ);
}

}
Loading