Реализовал функцию импорта сертификатов. Если он есть она обновляет, если сертификат было по умолнчаию она оставляет по умолчанию
This commit is contained in:
+42
-1
@@ -1,7 +1,8 @@
|
||||
import json
|
||||
from structs import CertInfo
|
||||
from structs import CertInfo, DSMCredentials
|
||||
from pathlib import Path
|
||||
from dataclasses import asdict
|
||||
import logging
|
||||
|
||||
class ServiceFunctions:
|
||||
|
||||
@@ -18,4 +19,44 @@ class ServiceFunctions:
|
||||
(save_dir / cert_info.dir_cert.name).write_text(
|
||||
json.dumps(data, indent=4, ensure_ascii=False),
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_login_pass_from_file(path_to_file: Path):
|
||||
|
||||
if not path_to_file.is_file():
|
||||
logging.error(f"Secret file not found: {path_to_file}")
|
||||
return None
|
||||
|
||||
try:
|
||||
lines = path_to_file.read_text(encoding="utf-8").splitlines()
|
||||
except OSError as e:
|
||||
logging.error(f"Cannot read secret file {path_to_file}: {e}")
|
||||
return None
|
||||
|
||||
secret = {}
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
|
||||
if not line or "=" not in line:
|
||||
continue
|
||||
|
||||
key, value = line.split("=", 1)
|
||||
secret[key.strip()] = value.strip()
|
||||
|
||||
user_name = secret.get("username")
|
||||
password = secret.get("password")
|
||||
|
||||
if not user_name:
|
||||
logging.error("user_name is not specified in secret")
|
||||
return None
|
||||
|
||||
if not password:
|
||||
logging.error("password is not specified in secret")
|
||||
return None
|
||||
|
||||
return DSMCredentials(
|
||||
user_name=user_name,
|
||||
password=password,
|
||||
)
|
||||
Reference in New Issue
Block a user