Skip to content

Commit

Permalink
⬆️ Migrate to pydantic 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Jun 12, 2024
1 parent 8fdf8ad commit f7b25eb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions octoprint_mfa_totp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import time
from typing import Dict
Expand Down Expand Up @@ -47,7 +48,9 @@ def _load_data(self):
self._data = MfaTotpSettings()
else:
try:
self._data = MfaTotpSettings.parse_file(self._data_file)
with open(self._data_file) as f:
data = json.load(f)
self._data = MfaTotpSettings.model_validate(data)
except Exception as e:
self._logger.exception(f"Error loading TOTP MFA data: {e}")

Expand All @@ -58,7 +61,7 @@ def _save_data(self):
self._cleanup_data()
try:
with open(self._data_file, "w") as f:
f.write(self._data.json(indent=4))
f.write(self._data.model_dump_json(indent=4))
except Exception as e:
self._logger.exception(f"Error saving TOTP MFA data: {e}")

Expand All @@ -80,7 +83,7 @@ def _enroll_user(self, userid):
else:
secret = pyotp.random_base32()
self._data.users[userid] = MfaTotpUserSettings(
created=time.time(), secret=secret
created=int(time.time()), secret=secret
)
self._save_data()

Expand Down

0 comments on commit f7b25eb

Please sign in to comment.