33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import type { MqAuth, MqSystemKind } from "@/types/mq";
|
|
|
|
export type MqAuthKind = MqAuth["kind"];
|
|
export type MqUiAuthKind = MqAuthKind | "kerberos";
|
|
|
|
const KAFKA_AUTH_KINDS = new Set<MqUiAuthKind>(["none", "basic", "kerberos"]);
|
|
const ROCKETMQ_AUTH_KINDS = new Set<MqUiAuthKind>(["none", "basic"]);
|
|
const RABBITMQ_AUTH_KINDS = new Set<MqUiAuthKind>(["none", "basic"]);
|
|
|
|
export function isMqAuthKindAllowedForSystem(systemKind: MqSystemKind, authKind: MqUiAuthKind): boolean {
|
|
if (systemKind === "kafka") return KAFKA_AUTH_KINDS.has(authKind);
|
|
if (systemKind === "rocketmq") return ROCKETMQ_AUTH_KINDS.has(authKind);
|
|
if (systemKind === "rabbitmq") return RABBITMQ_AUTH_KINDS.has(authKind);
|
|
return authKind !== "kerberos";
|
|
}
|
|
|
|
export function detectMqUiAuthKind({ systemKind, authKind, saslMechanism, jaasConfig }: { systemKind: MqSystemKind; authKind?: MqAuthKind; saslMechanism: string; jaasConfig: string }): MqUiAuthKind {
|
|
if (systemKind === "kafka") {
|
|
if (saslMechanism.toUpperCase() === "GSSAPI" && jaasConfig.includes("Krb5LoginModule")) {
|
|
return "kerberos";
|
|
}
|
|
return authKind === "basic" ? "basic" : "none";
|
|
}
|
|
if (systemKind === "rocketmq") {
|
|
return authKind === "basic" ? "basic" : "none";
|
|
}
|
|
if (systemKind === "rabbitmq") {
|
|
return authKind === "basic" ? "basic" : "none";
|
|
}
|
|
|
|
return authKind || "none";
|
|
}
|