Skip to content

Commit

Permalink
Merge pull request #112 from Yurzs/cert-export
Browse files Browse the repository at this point in the history
Certificate export method
  • Loading branch information
N4S4 committed Jan 20, 2023
2 parents c154417 + 77f7529 commit 44ab8e9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions synology_api/core_certificate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from io import BytesIO
from typing import Optional

from . import base_api_core

import os
Expand Down Expand Up @@ -80,3 +83,33 @@ def upload_cert(self, serv_key="server.key", ser_cert="server.crt", ca_cert=None
print('Certificate upload successful.')

return r.status_code, r.json()

def export_cert(self, cert_id: str) -> Optional[BytesIO]:
"""Export a certificate from the Synology NAS.
:param cert_id: The certificate ID to export. This can be found in the list_cert() method.
:return: A BytesIO object containing the certificate archive.
"""

api_name = "SYNO.Core.Certificate"
info = self.session.app_api_list[api_name]
api_path = info['path']

session = requests.session()

url = (
f"{self.base_url}{api_path}?"
f"api={api_name}&"
f"version={info['minVersion']}&"
f"method=export&"
f"file=\"archive\"&"
f"_sid={self._sid}&"
f"id={cert_id}"
)

result = session.get(url, verify=self.session.verify_cert_enabled())

if result.status_code == 200:
return BytesIO(result.content)

return

0 comments on commit 44ab8e9

Please sign in to comment.