From 31b1cd9004b5a769f2323363684a460dcf234ec3 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 26 Nov 2023 17:25:23 +0100 Subject: [PATCH] Make system time optional in provision and restore (#105) Typically, we want to use the current time as the system time. With this patch, the system time argument is made optional in provision and restore and set to the current time if not set. Fixes: https://github.com/Nitrokey/nethsm-sdk-py/issues/96 --- nethsm/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nethsm/__init__.py b/nethsm/__init__.py index 556090c..f184ebf 100644 --- a/nethsm/__init__.py +++ b/nethsm/__init__.py @@ -540,12 +540,15 @@ def provision( self, unlock_passphrase: str, admin_passphrase: str, - system_time: Union[str, datetime], + system_time: Optional[Union[str, datetime]] = None, ) -> None: from .client.components.schema.provision_request_data import ( ProvisionRequestDataDict, ) + if system_time is None: + system_time = datetime.now(timezone.utc) + request_body = ProvisionRequestDataDict( unlockPassphrase=unlock_passphrase, adminPassphrase=admin_passphrase, @@ -1413,13 +1416,16 @@ def backup(self) -> bytes: ) return response.response.data - def restore(self, backup: Bytes, passphrase: str, time: datetime) -> None: + def restore(self, backup: Bytes, passphrase: str, time: Optional[datetime]) -> None: try: from .client.components.schema.restore_request import ( ArgumentsDict, RestoreRequestDict, ) + if not time: + time = datetime.now(timezone.utc) + body = RestoreRequestDict( arguments=ArgumentsDict(backupPassphrase=passphrase, systemTime=time), backup_file=backup,