97 lines
2.6 KiB
Python
97 lines
2.6 KiB
Python
|
|
from caddy_worker import CaddyWorker
|
|
from service_functions import ServiceFunctions
|
|
from dsm_worker import DSMWorker
|
|
from pathlib import Path
|
|
from structs import CertInfo, DSMAuthInfo
|
|
|
|
def main():
|
|
|
|
service_worker = ServiceFunctions()
|
|
worker = CaddyWorker()
|
|
|
|
#### Тест CaddyWorker ##################
|
|
pem_cert = None
|
|
|
|
print(f"search_cert_caddy")
|
|
cert_path = worker.search_cert_caddy(
|
|
"D:/Work/Programming/Python/CaddyToDSM/TestData/certs",
|
|
"wud.stadidisk.ru"
|
|
)
|
|
|
|
print(f"Path to cert: {cert_path}")
|
|
print(f"\n")
|
|
|
|
if cert_path:
|
|
print(f"get_cert_info")
|
|
cert_info = worker.get_cert_info(cert_path)
|
|
service_worker.save_cert_info(cert_info, Path("D:/Work/Programming/Python/CaddyToDSM/TestData/pems"))
|
|
|
|
|
|
print(f"Domain: {cert_info.domain_name}")
|
|
print(f"Fingerprint: {cert_info.fingerprint}")
|
|
print(f"Expires at: {cert_info.expires_at}")
|
|
print(f"Key path: {cert_info.path_to_key}")
|
|
print(f"Dir cert: {cert_info.dir_cert}")
|
|
print(f"\n")
|
|
|
|
print(f"convert_to_dsm")
|
|
pem_cert = worker.convert_to_dsm(cert_info.dir_cert,
|
|
"D:/Work/Programming/Python/CaddyToDSM/TestData/pems")
|
|
|
|
if(pem_cert):
|
|
print(f"Cert Name: {pem_cert.certificate_name}")
|
|
print(f"Path to private key: {pem_cert.private_key_path}")
|
|
print(f"Path to pem: {pem_cert.private_key_path}")
|
|
print(f"Path to fullchain: {pem_cert.private_key_path}")
|
|
print(f"\n")
|
|
else:
|
|
print("Convert Certificate Fail")
|
|
print(f"\n")
|
|
|
|
else:
|
|
print("Certificate not found")
|
|
print(f"\n")
|
|
|
|
|
|
|
|
######### Тест DSM worker #################
|
|
|
|
dsm_worker = DSMWorker("http://stadidisk.local")
|
|
auth_info = dsm_worker.auth_in_DSM(Path("D:/Work/Programming/Python/CaddyToDSM/TestData/.secret"))
|
|
print("Starting dsm_worker\n")
|
|
|
|
|
|
if auth_info:
|
|
print(f"Session id: {auth_info.sid}")
|
|
print(f"Token: {auth_info.token}")
|
|
print("\n")
|
|
|
|
print("Starting get_list_certs\n")
|
|
list_certs = dsm_worker.get_list_certs()
|
|
|
|
if list_certs:
|
|
print(f"Cert list: {list_certs}\n")
|
|
|
|
print("Starting dsm_worker\n")
|
|
isOkImport = dsm_worker.import_cert(pem_cert)
|
|
if isOkImport:
|
|
print(f"Cert Import Success\n")
|
|
else:
|
|
print(f"Cert Import Fail\n")
|
|
|
|
|
|
else:
|
|
print("Cert list is empty\n")
|
|
|
|
else:
|
|
print(f"Error getting auth data")
|
|
print("\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |