Добавил функцию удаления папок которых нет в списке для обновления. Организовал main. Пока остались тестовые комментарии.
This commit is contained in:
Fedorov Dmitriy
2026-08-28 01:23:40 +03:00
parent e425b51966
commit f3acfc2bbf
5 changed files with 371 additions and 140 deletions
+16 -17
View File
@@ -32,10 +32,12 @@ class DSMWorker:
self.sid: str | None = None
self.token: str | None = None
def auth_in_DSM(self, path_to_secret) -> DSMAuthInfo | None:
def auth_in_DSM(self, path_to_secret) -> bool:
dsm_cred = ServiceFunctions.get_login_pass_from_file(path_to_secret)
if dsm_cred is None:
logging.error("Unable to load DSM credentials")
return False
url = f"{self.dsm_url}/webapi/entry.cgi"
@@ -59,13 +61,13 @@ class DSMWorker:
response.raise_for_status()
except requests.RequestException as e:
logging.error(f"Cannot connect to DSM: {e}")
return None
return False
try:
result = response.json()
except ValueError as e:
logging.error(f"DSM returned invalid JSON: {e}")
return None
return False
if not result.get("success"):
error = result.get("error", {})
@@ -75,7 +77,7 @@ class DSMWorker:
f"code={error.get('code')}"
)
return None
return False
data = result.get("data", {})
@@ -84,21 +86,18 @@ class DSMWorker:
if not sid:
logging.error("DSM did not return SID")
return None
return False
if not token:
logging.error("DSM did not return SynoToken")
return None
return False
self.sid = sid
self.token = token
logging.info("Successfully authenticated in DSM")
return DSMAuthInfo(
sid=sid,
token=token,
)
return True
def get_list_certs(self):
@@ -149,7 +148,7 @@ class DSMWorker:
return result.get("data")
def import_cert(self, dsm_info: DSMInfo) -> DSMInfo:
def import_cert(self, dsm_info: DSMInfo) -> DSMInfo | None:
if not self.sid or not self.token:
logging.error("DSM authentication required")
return None
@@ -166,10 +165,10 @@ class DSMWorker:
)
return None
if not dsm_info.path_to_fullchain.is_file():
if not dsm_info.path_inter_pem_chain.is_file():
logging.error(
f"Fullchain certificate not found: "
f"{dsm_info.path_to_fullchain}"
f"{dsm_info.path_inter_pem_chain}"
)
return None
@@ -221,7 +220,7 @@ class DSMWorker:
try:
with open(dsm_info.private_key_path, "rb") as key_file, \
open(dsm_info.certificate_pem_path, "rb") as cert_file, \
open(dsm_info.path_to_fullchain, "rb") as fullchain_file:
open(dsm_info.path_inter_pem_chain, "rb") as fullchain_file:
files = {
"key": ("private.key", key_file),
@@ -324,10 +323,10 @@ class DSMWorker:
)
return False
if not dsm_info.path_to_fullchain.is_file():
if not dsm_info.path_inter_pem_chain.is_file():
logging.error(
f"Fullchain certificate not found: "
f"{dsm_info.path_to_fullchain}"
f"{dsm_info.path_inter_pem_chain}"
)
return False