Skip to content

Commit

Permalink
Make system time optional in provision and restore (#105)
Browse files Browse the repository at this point in the history
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: #96
  • Loading branch information
robin-nitrokey authored Nov 26, 2023
1 parent 50f84ff commit 31b1cd9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nethsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 31b1cd9

Please sign in to comment.