support dashboard cdc mysql credentials
This commit is contained in:
parent
39603715be
commit
5a99fa46fd
@ -1364,19 +1364,25 @@ def render_dashboard_cdc_env() -> str:
|
||||
from .nacos import current_namespace, get_config_content
|
||||
|
||||
namespace_id, _ = current_namespace()
|
||||
content = get_config_content(namespace_id, "common", "rds-config.yml")
|
||||
rds_content = get_config_content(namespace_id, "common", "rds-config.yml")
|
||||
try:
|
||||
cdc_content = get_config_content(namespace_id, "common", "dashboard-cdc-worker.yml")
|
||||
except Exception: # noqa: BLE001
|
||||
cdc_content = ""
|
||||
|
||||
def yaml_value(key: str) -> str:
|
||||
def yaml_value(content: str, key: str, *, required: bool = True) -> str:
|
||||
match = re.search(rf"(?im)^\s*{re.escape(key)}\s*:\s*(.*?)\s*$", content)
|
||||
if not match:
|
||||
raise RuntimeError(f"missing {key} in common/rds-config.yml")
|
||||
if required:
|
||||
raise RuntimeError(f"missing {key} in nacos mysql config")
|
||||
return ""
|
||||
value = match.group(1).strip()
|
||||
if (value.startswith('"') and value.endswith('"')) or (value.startswith("'") and value.endswith("'")):
|
||||
value = value[1:-1]
|
||||
return value
|
||||
|
||||
jdbc_url = (
|
||||
yaml_value("url")
|
||||
yaml_value(rds_content, "url")
|
||||
.replace("jdbc:p6spy:mysql://", "mysql://", 1)
|
||||
.replace("jdbc:mysql://", "mysql://", 1)
|
||||
)
|
||||
@ -1384,8 +1390,8 @@ def render_dashboard_cdc_env() -> str:
|
||||
if not parsed.hostname:
|
||||
raise RuntimeError("invalid rds-config url for dashboard cdc worker")
|
||||
|
||||
username = yaml_value("username")
|
||||
password = yaml_value("password")
|
||||
username = yaml_value(cdc_content, "username", required=False) or yaml_value(rds_content, "username")
|
||||
password = yaml_value(cdc_content, "password", required=False) or yaml_value(rds_content, "password")
|
||||
database = parsed.path.lstrip("/") or "likei"
|
||||
addr = f"{parsed.hostname}:{parsed.port or 3306}"
|
||||
dsn = (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user