Files
prowler/ui/lib/lighthouse/data.ts
Chandrapal Badshah b9bfdc1a5a feat: Integrate Prowler MCP to Lighthouse AI (#9255)
Co-authored-by: Chandrapal Badshah <12944530+Chan9390@users.noreply.github.com>
Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com>
Co-authored-by: Alejandro Bailo <59607668+alejandrobailo@users.noreply.github.com>
Co-authored-by: Alan Buscaglia <gentlemanprogramming@gmail.com>
Co-authored-by: Adrián Jesús Peña Rodríguez <adrianjpr@gmail.com>
Co-authored-by: Andoni Alonso <14891798+andoniaf@users.noreply.github.com>
Co-authored-by: Rubén De la Torre Vico <ruben@prowler.com>
Co-authored-by: Daniel Barranquero <danielbo2001@gmail.com>
2025-12-17 10:10:43 +01:00

126 lines
3.6 KiB
TypeScript

import { getProviders } from "@/actions/providers/providers";
import { getScans } from "@/actions/scans/scans";
import { getUserInfo } from "@/actions/users/users";
import type { ProviderProps } from "@/types/providers";
interface ProviderEntry {
alias: string;
name: string;
provider_type: string;
id: string;
last_checked_at: string;
}
interface ProviderWithScans extends ProviderEntry {
scan_id?: string;
scan_duration?: number;
resource_count?: number;
}
export async function getCurrentDataSection(): Promise<string> {
try {
const profileData = await getUserInfo();
if (!profileData || !profileData.data) {
throw new Error("Unable to fetch user profile data");
}
const userData = {
name: profileData.data.attributes?.name || "",
email: profileData.data.attributes?.email || "",
company: profileData.data.attributes?.company_name || "",
};
const providersData = await getProviders({});
if (!providersData || !providersData.data) {
throw new Error("Unable to fetch providers data");
}
const providerEntries: ProviderEntry[] = providersData.data.map(
(provider: ProviderProps) => ({
alias: provider.attributes?.alias || "Unknown",
name: provider.attributes?.uid || "Unknown",
provider_type: provider.attributes?.provider || "Unknown",
id: provider.id || "Unknown",
last_checked_at:
provider.attributes?.connection?.last_checked_at || "Unknown",
}),
);
const providersWithScans: ProviderWithScans[] = await Promise.all(
providerEntries.map(async (provider: ProviderEntry) => {
try {
// Get scan data for this provider
const scansData = await getScans({
page: 1,
sort: "-inserted_at",
filters: {
"filter[provider]": provider.id,
"filter[state]": "completed",
},
});
// If scans exist, add the scan information to the provider
if (scansData && scansData.data && scansData.data.length > 0) {
const latestScan = scansData.data[0];
return {
...provider,
scan_id: latestScan.id,
scan_duration: latestScan.attributes?.duration,
resource_count: latestScan.attributes?.unique_resource_count,
};
}
return provider;
} catch (error) {
console.error(
`Error fetching scans for provider ${provider.id}:`,
error,
);
return provider;
}
}),
);
return `
**TODAY'S DATE:**
${new Date().toISOString()}
**CURRENT USER DATA:**
Information about the current user interacting with the chatbot:
User: ${userData.name}
Email: ${userData.email}
Company: ${userData.company}
**CURRENT PROVIDER DATA:**
${
providersWithScans.length === 0
? "No Providers Connected"
: providersWithScans
.map(
(provider, index) => `
Provider ${index + 1}:
- Name: ${provider.name}
- Type: ${provider.provider_type}
- Alias: ${provider.alias}
- Provider ID: ${provider.id}
- Last Checked: ${provider.last_checked_at}
${
provider.scan_id
? `- Latest Scan ID: ${provider.scan_id} (informational only - findings tools automatically use latest data)
- Scan Duration: ${provider.scan_duration || "Unknown"}
- Resource Count: ${provider.resource_count || "Unknown"}`
: "- No completed scans found"
}
`,
)
.join("\n")
}
`;
} catch (error) {
console.error("Failed to retrieve current data:", error);
return "**CURRENT DATA: Not available**";
}
}