mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-01-25 02:08:11 +00:00
Co-authored-by: Chandrapal Badshah <12944530+Chan9390@users.noreply.github.com> Co-authored-by: Alan Buscaglia <gentlemanprogramming@gmail.com> Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import type { LighthouseProvider } from "@/types/lighthouse";
|
|
import {
|
|
baseUrlSchema,
|
|
bedrockCredentialsSchema,
|
|
openAICompatibleCredentialsSchema,
|
|
openAICredentialsSchema,
|
|
} from "@/types/lighthouse/credentials";
|
|
|
|
/**
|
|
* Validate credentials based on provider type
|
|
*/
|
|
export function validateCredentials(
|
|
providerType: LighthouseProvider,
|
|
credentials: Record<string, string>,
|
|
): { success: boolean; error?: string } {
|
|
try {
|
|
switch (providerType) {
|
|
case "openai":
|
|
openAICredentialsSchema.parse(credentials);
|
|
break;
|
|
case "bedrock":
|
|
bedrockCredentialsSchema.parse(credentials);
|
|
break;
|
|
case "openai_compatible":
|
|
openAICompatibleCredentialsSchema.parse(credentials);
|
|
break;
|
|
default:
|
|
return {
|
|
success: false,
|
|
error: `Unknown provider type: ${providerType}`,
|
|
};
|
|
}
|
|
return { success: true };
|
|
} catch (error: unknown) {
|
|
const errorMessage =
|
|
(error as { issues?: Array<{ message: string }>; message?: string })
|
|
?.issues?.[0]?.message ||
|
|
(error as { message?: string })?.message ||
|
|
"Validation failed";
|
|
return {
|
|
success: false,
|
|
error: errorMessage,
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Validate base URL
|
|
*/
|
|
export function validateBaseUrl(baseUrl: string): {
|
|
success: boolean;
|
|
error?: string;
|
|
} {
|
|
try {
|
|
baseUrlSchema.parse(baseUrl);
|
|
return { success: true };
|
|
} catch (error: unknown) {
|
|
const errorMessage =
|
|
(error as { issues?: Array<{ message: string }>; message?: string })
|
|
?.issues?.[0]?.message ||
|
|
(error as { message?: string })?.message ||
|
|
"Invalid base URL";
|
|
return {
|
|
success: false,
|
|
error: errorMessage,
|
|
};
|
|
}
|
|
}
|