fix ssh 4
This commit is contained in:
parent
48f452ea2b
commit
038469b6f7
1 changed files with 37 additions and 16 deletions
|
|
@ -194,19 +194,21 @@ async def _autodetect_db_from_server(
|
||||||
parser = RawConfigParser(strict=False)
|
parser = RawConfigParser(strict=False)
|
||||||
parser.read_string(config_text)
|
parser.read_string(config_text)
|
||||||
|
|
||||||
db_uri = parser.get("server", "db_uri", fallback=None)
|
# Search all sections + DEFAULT (keys before any section header) for db_uri
|
||||||
if db_uri:
|
sections_to_check = list(parser.sections()) + ["DEFAULT"]
|
||||||
|
for section in sections_to_check:
|
||||||
|
try:
|
||||||
|
db_uri = parser.get(section, "db_uri", fallback=None)
|
||||||
|
if db_uri and db_uri.startswith("postgresql"):
|
||||||
|
return _parse_db_uri(db_uri)
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Also check raw defaults (keys before any section)
|
||||||
|
db_uri = parser.defaults().get("db_uri")
|
||||||
|
if db_uri and db_uri.startswith("postgresql"):
|
||||||
return _parse_db_uri(db_uri)
|
return _parse_db_uri(db_uri)
|
||||||
|
|
||||||
# Fallback: try [database] section with individual fields
|
|
||||||
if parser.has_section("database"):
|
|
||||||
return {
|
|
||||||
"host": parser.get("database", "host", fallback=None),
|
|
||||||
"port": int(parser.get("database", "port", fallback="5432")),
|
|
||||||
"user": parser.get("database", "user", fallback=None),
|
|
||||||
"password": parser.get("database", "password", fallback=None),
|
|
||||||
"dbname": parser.get("database", "name", fallback=None),
|
|
||||||
}
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -308,11 +310,30 @@ async def discover_via_ssh(
|
||||||
ssh_password=ssh_password,
|
ssh_password=ssh_password,
|
||||||
)
|
)
|
||||||
if not detected or not all([detected.get("host"), detected.get("user"), detected.get("dbname")]):
|
if not detected or not all([detected.get("host"), detected.get("user"), detected.get("dbname")]):
|
||||||
result.errors.append(
|
# Diagnostic: try to read the config and list what sections/keys are there
|
||||||
"DB connection not configured and could not be auto-detected from server config. "
|
try:
|
||||||
"Fill in the DB connection fields on the object or ensure /etc/caps/config.ini "
|
raw = await _read_remote_config(
|
||||||
"on the server contains a [server] db_uri field."
|
host=obj.server_ip,
|
||||||
)
|
port=ssh_port,
|
||||||
|
username=obj.ssh_user,
|
||||||
|
password=ssh_password,
|
||||||
|
config_path="/etc/caps/config.ini",
|
||||||
|
)
|
||||||
|
diag_parser = RawConfigParser(strict=False)
|
||||||
|
diag_parser.read_string(raw)
|
||||||
|
found_sections = diag_parser.sections()
|
||||||
|
found_keys = {s: list(diag_parser.options(s)) for s in found_sections}
|
||||||
|
result.errors.append(
|
||||||
|
f"db_uri not found in server config. "
|
||||||
|
f"Sections found: {found_sections}. "
|
||||||
|
f"Keys per section: {found_keys}. "
|
||||||
|
f"Fill in DB fields manually on the object."
|
||||||
|
)
|
||||||
|
except Exception as diag_exc:
|
||||||
|
result.errors.append(
|
||||||
|
f"Could not read server config for auto-detection: {diag_exc}. "
|
||||||
|
f"Fill in DB fields manually on the object."
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
db_host = detected["host"]
|
db_host = detected["host"]
|
||||||
db_port = detected["port"]
|
db_port = detected["port"]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue