mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 21:11:53 +00:00
Merge branch 'main' into PRWLR-5141-Prowler-V-release-tweaks-scan-page-v3
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { parseStringify } from "@/lib";
|
||||
|
||||
export const getService = async ({ page = 1 }) => {
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/services");
|
||||
const keyServer = process.env.SITE_URL;
|
||||
|
||||
try {
|
||||
const services = await fetch(
|
||||
`${keyServer}/api/services?page%5Bnumber%5D=${page}`,
|
||||
);
|
||||
const data = await services.json();
|
||||
const parsedData = parseStringify(data);
|
||||
revalidatePath("/services");
|
||||
return parsedData;
|
||||
} catch (error) {
|
||||
console.error("Error fetching services:", error);
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const getErrorMessage = (error: unknown): string => {
|
||||
let message: string;
|
||||
|
||||
if (error instanceof Error) {
|
||||
message = error.message;
|
||||
} else if (error && typeof error === "object" && "message" in error) {
|
||||
message = String(error.message);
|
||||
} else if (typeof error === "string") {
|
||||
message = error;
|
||||
} else {
|
||||
message = "Oops! Something went wrong.";
|
||||
}
|
||||
return message;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./services";
|
||||
@@ -0,0 +1,101 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
import { parse } from "path";
|
||||
|
||||
export const getServices = async ({}) => {
|
||||
const session = await auth();
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const servicesToFetch = [
|
||||
{ id: "accessanalyzer", alias: "IAM Access Analyzer" },
|
||||
{ id: "account", alias: "AWS Account" },
|
||||
{ id: "acm", alias: "AWS Certificate Manager" },
|
||||
{ id: "apigateway", alias: "Amazon API Gateway" },
|
||||
{ id: "apigatewayv2", alias: "Amazon API Gateway V2" },
|
||||
{ id: "athena", alias: "Amazon Athena" },
|
||||
{ id: "autoscaling", alias: "Amazon EC2 Auto Scaling" },
|
||||
{ id: "awslambda", alias: "AWS Lambda" },
|
||||
{ id: "backup", alias: "AWS Backup" },
|
||||
{ id: "cloudformation", alias: "AWS CloudFormation" },
|
||||
{ id: "cloudfront", alias: "Amazon CloudFront" },
|
||||
{ id: "cloudtrail", alias: "AWS CloudTrail" },
|
||||
{ id: "cloudwatch", alias: "Amazon CloudWatch" },
|
||||
{ id: "codeartifact", alias: "AWS CodeArtifact" },
|
||||
{ id: "codebuild", alias: "AWS CodeBuild" },
|
||||
{ id: "config", alias: "AWS Config" },
|
||||
{ id: "dlm", alias: "Amazon Data Lifecycle Manager" },
|
||||
{ id: "drs", alias: "AWS Data Replication Service" },
|
||||
{ id: "dynamodb", alias: "Amazon DynamoDB" },
|
||||
{ id: "ec2", alias: "Amazon EC2" },
|
||||
{ id: "ecr", alias: "Amazon ECR" },
|
||||
{ id: "ecs", alias: "Amazon ECS" },
|
||||
{ id: "efs", alias: "Amazon EFS" },
|
||||
{ id: "eks", alias: "Amazon EKS" },
|
||||
{ id: "elasticache", alias: "Amazon ElastiCache" },
|
||||
{ id: "elb", alias: "Elastic Load Balancing" },
|
||||
{ id: "elbv2", alias: "Elastic Load Balancing v2" },
|
||||
{ id: "emr", alias: "Amazon EMR" },
|
||||
{ id: "fms", alias: "AWS Firewall Manager" },
|
||||
{ id: "glacier", alias: "Amazon Glacier" },
|
||||
{ id: "glue", alias: "AWS Glue" },
|
||||
{ id: "guardduty", alias: "Amazon GuardDuty" },
|
||||
{ id: "iam", alias: "AWS IAM" },
|
||||
{ id: "inspector2", alias: "Amazon Inspector" },
|
||||
{ id: "kms", alias: "AWS KMS" },
|
||||
{ id: "macie", alias: "Amazon Macie" },
|
||||
{ id: "networkfirewall", alias: "AWS Network Firewall" },
|
||||
{ id: "organizations", alias: "AWS Organizations" },
|
||||
{ id: "rds", alias: "Amazon RDS" },
|
||||
{ id: "resourceexplorer2", alias: "AWS Resource Groups" },
|
||||
{ id: "route53", alias: "Amazon Route 53" },
|
||||
{ id: "s3", alias: "Amazon S3" },
|
||||
{ id: "secretsmanager", alias: "AWS Secrets Manager" },
|
||||
{ id: "securityhub", alias: "AWS Security Hub" },
|
||||
{ id: "sns", alias: "Amazon SNS" },
|
||||
{ id: "sqs", alias: "Amazon SQS" },
|
||||
{ id: "ssm", alias: "AWS Systems Manager" },
|
||||
{ id: "ssmincidents", alias: "AWS Systems Manager Incident Manager" },
|
||||
{ id: "trustedadvisor", alias: "AWS Trusted Advisor" },
|
||||
{ id: "vpc", alias: "Amazon VPC" },
|
||||
{ id: "wafv2", alias: "AWS WAF" },
|
||||
{ id: "wellarchitected", alias: "AWS Well-Architected Tool" }
|
||||
];
|
||||
|
||||
|
||||
|
||||
const parsedData = [];
|
||||
|
||||
for (const service of servicesToFetch) {
|
||||
const url = new URL(`${keyServer}/findings`);
|
||||
url.searchParams.append("filter[service]", service.id);
|
||||
url.searchParams.append("filter[status]", "FAIL");
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
headers: {
|
||||
Accept: "application/vnd.api+json",
|
||||
Authorization: `Bearer ${session?.accessToken}`,
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
const failFindings = data.meta.pagination.count;
|
||||
|
||||
parsedData.push({
|
||||
service_id: service.id,
|
||||
service_alias: service.alias,
|
||||
fail_findings: failFindings,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error fetching data for service ${service.id}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath("/services");
|
||||
return parsedData;
|
||||
};
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Spacer } from "@nextui-org/react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Suspense } from "react";
|
||||
|
||||
import { getService } from "@/actions/services";
|
||||
import { getServices } from "@/actions/services";
|
||||
import { FilterControls } from "@/components/filters";
|
||||
import { ServiceCard, ServiceSkeletonGrid } from "@/components/services";
|
||||
import { Header } from "@/components/ui";
|
||||
@@ -35,19 +34,16 @@ const SSRServiceGrid = async ({
|
||||
}: {
|
||||
searchParams: SearchParamsProps;
|
||||
}) => {
|
||||
const page = parseInt(searchParams.page?.toString() || "1", 10);
|
||||
const servicesData = await getService({ page });
|
||||
const servicesData = await getServices(searchParams);
|
||||
const [services] = await Promise.all([servicesData]);
|
||||
|
||||
if (services?.errors) redirect("/services");
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||
{services.services?.data.map((service: any) => (
|
||||
{services?.map((service: any) => (
|
||||
<ServiceCard
|
||||
key={service.id}
|
||||
fidingsFailed={service.attributes.findings.failed}
|
||||
serviceAlias={service.attributes.alias}
|
||||
key={service.service_id}
|
||||
fidingsFailed={service.fail_findings}
|
||||
serviceAlias={service.service_alias}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -4,8 +4,10 @@ import { ColumnDef } from "@tanstack/react-table";
|
||||
|
||||
import { SeverityBadge, Status, StatusBadge } from "@/components/ui/table";
|
||||
import { FindingProps } from "@/types";
|
||||
|
||||
import { TriggerSheet } from "@/components/ui/sheet";
|
||||
import { DataTableRowActions } from "./data-table-row-actions";
|
||||
import { PlusIcon } from "@/components/icons";
|
||||
import { DataTableRowDetails } from "@/components/findings/table";
|
||||
|
||||
const statusMap: Record<"PASS" | "FAIL" | "MANUAL" | "MUTED", Status> = {
|
||||
PASS: "completed",
|
||||
@@ -133,6 +135,21 @@ export const ColumnFindings: ColumnDef<FindingProps>[] = [
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "moreInfo",
|
||||
header: "Details",
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<TriggerSheet
|
||||
triggerComponent={<PlusIcon />}
|
||||
title="Finding Details"
|
||||
description="View the finding details"
|
||||
>
|
||||
<DataTableRowDetails finding={getFindingsData(row)} />
|
||||
</TriggerSheet>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
cell: ({ row }) => {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { FindingDetail } from "@/components/findings/table";
|
||||
import { FindingProps } from "@/types";
|
||||
|
||||
export const DataTableRowDetails = ({ finding }: { finding: FindingProps }) => {
|
||||
console.log(finding);
|
||||
return <FindingDetail findingDetails={finding} />;
|
||||
};
|
||||
@@ -0,0 +1,97 @@
|
||||
"use client";
|
||||
|
||||
import { Card, CardBody, CardHeader, Divider } from "@nextui-org/react";
|
||||
|
||||
import { DateWithTime, SnippetId } from "@/components/ui/entities";
|
||||
import { StatusBadge } from "@/components/ui/table/status-badge";
|
||||
import { FindingProps } from "@/types";
|
||||
import {Table, TableHeader, TableColumn, TableBody, TableRow, TableCell} from "@nextui-org/react";
|
||||
|
||||
export const FindingDetail = ({ findingDetails }: { findingDetails: FindingProps }) => {
|
||||
const finding = findingDetails;
|
||||
console.log(finding)
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
|
||||
<Table aria-label="Example static collection table">
|
||||
<TableHeader>
|
||||
<TableColumn>Name </TableColumn>
|
||||
<TableColumn>Value</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow key="1">
|
||||
<TableCell>Resource ID</TableCell>
|
||||
<TableCell>{finding.relationships.resource.id}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="2">
|
||||
<TableCell>Resource ARN</TableCell>
|
||||
<TableCell>{finding.relationships.resource.attributes.uid}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="3">
|
||||
<TableCell>Check ID</TableCell>
|
||||
<TableCell>{finding.attributes.check_id}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="4">
|
||||
<TableCell>Types</TableCell>
|
||||
<TableCell>{finding.attributes.check_metadata.checktype}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="5">
|
||||
<TableCell>Scan time</TableCell>
|
||||
<TableCell>{finding.attributes.inserted_at}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="6">
|
||||
<TableCell>Prowler Finding ID</TableCell>
|
||||
<TableCell>{finding.relationships.resource.attributes.uid}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="7">
|
||||
<TableCell>Severity</TableCell>
|
||||
<TableCell>{finding.id}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="8">
|
||||
<TableCell>Status</TableCell>
|
||||
<TableCell>{finding.attributes.status}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="9">
|
||||
<TableCell>Region</TableCell>
|
||||
<TableCell>{finding.relationships.resource.attributes.region}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="10">
|
||||
<TableCell>Service</TableCell>
|
||||
<TableCell>{finding.relationships.resource.attributes.service}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="11">
|
||||
<TableCell>Account</TableCell>
|
||||
<TableCell>{finding.relationships.provider.attributes.uid}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="12">
|
||||
<TableCell>Details</TableCell>
|
||||
<TableCell>{finding.attributes.status_extended}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="13">
|
||||
<TableCell>Risk</TableCell>
|
||||
<TableCell>{finding.attributes.check_metadata.risk}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="14">
|
||||
<TableCell>Recommendation</TableCell>
|
||||
<TableCell>{finding.attributes.check_metadata.remediation.recommendation.text}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="15">
|
||||
<TableCell>CLI</TableCell>
|
||||
<TableCell>{finding.attributes.check_metadata.remediation.code.cli}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="16">
|
||||
<TableCell>Other</TableCell>
|
||||
<TableCell>{finding.attributes.check_metadata.remediation.code.other}</TableCell>
|
||||
</TableRow>
|
||||
<TableRow key="17">
|
||||
<TableCell>Terraform</TableCell>
|
||||
<TableCell>{finding.attributes.check_metadata.remediation.code.terraform}</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,3 +1,5 @@
|
||||
export * from "./column-findings";
|
||||
export * from "./data-table-row-actions";
|
||||
export * from "./data-table-row-details";
|
||||
export * from "./skeleton-table-findings";
|
||||
export * from "./finding-detail";
|
||||
|
||||
@@ -20,7 +20,7 @@ export const ServiceCard: React.FC<CardServiceProps> = ({
|
||||
<small className="text-default-500">
|
||||
{fidingsFailed > 0
|
||||
? `${fidingsFailed} Failed Findings`
|
||||
: "All findings passed"}
|
||||
: "No failed findings"}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
@@ -39,7 +39,7 @@ export const ServiceCard: React.FC<CardServiceProps> = ({
|
||||
radius="full"
|
||||
size="md"
|
||||
>
|
||||
{fidingsFailed > 0 ? fidingsFailed : "All passed"}
|
||||
{fidingsFailed > 0 ? fidingsFailed : ""}
|
||||
</Chip>
|
||||
</CardBody>
|
||||
</Card>
|
||||
|
||||
@@ -247,6 +247,7 @@ export interface FindingProps {
|
||||
type: "Resource";
|
||||
id: string;
|
||||
}[];
|
||||
id: string;
|
||||
attributes: {
|
||||
uid: string;
|
||||
name: string;
|
||||
|
||||
Reference in New Issue
Block a user