Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

984 B
Raw Blame
export type ZooKeeperAuthScheme = "digest" | "sasl_digest";

const AUTH_SCHEME_PARAM = "auth_scheme";

function parseParams(params?: string): URLSearchParams {
  return new URLSearchParams((params || "").trim().replace(/^\?/, "").replace(/;/g, "&"));
}

function isAuthSchemeParam(key: string): boolean {
  return key.trim().toLowerCase() === AUTH_SCHEME_PARAM;
}

export function zooKeeperAuthScheme(params?: string): ZooKeeperAuthScheme {
  const configured = Array.from(parseParams(params).entries()).find(([key]) => isAuthSchemeParam(key))?.[1];
  return configured?.toLowerCase() === "sasl_digest" ? "sasl_digest" : "digest";
}

export function setZooKeeperAuthScheme(params: string | undefined, scheme: ZooKeeperAuthScheme): string {
  const parsed = parseParams(params);
  for (const key of Array.from(parsed.keys())) {
    if (isAuthSchemeParam(key)) parsed.delete(key);
  }
  if (scheme === "sasl_digest") parsed.set(AUTH_SCHEME_PARAM, scheme);
  return parsed.toString();
}