Skip to content

Commit 02eea4c

Browse files
fixes for ClientActor
1 parent 38632db commit 02eea4c

File tree

6 files changed

+87
-13
lines changed

6 files changed

+87
-13
lines changed

apps/database-abstractor/src/main/java/com/akto/action/DbAction.java

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,21 @@ public String updateApiCollectionNameForVxlan() {
305305
return Action.SUCCESS.toUpperCase();
306306
}
307307

308+
String transportType;
309+
public String updateTransportType() {
310+
try {
311+
ApiCollection apiCollection = ApiCollectionsDao.instance.getMeta(apiCollectionId);
312+
if (apiCollection != null) {
313+
ApiCollectionsDao.instance.updateTransportType(apiCollection, transportType);
314+
}
315+
} catch (Exception e) {
316+
loggerMaker.errorAndAddToDb(e, "error in updateTransportType " + e.toString());
317+
return Action.ERROR.toUpperCase();
318+
}
319+
return Action.SUCCESS.toUpperCase();
320+
}
321+
322+
308323
public String updateCidrList() {
309324
try {
310325
DbLayer.updateCidrList(cidrList);
@@ -414,9 +429,9 @@ public String bulkWriteSti() {
414429
}
415430
}
416431
}
417-
432+
418433
System.out.println("filters: " + filters.toString());
419-
434+
420435
if (isDeleteWrite) {
421436
writes.add(
422437
new DeleteOneModel<>(Filters.and(filters), new DeleteOptions())
@@ -427,7 +442,7 @@ public String bulkWriteSti() {
427442
);
428443
}
429444
}
430-
445+
431446
DbLayer.bulkWriteSingleTypeInfo(writes);
432447
} catch (Exception e) {
433448
String err = "Error: ";
@@ -466,15 +481,15 @@ public String bulkWriteSampleData() {
466481

467482
String responseCodeStr = mObj.get("responseCode").toString();
468483
int responseCode = Integer.valueOf(responseCodeStr);
469-
484+
470485
Bson filters = Filters.and(Filters.eq("_id.apiCollectionId", apiCollectionId),
471486
Filters.eq("_id.bucketEndEpoch", bucketEndEpoch),
472487
Filters.eq("_id.bucketStartEpoch", bucketStartEpoch),
473488
Filters.eq("_id.method", mObj.get("method")),
474489
Filters.eq("_id.responseCode", responseCode),
475490
Filters.eq("_id.url", mObj.get("url")));
476491
List<String> updatePayloadList = bulkUpdate.getUpdates();
477-
492+
478493
List<Bson> updates = new ArrayList<>();
479494
for (String payload: updatePayloadList) {
480495
Map<String, Object> json = gson.fromJson(payload, Map.class);
@@ -836,23 +851,23 @@ public String bulkWriteOverageInfo() {
836851
Filters.eq(UningestedApiOverage.METHOD, bulkUpdate.getFilters().get(UningestedApiOverage.METHOD)),
837852
Filters.eq(UningestedApiOverage.URL, bulkUpdate.getFilters().get(UningestedApiOverage.URL))
838853
);
839-
854+
840855
List<String> updatePayloadList = bulkUpdate.getUpdates();
841856
List<Bson> updates = new ArrayList<>();
842-
857+
843858
for (String payload: updatePayloadList) {
844859
Map<String, Object> json = gson.fromJson(payload, Map.class);
845860
String field = (String) json.get("field");
846861
Object val = json.get("val");
847862
String op = (String) json.get("op");
848-
863+
849864
if ("setOnInsert".equals(op)) {
850865
updates.add(Updates.setOnInsert(field, val));
851866
} else if ("set".equals(op)) {
852867
updates.add(Updates.set(field, val));
853868
}
854869
}
855-
870+
856871
if (!updates.isEmpty()) {
857872
writes.add(
858873
new UpdateOneModel<>(filters, Updates.combine(updates), new UpdateOptions().upsert(true))
@@ -1129,7 +1144,7 @@ public String findPendingTestingRun() {
11291144
testingRun = DbLayer.findPendingTestingRun(delta);
11301145
if (testingRun != null) {
11311146
/*
1132-
* There is a db call involved for collectionWiseTestingEndpoints, thus this hack.
1147+
* There is a db call involved for collectionWiseTestingEndpoints, thus this hack.
11331148
*/
11341149
if(testingRun.getTestingEndpoints() instanceof CollectionWiseTestingEndpoints){
11351150
CollectionWiseTestingEndpoints ts = (CollectionWiseTestingEndpoints) testingRun.getTestingEndpoints();
@@ -1790,7 +1805,7 @@ public String fetchTestScript() {
17901805
return Action.ERROR.toUpperCase();
17911806
}
17921807
}
1793-
1808+
17941809
public String countTestingRunResultSummaries() {
17951810
count = DbLayer.countTestingRunResultSummaries(filter);
17961811
return Action.SUCCESS.toUpperCase();
@@ -2773,4 +2788,11 @@ public void setTestingRunPlayground(TestingRunPlayground testingRunPlayground) {
27732788
this.testingRunPlayground = testingRunPlayground;
27742789
}
27752790

2791+
public String getTransportType() {
2792+
return transportType;
2793+
}
2794+
2795+
public void setTransportType(String transportType) {
2796+
this.transportType = transportType;
2797+
}
27762798
}

apps/database-abstractor/src/main/resources/struts.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
</result>
5858
</action>
5959

60+
<action name="api/updateTransportType" class="com.akto.action.DbAction" method="updateTransportType">
61+
<interceptor-ref name="json"/>
62+
<interceptor-ref name="defaultStack" />
63+
<result name="SUCCESS" type="json"/>
64+
<result name="ERROR" type="json">
65+
<param name="statusCode">422</param>
66+
<param name="ignoreHierarchy">false</param>
67+
<param name="includeProperties">^actionErrors.*</param>
68+
</result>
69+
</action>
70+
71+
6072
<action name="api/updateCidrList" class="com.akto.action.DbAction" method="updateCidrList">
6173
<interceptor-ref name="json"/>
6274
<interceptor-ref name="defaultStack" />
@@ -1200,7 +1212,7 @@
12001212
<param name="includeProperties">^actionErrors.*</param>
12011213
</result>
12021214
</action>
1203-
1215+
12041216
<action name="api/countTestingRunResultSummaries" class="com.akto.action.DbAction" method="countTestingRunResultSummaries">
12051217
<interceptor-ref name="json"/>
12061218
<interceptor-ref name="defaultStack" />

libs/dao/src/main/java/com/akto/dao/ApiCollectionsDao.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public Map<Integer, ApiCollection> getApiCollectionsMetaMap() {
7474
return apiCollectionsMap;
7575
}
7676

77+
public void updateTransportType(ApiCollection apiCollection, String transportType) {
78+
Bson filter = Filters.eq(ApiCollection.ID, apiCollection.getId());
79+
Bson update = Updates.set(ApiCollection.MCP_TRANSPORT_TYPE, transportType);
80+
ApiCollectionsDao.instance.updateOne(filter, update);
81+
apiCollection.setMcpTransportType(transportType);
82+
}
83+
84+
7785
public List<ApiCollection> getMetaAll() {
7886
return ApiCollectionsDao.instance.findAll(new BasicDBObject(), Projections.exclude("urls"));
7987
}

libs/dao/src/main/java/com/akto/dto/ApiCollection.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ public class ApiCollection {
6262
String sseCallbackUrl;
6363
public static final String SSE_CALLBACK_URL = "sseCallbackUrl";
6464

65+
private String mcpTransportType;
66+
public static final String MCP_TRANSPORT_TYPE = "mcpTransportType";
67+
68+
public String getMcpTransportType() {
69+
return mcpTransportType;
70+
}
71+
72+
public void setMcpTransportType(String mcpTransportType) {
73+
this.mcpTransportType = mcpTransportType;
74+
}
75+
6576
public enum Type {
6677
API_GROUP
6778
}
@@ -91,7 +102,7 @@ public enum ENV_TYPE {
91102
"localhost", "local", "intranet", "lan", "example", "invalid",
92103
"home", "corp", "priv", "localdomain", "localnet", "network",
93104
"int", "private");
94-
105+
95106
private static final List<String> ENV_KEYWORDS_WITHOUT_DOT = Arrays.asList(
96107
"kubernetes", "internal"
97108
);

libs/utils/src/main/java/com/akto/data_actor/ClientActor.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,25 @@ public void updateModuleInfo(ModuleInfo moduleInfo) {
235235
}
236236
}
237237

238+
@Override
239+
public void updateTransportType(int apiCollectionId, String transportType) {
240+
Map<String, List<String>> headers = buildHeaders();
241+
BasicDBObject obj = new BasicDBObject();
242+
obj.put("apiCollectionId", apiCollectionId);
243+
obj.put("transportType", transportType);
244+
OriginalHttpRequest request = new OriginalHttpRequest(url + "/updateTransportType", "", "POST", obj.toString(), headers, "");
245+
try {
246+
OriginalHttpResponse response = ApiExecutor.sendRequest(request, true, null, false, null);
247+
if (response.getStatusCode() != 200) {
248+
loggerMaker.errorAndAddToDb("non 2xx response in updateTransportType", LoggerMaker.LogDb.RUNTIME);
249+
return;
250+
}
251+
} catch (Exception e) {
252+
loggerMaker.errorAndAddToDb("error updating transport type" + e + " apiCollectionId " + apiCollectionId
253+
+ " transportType " + transportType, LoggerMaker.LogDb.RUNTIME);
254+
}
255+
}
256+
238257
public APIConfig fetchApiConfig(String configName) {
239258
Map<String, List<String>> headers = buildHeaders();
240259
String queryParams = "?configName="+configName;

libs/utils/src/main/java/com/akto/data_actor/DataActor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public abstract class DataActor {
5757

5858
public abstract void updateApiCollectionNameForVxlan(int vxlanId, String name);
5959

60+
public abstract void updateTransportType(int apiCollectionId, String transportType);
61+
6062
public abstract APIConfig fetchApiConfig(String configName);
6163

6264
public abstract void bulkWriteSingleTypeInfo(List<Object> writesForApiInfo);

0 commit comments

Comments
 (0)