From d5be35af4939fa049647ecf4d432c75b0dd771b8 Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Mon, 17 Mar 2025 16:26:27 +0100 Subject: [PATCH] chore: Rename keyServer and extract to helper (#7256) --- ui/actions/auth/auth.ts | 10 +-- ui/actions/compliances/compliances.ts | 5 +- ui/actions/findings/findings.ts | 8 +- ui/actions/invitations/invitation.ts | 17 ++-- ui/actions/manage-groups/manage-groups.ts | 17 ++-- ui/actions/overview/overview.ts | 11 +-- ui/actions/providers/providers.ts | 29 +++---- ui/actions/roles/roles.ts | 17 ++-- ui/actions/scans/scans.ts | 23 ++---- ui/actions/services/index.ts | 1 - ui/actions/services/services.ts | 97 ----------------------- ui/actions/task/tasks.ts | 5 +- ui/actions/users/users.ts | 17 ++-- ui/app/(prowler)/services/page.tsx | 32 +------- ui/app/api/auth/callback/github/route.ts | 6 +- ui/app/api/auth/callback/google/route.ts | 6 +- ui/auth.config.ts | 4 +- ui/lib/helper.ts | 1 + 18 files changed, 68 insertions(+), 238 deletions(-) delete mode 100644 ui/actions/services/index.ts delete mode 100644 ui/actions/services/services.ts diff --git a/ui/actions/auth/auth.ts b/ui/actions/auth/auth.ts index d39314d2da..e0e3a75e20 100644 --- a/ui/actions/auth/auth.ts +++ b/ui/actions/auth/auth.ts @@ -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, ) => { - 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) => { - 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) => { }; 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(), { diff --git a/ui/actions/compliances/compliances.ts b/ui/actions/compliances/compliances.ts index 5eb94cde98..a89c932d91 100644 --- a/ui/actions/compliances/compliances.ts +++ b/ui/actions/compliances/compliances.ts @@ -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); diff --git a/ui/actions/findings/findings.ts b/ui/actions/findings/findings.ts index 901228a91a..b4c804e43c 100644 --- a/ui/actions/findings/findings.ts +++ b/ui/actions/findings/findings.ts @@ -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); diff --git a/ui/actions/invitations/invitation.ts b/ui/actions/invitations/invitation.ts index 28ef77c9e2..d1908f21da 100644 --- a/ui/actions/invitations/invitation.ts +++ b/ui/actions/invitations/invitation.ts @@ -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(), { diff --git a/ui/actions/manage-groups/manage-groups.ts b/ui/actions/manage-groups/manage-groups.ts index 13b29534ae..7ed92989c8 100644 --- a/ui/actions/manage-groups/manage-groups.ts +++ b/ui/actions/manage-groups/manage-groups.ts @@ -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(), { diff --git a/ui/actions/overview/overview.ts b/ui/actions/overview/overview.ts index 2095a9f32f..ef591ee11f 100644 --- a/ui/actions/overview/overview.ts +++ b/ui/actions/overview/overview.ts @@ -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); diff --git a/ui/actions/providers/providers.ts b/ui/actions/providers/providers.ts index 0ac39db2d6..5289eb5205 100644 --- a/ui/actions/providers/providers.ts +++ b/ui/actions/providers/providers.ts @@ -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(), { diff --git a/ui/actions/roles/roles.ts b/ui/actions/roles/roles.ts index a371fd74ea..8f7cbde0fb 100644 --- a/ui/actions/roles/roles.ts +++ b/ui/actions/roles/roles.ts @@ -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", diff --git a/ui/actions/scans/scans.ts b/ui/actions/scans/scans.ts index 954b600a26..d647c3fdfb 100644 --- a/ui/actions/scans/scans.ts +++ b/ui/actions/scans/scans.ts @@ -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(), { diff --git a/ui/actions/services/index.ts b/ui/actions/services/index.ts deleted file mode 100644 index b2221a94a8..0000000000 --- a/ui/actions/services/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./services"; diff --git a/ui/actions/services/services.ts b/ui/actions/services/services.ts deleted file mode 100644 index cfd295e1cb..0000000000 --- a/ui/actions/services/services.ts +++ /dev/null @@ -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; -}; diff --git a/ui/actions/task/tasks.ts b/ui/actions/task/tasks.ts index fdf75c7cea..dc4ea9eee9 100644 --- a/ui/actions/task/tasks.ts +++ b/ui/actions/task/tasks.ts @@ -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(), { diff --git a/ui/actions/users/users.ts b/ui/actions/users/users.ts index 4e64023b13..18db0ab2ec 100644 --- a/ui/actions/users/users.ts +++ b/ui/actions/users/users.ts @@ -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 = {}; @@ -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(), { diff --git a/ui/app/(prowler)/services/page.tsx b/ui/app/(prowler)/services/page.tsx index 5177ea2310..dc4878cf64 100644 --- a/ui/app/(prowler)/services/page.tsx +++ b/ui/app/(prowler)/services/page.tsx @@ -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 ( - }> + {/* }> - + */} ); } - -const SSRServiceGrid = async () => { - const services = await getServices(); - - return ( -
- {services?.map((service: any) => ( - - ))} -
- ); -}; diff --git a/ui/app/api/auth/callback/github/route.ts b/ui/app/api/auth/callback/github/route.ts index 918d019360..2c70a8cd88 100644 --- a/ui/app/api/auth/callback/github/route.ts +++ b/ui/app/api/auth/callback/github/route.ts @@ -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", diff --git a/ui/app/api/auth/callback/google/route.ts b/ui/app/api/auth/callback/google/route.ts index 521ed1c413..0f92d8ef46 100644 --- a/ui/app/api/auth/callback/google/route.ts +++ b/ui/app/api/auth/callback/google/route.ts @@ -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", diff --git a/ui/auth.config.ts b/ui/auth.config.ts index 6db01ce49a..ed15ed4a38 100644 --- a/ui/auth.config.ts +++ b/ui/auth.config.ts @@ -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: { diff --git a/ui/lib/helper.ts b/ui/lib/helper.ts index 428270ed2e..7f7e199fba 100644 --- a/ui/lib/helper.ts +++ b/ui/lib/helper.ts @@ -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 = {