mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-09 21:14:22 +00:00
feat: Scan on demand can be executed now from the UI
This commit is contained in:
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { parseStringify } from "@/lib";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
|
||||
export const getProviders = async ({
|
||||
page = 1,
|
||||
@@ -198,18 +198,3 @@ export const deleteProvider = async (formData: FormData) => {
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const getErrorMessage = async (error: unknown): Promise<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;
|
||||
};
|
||||
|
||||
+49
-1
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { parseStringify } from "@/lib";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
|
||||
export const getScans = async ({
|
||||
page = 1,
|
||||
@@ -46,3 +46,51 @@ export const getScans = async ({
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const scanOnDemand = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const providerId = formData.get("providerId");
|
||||
const scanName = formData.get("scanName");
|
||||
|
||||
const url = new URL(`${keyServer}/scans`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/vnd.api+json",
|
||||
Accept: "application/vnd.api+json",
|
||||
Authorization: `Bearer ${session?.accessToken}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
type: "Scan",
|
||||
attributes: {
|
||||
name: scanName,
|
||||
scanner_args: {
|
||||
checks_to_execute: ["accessanalyzer_enabled"],
|
||||
},
|
||||
},
|
||||
relationships: {
|
||||
provider: {
|
||||
data: {
|
||||
type: "Provider",
|
||||
id: providerId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
const data = await response.json();
|
||||
revalidatePath("/scans");
|
||||
return parseStringify(data);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return {
|
||||
error: getErrorMessage(error),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user