mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-11-09 12:49:27 +00:00
Merge branch 'master' into PRWLR-7160-findings-page-scan-id-filter-improvement
# Conflicts: # ui/CHANGELOG.md # ui/app/(prowler)/findings/page.tsx # ui/components/ui/custom/custom-dropdown-filter.tsx # ui/types/filters.ts
This commit is contained in:
commit
97d216c49f
126 files changed
+35995
-710
No files matched your search
@@ -10,6 +10,7 @@ import {
|
||||
parseStringify,
|
||||
wait,
|
||||
} from "@/lib";
|
||||
import { ProvidersApiResponse } from "@/types/providers";
|
||||
|
||||
export const getProviders = async ({
|
||||
page = 1,
|
||||
@@ -17,7 +18,7 @@ export const getProviders = async ({
|
||||
sort = "",
|
||||
filters = {},
|
||||
pageSize = 10,
|
||||
}) => {
|
||||
}): Promise<ProvidersApiResponse | undefined> => {
|
||||
const headers = await getAuthHeaders({ contentType: false });
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/providers");
|
||||
|
||||
@@ -238,10 +238,23 @@ export const getExportsZip = async (scanId: string) => {
|
||||
headers,
|
||||
});
|
||||
|
||||
if (response.status === 202) {
|
||||
const json = await response.json();
|
||||
const taskId = json?.data?.id;
|
||||
const state = json?.data?.attributes?.state;
|
||||
return {
|
||||
pending: true,
|
||||
state,
|
||||
taskId,
|
||||
};
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
|
||||
throw new Error(
|
||||
errorData?.errors?.[0]?.detail || "Failed to fetch report",
|
||||
errorData?.errors?.detail ||
|
||||
"Unable to fetch scan report. Contact support if the issue continues.",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -273,20 +286,28 @@ export const getComplianceCsv = async (
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
headers,
|
||||
});
|
||||
const response = await fetch(url.toString(), { headers });
|
||||
|
||||
if (response.status === 202) {
|
||||
const json = await response.json();
|
||||
const taskId = json?.data?.id;
|
||||
const state = json?.data?.attributes?.state;
|
||||
return {
|
||||
pending: true,
|
||||
state,
|
||||
taskId,
|
||||
};
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(
|
||||
errorData?.errors?.[0]?.detail || "Failed to fetch compliance report",
|
||||
errorData?.errors?.detail ||
|
||||
"Unable to retrieve compliance report. Contact support if the issue continues.",
|
||||
);
|
||||
}
|
||||
|
||||
// Get the blob data as an array buffer
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
// Convert to base64
|
||||
const base64 = Buffer.from(arrayBuffer).toString("base64");
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
|
||||
import { apiBaseUrl, getAuthHeaders, parseStringify } from "@/lib/helper";
|
||||
|
||||
@@ -26,3 +29,67 @@ export const getAllTenants = async () => {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const editTenantFormSchema = z
|
||||
.object({
|
||||
tenantId: z.string(),
|
||||
name: z.string().trim().min(1, { message: "Name is required" }),
|
||||
currentName: z.string(),
|
||||
})
|
||||
.refine((data) => data.name !== data.currentName, {
|
||||
message: "Name must be different from the current name",
|
||||
path: ["name"],
|
||||
});
|
||||
|
||||
export async function updateTenantName(prevState: any, formData: FormData) {
|
||||
const headers = await getAuthHeaders({ contentType: true });
|
||||
const formDataObject = Object.fromEntries(formData);
|
||||
const validatedData = editTenantFormSchema.safeParse(formDataObject);
|
||||
|
||||
if (!validatedData.success) {
|
||||
const formFieldErrors = validatedData.error.flatten().fieldErrors;
|
||||
|
||||
return {
|
||||
errors: {
|
||||
name: formFieldErrors?.name?.[0],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const { tenantId, name } = validatedData.data;
|
||||
|
||||
const payload = {
|
||||
data: {
|
||||
type: "tenants",
|
||||
id: tenantId,
|
||||
attributes: {
|
||||
name: name.trim(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
const url = new URL(`${apiBaseUrl}/tenants/${tenantId}`);
|
||||
const response = await fetch(url.toString(), {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to update tenant name: ${response.statusText}`);
|
||||
}
|
||||
|
||||
await response.json();
|
||||
revalidatePath("/profile");
|
||||
return { success: "Tenant name updated successfully!" };
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Error updating tenant name:", error);
|
||||
return {
|
||||
errors: {
|
||||
general: "Error updating tenant name. Please try again.",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user