-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1613 from akto-api-security/feature/audit_logs
Feature/audit logs
- Loading branch information
Showing
18 changed files
with
768 additions
and
52 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
apps/dashboard/src/main/java/com/akto/action/settings/ApiAuditLogsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.akto.action.settings; | ||
|
||
import com.akto.action.UserAction; | ||
import com.akto.dao.audit_logs.ApiAuditLogsDao; | ||
import com.akto.dto.User; | ||
import com.akto.dto.audit_logs.ApiAuditLogs; | ||
import com.mongodb.client.model.Filters; | ||
import com.mongodb.client.model.Sorts; | ||
import org.bson.conversions.Bson; | ||
|
||
import java.util.List; | ||
|
||
public class ApiAuditLogsAction extends UserAction { | ||
private int skip; | ||
private int limit; | ||
private int sortOrder; | ||
private int startTimestamp; | ||
private int endTimestamp; | ||
|
||
private List<ApiAuditLogs> apiAuditLogs; | ||
private long totalAuditLogs; | ||
public String fetchApiAuditLogsFromDb() { | ||
User user = getSUser(); | ||
if(user == null) return ERROR.toUpperCase(); | ||
|
||
Bson filters = Filters.and( | ||
Filters.gte(ApiAuditLogs.TIMESTAMP, startTimestamp), | ||
Filters.lt(ApiAuditLogs.TIMESTAMP, endTimestamp) | ||
); | ||
Bson sort = sortOrder == -1 ? Sorts.descending(ApiAuditLogs.TIMESTAMP) : Sorts.ascending(ApiAuditLogs.TIMESTAMP); | ||
|
||
if(limit == -1) { | ||
apiAuditLogs = ApiAuditLogsDao.instance.findAll(filters); | ||
totalAuditLogs = apiAuditLogs.size(); | ||
} else { | ||
apiAuditLogs = ApiAuditLogsDao.instance.findAll(filters, skip, limit, sort); | ||
totalAuditLogs = ApiAuditLogsDao.instance.getMCollection().countDocuments(Filters.empty()); | ||
} | ||
|
||
return SUCCESS.toUpperCase(); | ||
} | ||
|
||
public List<ApiAuditLogs> getApiAuditLogs() { | ||
return apiAuditLogs; | ||
} | ||
|
||
public long getTotalAuditLogs() { | ||
return totalAuditLogs; | ||
} | ||
|
||
public void setSortOrder(int sortOrder) { | ||
this.sortOrder = sortOrder; | ||
} | ||
|
||
public void setSkip(int skip) { | ||
this.skip = skip; | ||
} | ||
|
||
public void setLimit(int limit) { | ||
this.limit = limit; | ||
} | ||
|
||
public void setStartTimestamp(int startTimestamp) { | ||
this.startTimestamp = startTimestamp; | ||
} | ||
|
||
public void setEndTimestamp(int endTimestamp) { | ||
this.endTimestamp = endTimestamp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.