Add per-Connection authentication so CDH 5 / Kerberos / HTTP Basic clusters can be queried. - auth_type: none / simple / basic / kerberos - auth_user / auth_password for HTTP Basic - auth_principal / auth_keytab stored for audit/display; actual SPNEGO handled by httpx-kerberos using the system Kerberos credential cache - YarnClientConfig.auth_for_httpx() returns the right httpx.Auth object - _request passes auth= through to httpx.request alongside verify= New dependency: httpx-kerberos. Tests cover none/simple (no auth object), Basic auth header, Kerberos auth object, missing basic user, invalid auth_type, and tool-layer config propagation.
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
# coding=utf-8
|
|
"""
|
|
@Time :2026/6/24
|
|
@Author :tao.chen
|
|
"""
|
|
from common.logging import logger
|
|
from spark_executor.core.connection_store import ConnectionStore, store
|
|
from spark_executor.models import Connection
|
|
|
|
|
|
def save_connection(
|
|
*,
|
|
name: str,
|
|
master: str,
|
|
deploy_mode: str = "cluster",
|
|
yarn_rm_url: str | None = None,
|
|
spark_conf: dict[str, str] | None = None,
|
|
ssl_verify: bool | None = None,
|
|
ssl_ca_bundle: str | None = None,
|
|
auth_type: str = "none",
|
|
auth_user: str | None = None,
|
|
auth_password: str | None = None,
|
|
auth_principal: str | None = None,
|
|
auth_keytab: str | None = None,
|
|
) -> dict[str, str]:
|
|
logger.debug(
|
|
f"save_connection enter name={name} master={master} deploy_mode={deploy_mode} "
|
|
f"yarn_rm_url={yarn_rm_url} spark_conf_keys={list((spark_conf or {}).keys())}"
|
|
)
|
|
conn = Connection(
|
|
name=name,
|
|
master=master,
|
|
deploy_mode=deploy_mode,
|
|
yarn_rm_url=yarn_rm_url,
|
|
spark_conf=spark_conf or {},
|
|
ssl_verify=ssl_verify,
|
|
ssl_ca_bundle=ssl_ca_bundle,
|
|
auth_type=auth_type,
|
|
auth_user=auth_user,
|
|
auth_password=auth_password,
|
|
auth_principal=auth_principal,
|
|
auth_keytab=auth_keytab,
|
|
)
|
|
store.save(conn)
|
|
return {"name": name, "status": "SAVED"}
|
|
|
|
|
|
def list_connections() -> list[dict[str, object]]:
|
|
logger.debug("list_connections enter")
|
|
return [c.model_dump() for c in store.list_all()]
|
|
|
|
|
|
def get_connection(name: str) -> dict[str, object]:
|
|
logger.debug(f"get_connection enter name={name}")
|
|
conn = store.get(name)
|
|
if conn is None:
|
|
raise KeyError(f"Unknown connection: {name}")
|
|
return conn.model_dump()
|
|
|
|
|
|
def delete_connection(name: str) -> dict[str, str]:
|
|
logger.debug(f"delete_connection enter name={name}")
|
|
removed = store.delete(name)
|
|
if not removed:
|
|
raise KeyError(f"Unknown connection: {name}")
|
|
return {"name": name, "status": "DELETED"}
|