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

Hotfix/security posture bugs #1519

Merged
merged 8 commits into from
Sep 19, 2024
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 @@ -2341,7 +2341,7 @@ private static void backFillDiscovered() {
do {
Map<ApiInfo.ApiInfoKey, ApiInfo> apiInfoMap = new HashMap<>();
Bson idFilter = id == null ? Filters.empty() : Filters.gt("_id", id);
singleTypeInfos = SingleTypeInfoDao.instance.findAll(Filters.gt("_id", idFilter), 0, 100_000, sort, Projections.include(SingleTypeInfo._TIMESTAMP, SingleTypeInfo._URL, SingleTypeInfo._API_COLLECTION_ID, SingleTypeInfo._METHOD));
singleTypeInfos = SingleTypeInfoDao.instance.findAll(idFilter, 0, 100_000, sort, Projections.include(SingleTypeInfo._TIMESTAMP, SingleTypeInfo._URL, SingleTypeInfo._API_COLLECTION_ID, SingleTypeInfo._METHOD));
for (SingleTypeInfo singleTypeInfo: singleTypeInfos) {
id = singleTypeInfo.getId();
ApiInfo.ApiInfoKey apiInfoKey = new ApiInfo.ApiInfoKey(singleTypeInfo.getApiCollectionId(), singleTypeInfo.getUrl(), Method.fromString(singleTypeInfo.getMethod()));
Expand All @@ -2356,7 +2356,21 @@ private static void backFillDiscovered() {
for (ApiInfo apiInfo: apiInfoMap.values()) {
updates.add(
new UpdateOneModel<>(
ApiInfoDao.getFilter(apiInfo.getId()),
Filters.and(
ApiInfoDao.getFilter(apiInfo.getId()),
Filters.exists(ApiInfo.DISCOVERED_TIMESTAMP, false)
),
Updates.set(ApiInfo.DISCOVERED_TIMESTAMP, apiInfo.getDiscoveredTimestamp()),
new UpdateOptions().upsert(false)
)
);

updates.add(
new UpdateOneModel<>(
Filters.and(
ApiInfoDao.getFilter(apiInfo.getId()),
Filters.exists(ApiInfo.DISCOVERED_TIMESTAMP, true)
),
Updates.min(ApiInfo.DISCOVERED_TIMESTAMP, apiInfo.getDiscoveredTimestamp()),
new UpdateOptions().upsert(false)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import SmoothAreaChart from './new_components/SmoothChart'
import DateRangeFilter from '../../components/layouts/DateRangeFilter';
import { produce } from 'immer';
import EmptyCard from './new_components/EmptyCard';
import TooltipText from '../../components/shared/TooltipText';
import transform from '../observe/transform';

function HomeDashboard() {

Expand Down Expand Up @@ -378,15 +380,19 @@ function HomeDashboard() {
Object.keys(apiStats.riskScoreMap).forEach((key) => {
const badgeIndex = 5 - parseInt(key, 10);
const value = apiStats.riskScoreMap[key];
result[badgeIndex].text = value;
result[badgeIndex].progressValue = `${((value / totalApisCount) * 100).toFixed(2)}%`;
result[badgeIndex].text = value ? value : 0;
if (!totalApisCount || totalApisCount === 0) {
result[badgeIndex].progressValue = `0%`;
} else {
result[badgeIndex].progressValue = `${((value / totalApisCount) * 100).toFixed(2)}%`;
}
});

setRiskScoreData(result)
}

function getCollectionsWithCoverage() {
const validCollections = allCollections.filter(collection => collection.hostName !== null && collection.hostName !== undefined);
const validCollections = allCollections.filter(collection => collection.hostName !== null && collection.hostName !== undefined && !collection.deactivated);

const sortedCollections = validCollections.sort((a, b) => b.startTs - a.startTs);

Expand All @@ -405,7 +411,7 @@ function HomeDashboard() {
const summaryInfo = [
{
title: 'Total APIs',
data: totalAPIs,
data: transform.formatNumberWithCommas(totalAPIs),
variant: 'heading2xl',
byLineComponent: generateByLineComponent((totalAPIs - oldTotalApis), func.timeDifference(startTimestamp, endTimestamp)),
smoothChartComponent: (<SmoothAreaChart tickPositions={[oldTotalApis, totalAPIs]} />)
Expand Down Expand Up @@ -507,8 +513,10 @@ function HomeDashboard() {
return collections.map((collection, index) => ([
<HorizontalStack align='space-between'>
<HorizontalStack gap={2}>
<Text>{collection.name}</Text>
<Text color='subdued'>{Math.floor(100.0 * collection.apisTested / collection.totalApis)}% test coverage</Text>
<Box maxWidth='287px'>
<TooltipText tooltip={collection.name} text={collection.name}/>
</Box>
<Text variant='bodySm' color='subdued'>{(collection.totalApis === 0 ? 0 : Math.floor(100.0 * collection.apisTested / collection.totalApis))}% test coverage</Text>
</HorizontalStack>
<Text>{collection.totalApis}</Text>
</HorizontalStack>
Expand Down
Loading