Skip to content

Commit

Permalink
Merge pull request #1486 from akto-api-security/feature/deactivate_co…
Browse files Browse the repository at this point in the history
…llection

Added deactivated collection tab
  • Loading branch information
notshivansh authored Sep 12, 2024
2 parents adb38da + a4b386c commit 596b461
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,19 @@ const transform = {
},

getCountInfo: (collectionsArr, coverageObject) => {
let urlsCount = 0 ;
let coverageCount = 0 ;
collectionsArr.forEach((x) =>{
let urlsCount = 0;
let coverageCount = 0;
collectionsArr.forEach((x) => {
if (x.hasOwnProperty('type') && x.type === 'API_GROUP') {
return
return;
}

urlsCount += x.urlsCount;
coverageCount += coverageObject[x.id] || 0 ;
})

// Only count active collections
if (!x.deactivated) {
urlsCount += x.urlsCount;
coverageCount += coverageObject[x.id] || 0;
}
});
return {
totalUrls: urlsCount,
coverage: urlsCount === 0 ? "0%" : Math.ceil((coverageCount * 100) / urlsCount) + '%'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const convertToNewData = (collectionsArr, sensitiveInfoMap, severityInfoMap, cov
sensitiveInRespTypes: sensitiveInfoMap[c.id] ? sensitiveInfoMap[c.id] : [],
severityInfo: severityInfoMap[c.id] ? severityInfoMap[c.id] : {},
detected: func.prettifyEpoch(trafficInfoMap[c.id] || 0),
detectedTimestamp : trafficInfoMap[c.id] || 0,
detectedTimestamp: trafficInfoMap[c.id] || 0,
riskScore: riskScoreMap[c.id] ? riskScoreMap[c.id] : 0,
discovered: func.prettifyEpoch(c.startTs || 0),
}
Expand Down Expand Up @@ -208,7 +208,7 @@ function ApiCollections() {

// const dummyData = dummyJson;

const definedTableTabs = ['All', 'Hostname', 'Groups', 'Custom']
const definedTableTabs = ['All', 'Hostname', 'Groups', 'Custom', 'Deactivated']

const { tabsInfo, selectItems } = useTable()
const tableCountObj = func.getTabsCount(definedTableTabs, data)
Expand Down Expand Up @@ -341,21 +341,26 @@ function ApiCollections() {

dataObj = convertToNewData(tmp, sensitiveInfo.sensitiveInfoMap, severityObj, coverageInfo, trafficInfo, riskScoreObj?.riskScoreMap, false);
setNormalData(dataObj.normal)

// Separate active and deactivated collections
const deactivatedCollections = dataObj.prettify.filter(c => c.deactivated);

// Calculate summary data only for active collections
const summary = transform.getSummaryData(dataObj.normal)
summary.totalCriticalEndpoints = riskScoreObj.criticalUrls;
summary.totalSensitiveEndpoints = sensitiveInfo.sensitiveUrls
setSummaryData(summary)


setCollectionsMap(func.mapCollectionIdToName(tmp))
const allHostNameMap = func.mapCollectionIdToHostName(tmp)
setHostNameMap(allHostNameMap)

tmp = {}
tmp.all = dataObj.prettify
tmp.hostname = dataObj.prettify.filter((c) => c.hostName !== null && c.hostName !== undefined)
tmp.groups = dataObj.prettify.filter((c) => c.type === "API_GROUP")
tmp.custom = tmp.all.filter(x => !tmp.hostname.includes(x) && !tmp.groups.includes(x));
tmp.custom = tmp.all.filter(x => !tmp.hostname.includes(x) && !x.deactivated && !tmp.groups.includes(x));
tmp.deactivated = deactivatedCollections

setData(tmp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ const transform = {
if (c.hasOwnProperty('type') && c.type === 'API_GROUP') {
return
}

if (c.deactivated) {
return
}
totalUrl += c.urlsCount ;
totalTested += c.testedEndpoints;
})
Expand Down

0 comments on commit 596b461

Please sign in to comment.