mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-04 19:21:51 +00:00
chore: Rename keyServer and extract to helper (#7256)
This commit is contained in:
@@ -4,6 +4,7 @@ import { AuthError } from "next-auth";
|
||||
import { z } from "zod";
|
||||
|
||||
import { signIn, signOut } from "@/auth.config";
|
||||
import { apiBaseUrl } from "@/lib";
|
||||
import { authFormSchema } from "@/types";
|
||||
|
||||
const formSchemaSignIn = authFormSchema("sign-in");
|
||||
@@ -57,8 +58,7 @@ export async function authenticate(
|
||||
export const createNewUser = async (
|
||||
formData: z.infer<typeof formSchemaSignUp>,
|
||||
) => {
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/users`);
|
||||
const url = new URL(`${apiBaseUrl}/users`);
|
||||
|
||||
if (formData.invitationToken) {
|
||||
url.searchParams.append("invitation_token", formData.invitationToken);
|
||||
@@ -105,8 +105,7 @@ export const createNewUser = async (
|
||||
};
|
||||
|
||||
export const getToken = async (formData: z.infer<typeof formSchemaSignIn>) => {
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/tokens`);
|
||||
const url = new URL(`${apiBaseUrl}/tokens`);
|
||||
|
||||
const bodyData = {
|
||||
data: {
|
||||
@@ -144,8 +143,7 @@ export const getToken = async (formData: z.infer<typeof formSchemaSignIn>) => {
|
||||
};
|
||||
|
||||
export const getUserByMe = async (accessToken: string) => {
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/users/me`);
|
||||
const url = new URL(`${apiBaseUrl}/users/me`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, parseStringify } from "@/lib";
|
||||
|
||||
export const getCompliancesOverview = async ({
|
||||
scanId,
|
||||
@@ -15,8 +15,7 @@ export const getCompliancesOverview = async ({
|
||||
}) => {
|
||||
const session = await auth();
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/compliance-overviews`);
|
||||
const url = new URL(`${apiBaseUrl}/compliance-overviews`);
|
||||
|
||||
if (scanId) url.searchParams.append("filter[scan_id]", scanId);
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, parseStringify } from "@/lib";
|
||||
|
||||
export const getFindings = async ({
|
||||
page = 1,
|
||||
@@ -18,8 +18,7 @@ export const getFindings = async ({
|
||||
if (isNaN(Number(page)) || page < 1)
|
||||
redirect("findings?include=resources,scan.provider");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/findings?include=resources,scan.provider`);
|
||||
const url = new URL(`${apiBaseUrl}/findings?include=resources,scan.provider`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (pageSize) url.searchParams.append("page[size]", pageSize.toString());
|
||||
@@ -56,8 +55,7 @@ export const getMetadataInfo = async ({
|
||||
}) => {
|
||||
const session = await auth();
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/findings/metadata`);
|
||||
const url = new URL(`${apiBaseUrl}/findings/metadata`);
|
||||
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
if (sort) url.searchParams.append("sort", sort);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, getErrorMessage, parseStringify } from "@/lib";
|
||||
|
||||
export const getInvitations = async ({
|
||||
page = 1,
|
||||
@@ -16,8 +16,7 @@ export const getInvitations = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/invitations");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/tenants/invitations`);
|
||||
const url = new URL(`${apiBaseUrl}/tenants/invitations`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
@@ -50,11 +49,10 @@ export const getInvitations = async ({
|
||||
|
||||
export const sendInvite = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const email = formData.get("email");
|
||||
const role = formData.get("role");
|
||||
const url = new URL(`${keyServer}/tenants/invitations`);
|
||||
const url = new URL(`${apiBaseUrl}/tenants/invitations`);
|
||||
|
||||
const body = JSON.stringify({
|
||||
data: {
|
||||
@@ -99,7 +97,6 @@ export const sendInvite = async (formData: FormData) => {
|
||||
|
||||
export const updateInvite = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const invitationId = formData.get("invitationId");
|
||||
const invitationEmail = formData.get("invitationEmail");
|
||||
@@ -108,7 +105,7 @@ export const updateInvite = async (formData: FormData) => {
|
||||
formData.get("expires_at") ||
|
||||
new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString();
|
||||
|
||||
const url = new URL(`${keyServer}/tenants/invitations/${invitationId}`);
|
||||
const url = new URL(`${apiBaseUrl}/tenants/invitations/${invitationId}`);
|
||||
|
||||
const body: any = {
|
||||
data: {
|
||||
@@ -165,8 +162,7 @@ export const updateInvite = async (formData: FormData) => {
|
||||
|
||||
export const getInvitationInfoById = async (invitationId: string) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/tenants/invitations/${invitationId}`);
|
||||
const url = new URL(`${apiBaseUrl}/tenants/invitations/${invitationId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -188,14 +184,13 @@ export const getInvitationInfoById = async (invitationId: string) => {
|
||||
|
||||
export const revokeInvite = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const invitationId = formData.get("invitationId");
|
||||
|
||||
if (!invitationId) {
|
||||
return { error: "Invitation ID is required" };
|
||||
}
|
||||
|
||||
const url = new URL(`${keyServer}/tenants/invitations/${invitationId}`);
|
||||
const url = new URL(`${apiBaseUrl}/tenants/invitations/${invitationId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, getErrorMessage, parseStringify } from "@/lib";
|
||||
import { ManageGroupPayload, ProviderGroupsResponse } from "@/types/components";
|
||||
|
||||
export const getProviderGroups = async ({
|
||||
@@ -22,8 +22,7 @@ export const getProviderGroups = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/manage-groups");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/provider-groups`);
|
||||
const url = new URL(`${apiBaseUrl}/provider-groups`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
@@ -61,8 +60,7 @@ export const getProviderGroups = async ({
|
||||
|
||||
export const getProviderGroupInfoById = async (providerGroupId: string) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/provider-groups/${providerGroupId}`);
|
||||
const url = new URL(`${apiBaseUrl}/provider-groups/${providerGroupId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -90,7 +88,6 @@ export const getProviderGroupInfoById = async (providerGroupId: string) => {
|
||||
|
||||
export const createProviderGroup = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const name = formData.get("name") as string;
|
||||
const providersJson = formData.get("providers") as string;
|
||||
@@ -127,7 +124,7 @@ export const createProviderGroup = async (formData: FormData) => {
|
||||
const body = JSON.stringify(payload);
|
||||
|
||||
try {
|
||||
const url = new URL(`${keyServer}/provider-groups`);
|
||||
const url = new URL(`${apiBaseUrl}/provider-groups`);
|
||||
const response = await fetch(url.toString(), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -152,7 +149,6 @@ export const updateProviderGroup = async (
|
||||
formData: FormData,
|
||||
) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const name = formData.get("name") as string;
|
||||
const providersJson = formData.get("providers") as string;
|
||||
@@ -180,7 +176,7 @@ export const updateProviderGroup = async (
|
||||
}
|
||||
|
||||
try {
|
||||
const url = `${keyServer}/provider-groups/${providerGroupId}`;
|
||||
const url = `${apiBaseUrl}/provider-groups/${providerGroupId}`;
|
||||
const response = await fetch(url, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
@@ -209,14 +205,13 @@ export const updateProviderGroup = async (
|
||||
|
||||
export const deleteProviderGroup = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const providerGroupId = formData.get("id");
|
||||
|
||||
if (!providerGroupId) {
|
||||
return { error: "Provider Group ID is required" };
|
||||
}
|
||||
|
||||
const url = new URL(`${keyServer}/provider-groups/${providerGroupId}`);
|
||||
const url = new URL(`${apiBaseUrl}/provider-groups/${providerGroupId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, parseStringify } from "@/lib";
|
||||
|
||||
export const getProvidersOverview = async ({
|
||||
page = 1,
|
||||
@@ -15,8 +15,7 @@ export const getProvidersOverview = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/providers-overview");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/overviews/providers`);
|
||||
const url = new URL(`${apiBaseUrl}/overviews/providers`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
@@ -58,8 +57,7 @@ export const getFindingsByStatus = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/overviews/findings`);
|
||||
const url = new URL(`${apiBaseUrl}/overviews/findings`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
@@ -105,8 +103,7 @@ export const getFindingsBySeverity = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/overviews/findings_severity`);
|
||||
const url = new URL(`${apiBaseUrl}/overviews/findings_severity`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { getErrorMessage, parseStringify, wait } from "@/lib";
|
||||
import { apiBaseUrl, getErrorMessage, parseStringify, wait } from "@/lib";
|
||||
|
||||
export const getProviders = async ({
|
||||
page = 1,
|
||||
@@ -16,8 +16,7 @@ export const getProviders = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/providers");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/providers?include=provider_groups`);
|
||||
const url = new URL(`${apiBaseUrl}/providers?include=provider_groups`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
@@ -52,8 +51,7 @@ export const getProvider = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const providerId = formData.get("id");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/providers/${providerId}`);
|
||||
const url = new URL(`${apiBaseUrl}/providers/${providerId}`);
|
||||
|
||||
try {
|
||||
const providers = await fetch(url.toString(), {
|
||||
@@ -74,12 +72,11 @@ export const getProvider = async (formData: FormData) => {
|
||||
|
||||
export const updateProvider = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const providerId = formData.get("providerId");
|
||||
const providerAlias = formData.get("alias");
|
||||
|
||||
const url = new URL(`${keyServer}/providers/${providerId}`);
|
||||
const url = new URL(`${apiBaseUrl}/providers/${providerId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -113,13 +110,12 @@ export const updateProvider = async (formData: FormData) => {
|
||||
|
||||
export const addProvider = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const providerType = formData.get("providerType") as string;
|
||||
const providerUid = formData.get("providerUid") as string;
|
||||
const providerAlias = formData.get("providerAlias") as string;
|
||||
|
||||
const url = new URL(`${keyServer}/providers`);
|
||||
const url = new URL(`${apiBaseUrl}/providers`);
|
||||
|
||||
try {
|
||||
const bodyData = {
|
||||
@@ -157,8 +153,7 @@ export const addProvider = async (formData: FormData) => {
|
||||
|
||||
export const addCredentialsProvider = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/providers/secrets`);
|
||||
const url = new URL(`${apiBaseUrl}/providers/secrets`);
|
||||
|
||||
const secretName = formData.get("secretName");
|
||||
const providerId = formData.get("providerId");
|
||||
@@ -259,8 +254,7 @@ export const updateCredentialsProvider = async (
|
||||
formData: FormData,
|
||||
) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/providers/secrets/${credentialsId}`);
|
||||
const url = new URL(`${apiBaseUrl}/providers/secrets/${credentialsId}`);
|
||||
|
||||
const secretName = formData.get("secretName");
|
||||
const providerType = formData.get("providerType");
|
||||
@@ -352,11 +346,10 @@ export const updateCredentialsProvider = async (
|
||||
|
||||
export const checkConnectionProvider = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const providerId = formData.get("providerId");
|
||||
|
||||
const url = new URL(`${keyServer}/providers/${providerId}/connection`);
|
||||
const url = new URL(`${apiBaseUrl}/providers/${providerId}/connection`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -379,13 +372,12 @@ export const checkConnectionProvider = async (formData: FormData) => {
|
||||
|
||||
export const deleteCredentials = async (secretId: string) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
if (!secretId) {
|
||||
return { error: "Secret ID is required" };
|
||||
}
|
||||
|
||||
const url = new URL(`${keyServer}/providers/secrets/${secretId}`);
|
||||
const url = new URL(`${apiBaseUrl}/providers/secrets/${secretId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -422,14 +414,13 @@ export const deleteCredentials = async (secretId: string) => {
|
||||
|
||||
export const deleteProvider = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const providerId = formData.get("id");
|
||||
|
||||
if (!providerId) {
|
||||
return { error: "Provider ID is required" };
|
||||
}
|
||||
|
||||
const url = new URL(`${keyServer}/providers/${providerId}`);
|
||||
const url = new URL(`${apiBaseUrl}/providers/${providerId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, getErrorMessage, parseStringify } from "@/lib";
|
||||
|
||||
export const getRoles = async ({
|
||||
page = 1,
|
||||
@@ -16,8 +16,7 @@ export const getRoles = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/roles");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/roles`);
|
||||
const url = new URL(`${apiBaseUrl}/roles`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
@@ -50,8 +49,7 @@ export const getRoles = async ({
|
||||
|
||||
export const getRoleInfoById = async (roleId: string) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/roles/${roleId}`);
|
||||
const url = new URL(`${apiBaseUrl}/roles/${roleId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -77,7 +75,6 @@ export const getRoleInfoById = async (roleId: string) => {
|
||||
|
||||
export const addRole = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const name = formData.get("name") as string;
|
||||
const groups = formData.getAll("groups[]") as string[];
|
||||
@@ -118,7 +115,7 @@ export const addRole = async (formData: FormData) => {
|
||||
const body = JSON.stringify(payload);
|
||||
|
||||
try {
|
||||
const url = new URL(`${keyServer}/roles`);
|
||||
const url = new URL(`${apiBaseUrl}/roles`);
|
||||
const response = await fetch(url.toString(), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -143,7 +140,6 @@ export const addRole = async (formData: FormData) => {
|
||||
|
||||
export const updateRole = async (formData: FormData, roleId: string) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const name = formData.get("name") as string;
|
||||
const groups = formData.getAll("groups[]") as string[];
|
||||
@@ -185,7 +181,7 @@ export const updateRole = async (formData: FormData, roleId: string) => {
|
||||
const body = JSON.stringify(payload);
|
||||
|
||||
try {
|
||||
const url = new URL(`${keyServer}/roles/${roleId}`);
|
||||
const url = new URL(`${apiBaseUrl}/roles/${roleId}`);
|
||||
const response = await fetch(url.toString(), {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
@@ -210,9 +206,8 @@ export const updateRole = async (formData: FormData, roleId: string) => {
|
||||
|
||||
export const deleteRole = async (roleId: string) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const url = new URL(`${keyServer}/roles/${roleId}`);
|
||||
const url = new URL(`${apiBaseUrl}/roles/${roleId}`);
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
method: "DELETE",
|
||||
|
||||
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, getErrorMessage, parseStringify } from "@/lib";
|
||||
|
||||
export const getScans = async ({
|
||||
page = 1,
|
||||
@@ -16,8 +16,7 @@ export const getScans = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/scans");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/scans`);
|
||||
const url = new URL(`${apiBaseUrl}/scans`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
@@ -51,8 +50,7 @@ export const getScans = async ({
|
||||
export const getScansByState = async () => {
|
||||
const session = await auth();
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/scans`);
|
||||
const url = new URL(`${apiBaseUrl}/scans`);
|
||||
|
||||
// Request only the necessary fields to optimize the response
|
||||
url.searchParams.append("fields[scans]", "state");
|
||||
@@ -87,8 +85,7 @@ export const getScansByState = async () => {
|
||||
export const getScan = async (scanId: string) => {
|
||||
const session = await auth();
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/scans/${scanId}`);
|
||||
const url = new URL(`${apiBaseUrl}/scans/${scanId}`);
|
||||
|
||||
try {
|
||||
const scan = await fetch(url.toString(), {
|
||||
@@ -110,7 +107,6 @@ export const getScan = async (scanId: string) => {
|
||||
|
||||
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") || undefined;
|
||||
@@ -119,7 +115,7 @@ export const scanOnDemand = async (formData: FormData) => {
|
||||
return { error: "Provider ID is required" };
|
||||
}
|
||||
|
||||
const url = new URL(`${keyServer}/scans`);
|
||||
const url = new URL(`${apiBaseUrl}/scans`);
|
||||
|
||||
try {
|
||||
const requestBody = {
|
||||
@@ -169,11 +165,10 @@ export const scanOnDemand = async (formData: FormData) => {
|
||||
|
||||
export const scheduleDaily = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const providerId = formData.get("providerId");
|
||||
|
||||
const url = new URL(`${keyServer}/schedules/daily`);
|
||||
const url = new URL(`${apiBaseUrl}/schedules/daily`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -211,12 +206,11 @@ export const scheduleDaily = async (formData: FormData) => {
|
||||
|
||||
export const updateScan = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const scanId = formData.get("scanId");
|
||||
const scanName = formData.get("scanName");
|
||||
|
||||
const url = new URL(`${keyServer}/scans/${scanId}`);
|
||||
const url = new URL(`${apiBaseUrl}/scans/${scanId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -251,8 +245,7 @@ export const updateScan = async (formData: FormData) => {
|
||||
export const getExportsZip = async (scanId: string) => {
|
||||
const session = await auth();
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/scans/${scanId}/report`);
|
||||
const url = new URL(`${apiBaseUrl}/scans/${scanId}/report`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./services";
|
||||
@@ -1,97 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
|
||||
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) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`Error fetching data for service ${service.id}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath("/services");
|
||||
return parsedData;
|
||||
};
|
||||
@@ -1,13 +1,12 @@
|
||||
"use server";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, getErrorMessage, parseStringify } from "@/lib";
|
||||
|
||||
export const getTask = async (taskId: string) => {
|
||||
const session = await auth();
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/tasks/${taskId}`);
|
||||
const url = new URL(`${apiBaseUrl}/tasks/${taskId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { auth } from "@/auth.config";
|
||||
import { getErrorMessage, parseStringify } from "@/lib";
|
||||
import { apiBaseUrl, getErrorMessage, parseStringify } from "@/lib";
|
||||
|
||||
export const getUsers = async ({
|
||||
page = 1,
|
||||
@@ -16,8 +16,7 @@ export const getUsers = async ({
|
||||
|
||||
if (isNaN(Number(page)) || page < 1) redirect("/users?include=roles");
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/users?include=roles`);
|
||||
const url = new URL(`${apiBaseUrl}/users?include=roles`);
|
||||
|
||||
if (page) url.searchParams.append("page[number]", page.toString());
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
@@ -50,7 +49,6 @@ export const getUsers = async ({
|
||||
|
||||
export const updateUser = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const userId = formData.get("userId") as string; // Ensure userId is a string
|
||||
const userName = formData.get("name") as string | null;
|
||||
@@ -58,7 +56,7 @@ export const updateUser = async (formData: FormData) => {
|
||||
const userEmail = formData.get("email") as string | null;
|
||||
const userCompanyName = formData.get("company_name") as string | null;
|
||||
|
||||
const url = new URL(`${keyServer}/users/${userId}`);
|
||||
const url = new URL(`${apiBaseUrl}/users/${userId}`);
|
||||
|
||||
// Prepare attributes to send based on changes
|
||||
const attributes: Record<string, any> = {};
|
||||
@@ -105,7 +103,6 @@ export const updateUser = async (formData: FormData) => {
|
||||
|
||||
export const updateUserRole = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const userId = formData.get("userId") as string;
|
||||
const roleId = formData.get("roleId") as string;
|
||||
@@ -115,7 +112,7 @@ export const updateUserRole = async (formData: FormData) => {
|
||||
return { error: "userId and roleId are required" };
|
||||
}
|
||||
|
||||
const url = new URL(`${keyServer}/users/${userId}/relationships/roles`);
|
||||
const url = new URL(`${apiBaseUrl}/users/${userId}/relationships/roles`);
|
||||
|
||||
const requestBody = {
|
||||
data: [
|
||||
@@ -156,14 +153,13 @@ export const updateUserRole = async (formData: FormData) => {
|
||||
|
||||
export const deleteUser = async (formData: FormData) => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const userId = formData.get("userId");
|
||||
|
||||
if (!userId) {
|
||||
return { error: "User ID is required" };
|
||||
}
|
||||
|
||||
const url = new URL(`${keyServer}/users/${userId}`);
|
||||
const url = new URL(`${apiBaseUrl}/users/${userId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
@@ -197,8 +193,7 @@ export const deleteUser = async (formData: FormData) => {
|
||||
|
||||
export const getProfileInfo = async () => {
|
||||
const session = await auth();
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/users/me`);
|
||||
const url = new URL(`${apiBaseUrl}/users/me`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
import { Spacer } from "@nextui-org/react";
|
||||
import { Suspense } from "react";
|
||||
|
||||
import { getServices } from "@/actions/services";
|
||||
import { FilterControls } from "@/components/filters";
|
||||
import { ServiceCard, ServiceSkeletonGrid } from "@/components/services";
|
||||
import { ContentLayout } from "@/components/ui";
|
||||
import { SearchParamsProps } from "@/types";
|
||||
|
||||
export default async function Services({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: SearchParamsProps;
|
||||
}) {
|
||||
const searchParamsKey = JSON.stringify(searchParams || {});
|
||||
export default async function Services() {
|
||||
// const searchParamsKey = JSON.stringify(searchParams || {});
|
||||
return (
|
||||
<ContentLayout
|
||||
title="Services"
|
||||
@@ -21,25 +13,9 @@ export default async function Services({
|
||||
<Spacer y={4} />
|
||||
<FilterControls />
|
||||
<Spacer y={4} />
|
||||
<Suspense key={searchParamsKey} fallback={<ServiceSkeletonGrid />}>
|
||||
{/* <Suspense key={searchParamsKey} fallback={<ServiceSkeletonGrid />}>
|
||||
<SSRServiceGrid />
|
||||
</Suspense>
|
||||
</Suspense> */}
|
||||
</ContentLayout>
|
||||
);
|
||||
}
|
||||
|
||||
const SSRServiceGrid = async () => {
|
||||
const services = await getServices();
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||
{services?.map((service: any) => (
|
||||
<ServiceCard
|
||||
key={service.service_id}
|
||||
fidingsFailed={service.fail_findings}
|
||||
serviceAlias={service.service_alias}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -3,13 +3,11 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { signIn } from "@/auth.config";
|
||||
import { baseUrl } from "@/lib/helper";
|
||||
import { apiBaseUrl, baseUrl } from "@/lib/helper";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const code = searchParams.get("code");
|
||||
|
||||
const params = new URLSearchParams();
|
||||
@@ -23,7 +21,7 @@ export async function GET(req: Request) {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${keyServer}/tokens/github`, {
|
||||
const response = await fetch(`${apiBaseUrl}/tokens/github`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
|
||||
@@ -3,13 +3,11 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { signIn } from "@/auth.config";
|
||||
import { baseUrl } from "@/lib/helper";
|
||||
import { apiBaseUrl, baseUrl } from "@/lib/helper";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
|
||||
const code = searchParams.get("code");
|
||||
|
||||
const params = new URLSearchParams();
|
||||
@@ -23,7 +21,7 @@ export async function GET(req: Request) {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${keyServer}/tokens/google`, {
|
||||
const response = await fetch(`${apiBaseUrl}/tokens/google`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
|
||||
+2
-2
@@ -4,6 +4,7 @@ import Credentials from "next-auth/providers/credentials";
|
||||
import { z } from "zod";
|
||||
|
||||
import { getToken, getUserByMe } from "./actions/auth";
|
||||
import { apiBaseUrl } from "./lib";
|
||||
|
||||
interface CustomJwtPayload extends JwtPayload {
|
||||
user_id: string;
|
||||
@@ -11,8 +12,7 @@ interface CustomJwtPayload extends JwtPayload {
|
||||
}
|
||||
|
||||
const refreshAccessToken = async (token: JwtPayload) => {
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/tokens/refresh`);
|
||||
const url = new URL(`${apiBaseUrl}/tokens/refresh`);
|
||||
|
||||
const bodyData = {
|
||||
data: {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { getTask } from "@/actions/task";
|
||||
import { AuthSocialProvider, MetaDataProps, PermissionInfo } from "@/types";
|
||||
|
||||
export const baseUrl = process.env.AUTH_URL || "http://localhost:3000";
|
||||
export const apiBaseUrl = process.env.API_BASE_URL;
|
||||
|
||||
export const getAuthUrl = (provider: AuthSocialProvider) => {
|
||||
const config = {
|
||||
|
||||
Reference in New Issue
Block a user