mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-09 21:14:22 +00:00
feat(ui): add MongoDB Atlas provider support (#9253)
Co-authored-by: Alan Buscaglia <gentlemanprogramming@gmail.com>
This commit is contained in:
co-authored by
Alan Buscaglia
parent
6e135abaa0
commit
ed5f6b3af6
@@ -4,62 +4,6 @@ import { redirect } from "next/navigation";
|
||||
|
||||
import { apiBaseUrl, getAuthHeaders } from "@/lib";
|
||||
import { handleApiResponse } from "@/lib/server-actions-helper";
|
||||
import { FindingsResponse } from "@/types";
|
||||
|
||||
interface IncludedItem {
|
||||
type: string;
|
||||
id: string;
|
||||
attributes?: { provider?: string };
|
||||
relationships?: { provider?: { data?: { id: string } } };
|
||||
}
|
||||
|
||||
type FindingsApiResponse = FindingsResponse & {
|
||||
included?: IncludedItem[];
|
||||
};
|
||||
|
||||
const filterMongoFindings = <T extends FindingsApiResponse | null | undefined>(
|
||||
result: T,
|
||||
): T => {
|
||||
if (!result?.data) return result;
|
||||
|
||||
const included = (result as FindingsApiResponse).included || [];
|
||||
|
||||
// Get IDs of providers containing "mongo" in included items
|
||||
const mongoProviderIds = new Set(
|
||||
included
|
||||
.filter(
|
||||
(item) =>
|
||||
item.type === "providers" &&
|
||||
item.attributes?.provider?.toLowerCase().includes("mongo"),
|
||||
)
|
||||
.map((item) => item.id),
|
||||
);
|
||||
|
||||
// Filter out findings associated with mongo providers
|
||||
result.data = result.data.filter((finding) => {
|
||||
const scanId = finding.relationships?.scan?.data?.id;
|
||||
// Find the scan in included items
|
||||
const scan = included.find(
|
||||
(item) => item.type === "scans" && item.id === scanId,
|
||||
);
|
||||
const providerId = scan?.relationships?.provider?.data?.id;
|
||||
return !providerId || !mongoProviderIds.has(providerId);
|
||||
});
|
||||
|
||||
// Filter out mongo-related included items
|
||||
if ((result as FindingsApiResponse).included) {
|
||||
(result as FindingsApiResponse).included = included.filter(
|
||||
(item) =>
|
||||
!(
|
||||
item.type === "providers" &&
|
||||
item.attributes?.provider?.toLowerCase().includes("mongo")
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getFindings = async ({
|
||||
page = 1,
|
||||
pageSize = 10,
|
||||
@@ -89,9 +33,7 @@ export const getFindings = async ({
|
||||
headers,
|
||||
});
|
||||
|
||||
const result = await handleApiResponse(findings);
|
||||
|
||||
return filterMongoFindings(result);
|
||||
return handleApiResponse(findings);
|
||||
} catch (error) {
|
||||
console.error("Error fetching findings:", error);
|
||||
return undefined;
|
||||
@@ -129,9 +71,7 @@ export const getLatestFindings = async ({
|
||||
headers,
|
||||
});
|
||||
|
||||
const result = await handleApiResponse(findings);
|
||||
|
||||
return filterMongoFindings(result);
|
||||
return handleApiResponse(findings);
|
||||
} catch (error) {
|
||||
console.error("Error fetching findings:", error);
|
||||
return undefined;
|
||||
|
||||
@@ -28,8 +28,6 @@ interface AggregatedProvider {
|
||||
fail: number;
|
||||
}
|
||||
|
||||
const EXCLUDED_PROVIDERS = new Set(["mongo", "mongodb", "mongodbatlas"]);
|
||||
|
||||
// API can return multiple entries for the same provider type, so we sum their findings
|
||||
function aggregateProvidersByType(
|
||||
providers: ProviderOverview[],
|
||||
@@ -39,8 +37,6 @@ function aggregateProvidersByType(
|
||||
for (const provider of providers) {
|
||||
const { id, attributes } = provider;
|
||||
|
||||
if (EXCLUDED_PROVIDERS.has(id)) continue;
|
||||
|
||||
const existing = aggregated.get(id);
|
||||
|
||||
if (existing) {
|
||||
|
||||
@@ -39,26 +39,9 @@ export const getProviders = async ({
|
||||
headers,
|
||||
});
|
||||
|
||||
const result = (await handleApiResponse(response)) as
|
||||
return (await handleApiResponse(response)) as
|
||||
| ProvidersApiResponse
|
||||
| undefined;
|
||||
|
||||
if (result?.data) {
|
||||
// Filter out providers with provider type containing "mongo"
|
||||
result.data = result.data.filter(
|
||||
(provider) =>
|
||||
!provider.attributes?.provider?.toLowerCase().includes("mongo"),
|
||||
);
|
||||
|
||||
// Also filter out mongo-related included items if present
|
||||
if (result.included) {
|
||||
result.included = result.included.filter(
|
||||
(item) => !item.type.toLowerCase().includes("mongo"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Error fetching providers:", error);
|
||||
return undefined;
|
||||
|
||||
@@ -9,47 +9,6 @@ import {
|
||||
} from "@/lib/compliance/compliance-report-types";
|
||||
import { addScanOperation } from "@/lib/sentry-breadcrumbs";
|
||||
import { handleApiError, handleApiResponse } from "@/lib/server-actions-helper";
|
||||
import { ScansApiResponse } from "@/types";
|
||||
|
||||
const filterMongoScans = (result: ScansApiResponse | undefined) => {
|
||||
if (!result?.data) return result;
|
||||
|
||||
const included = result.included || [];
|
||||
|
||||
// Get IDs of providers containing "mongo"
|
||||
const mongoProviderIds = new Set(
|
||||
included
|
||||
.filter(
|
||||
(item) =>
|
||||
item.type === "providers" &&
|
||||
item.attributes?.provider?.toLowerCase().includes("mongo"),
|
||||
)
|
||||
.map((item) => item.id),
|
||||
);
|
||||
|
||||
// If no mongo providers found, return as-is
|
||||
if (mongoProviderIds.size === 0) return result;
|
||||
|
||||
// Filter out scans associated with mongo providers
|
||||
result.data = result.data.filter((scan) => {
|
||||
const providerId = scan.relationships?.provider?.data?.id;
|
||||
return !providerId || !mongoProviderIds.has(providerId);
|
||||
});
|
||||
|
||||
// Filter out mongo-related included items
|
||||
if (result.included) {
|
||||
result.included = included.filter(
|
||||
(item) =>
|
||||
!(
|
||||
item.type === "providers" &&
|
||||
item.attributes?.provider?.toLowerCase().includes("mongo")
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getScans = async ({
|
||||
page = 1,
|
||||
query = "",
|
||||
@@ -84,10 +43,7 @@ export const getScans = async ({
|
||||
try {
|
||||
const response = await fetch(url.toString(), { headers });
|
||||
|
||||
const result = await handleApiResponse(response);
|
||||
|
||||
// Filter out mongo-related scans when provider is included
|
||||
return filterMongoScans(result);
|
||||
return handleApiResponse(response);
|
||||
} catch (error) {
|
||||
console.error("Error fetching scans:", error);
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user