Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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 @@ -10,6 +10,7 @@ public class ThreatConfiguration {

private Actor actor;
private RatelimitConfig ratelimitConfig;
private Integer archivalDays;

@lombok.Getter
@lombok.Setter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { useState, useEffect } from "react";
import func from "@/util/func"
import { LegacyCard, VerticalStack, Divider, Text, Button, Box } from "@shopify/polaris";
import api from "../../../pages/threat_detection/api.js";
import Dropdown from "../../../components/layouts/Dropdown.jsx";

const ArchivalConfigComponent = ({ title, description }) => {
const [archivalDays, setArchivalDays] = useState(60);
const [isSaveDisabled, setIsSaveDisabled] = useState(true);

const fetchData = async () => {
const response = await api.fetchThreatConfiguration();
const days = response?.threatConfiguration?.archivalDays;
const value = days === 30 || days === 60 || days === 90 ? days : 60;
setArchivalDays(value);
setIsSaveDisabled(true);
};

const onSave = async () => {
const payload = {
archivalDays: archivalDays
};
await api.modifyThreatConfiguration(payload).then(() => {
try {
func.setToast(true, false, "Archival time saved successfully");
fetchData()
} catch (error) {
func.setToast(true, true, "Error saving archival time");
}
});
};

useEffect(() => {
fetchData();
}, []);

const options = [
{ value: 30, label: "30 days" },
{ value: 60, label: "60 days" },
{ value: 90, label: "90 days" },
];

function TitleComponent({ title, description }) {
return (
<Box paddingBlockEnd="4">
<Text variant="headingMd">{title}</Text>
<Box paddingBlockStart="2">
<Text variant="bodyMd">{description}</Text>
</Box>
</Box>
)
}

const onChange = (val) => {
setArchivalDays(val);
setIsSaveDisabled(false);
};

return (
<LegacyCard title={<TitleComponent title={title} description={description} />}
primaryFooterAction={{
content: 'Save',
onAction: onSave,
loading: false,
disabled: isSaveDisabled
}}
>
<Divider />
<LegacyCard.Section>
<VerticalStack gap="4">
<Box width="200px">
<Dropdown
menuItems={options}
selected={(val) => onChange(val)}
label="Archival Time"
initial={() => archivalDays}
/>
</Box>
</VerticalStack>
</LegacyCard.Section>
</LegacyCard>
);
};

export default ArchivalConfigComponent;


Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PageWithMultipleCards from "../../../components/layouts/PageWithMultipleCards"
import ThreatActorConfigComponent from "./ThreatActorConfig.jsx"
import RatelimitConfigComponent from "./RatelimitConfigComponent.jsx"
import ArchivalConfigComponent from "./ArchivalConfigComponent.jsx"

function ThreatConfiguration() {

Expand All @@ -14,6 +15,11 @@ function ThreatConfiguration() {
title={"Rate Limit Configuration"}
description={"Configure rate limiting rules to protect your APIs from abuse."}
key={"ratelimitConfig"}
/>,
<ArchivalConfigComponent
title={"Archival Configuration"}
description={"Choose how long to retain malicious events before archival."}
key={"archivalConfig"}
/>
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.akto.threat.backend.service.ThreatActorService;
import com.akto.threat.backend.service.ThreatApiService;
import com.akto.threat.backend.tasks.FlushMessagesToDB;
import com.akto.threat.backend.cron.ArchiveOldMaliciousEventsCron;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.ReadPreference;
Expand Down Expand Up @@ -73,6 +74,14 @@ public static void main(String[] args) throws Exception {
ApiDistributionDataService apiDistributionDataService = new ApiDistributionDataService(threatProtectionMongo);

new BackendVerticle(maliciousEventService, threatActorService, threatApiService, apiDistributionDataService).start();

try {
logger.infoAndAddToDb("Starting ArchiveOldMaliciousEventsCron for all databases", LoggerMaker.LogDb.RUNTIME);
new ArchiveOldMaliciousEventsCron(threatProtectionMongo).cron();
logger.infoAndAddToDb("Scheduled ArchiveOldMaliciousEventsCron", LoggerMaker.LogDb.RUNTIME);
} catch (Exception e) {
logger.errorAndAddToDb("Error starting ArchiveOldMaliciousEventsCron: " + e.getMessage(), LoggerMaker.LogDb.RUNTIME);
}
}

}
Loading