From f7b25ebda460b8dba149f7a31aa59f0a53e09e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 12 Jun 2024 16:59:14 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Migrate=20to=20pydantic=20?= =?UTF-8?q?2.x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- octoprint_mfa_totp/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/octoprint_mfa_totp/__init__.py b/octoprint_mfa_totp/__init__.py index 52642bd..71a3fdb 100644 --- a/octoprint_mfa_totp/__init__.py +++ b/octoprint_mfa_totp/__init__.py @@ -1,3 +1,4 @@ +import json import os import time from typing import Dict @@ -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}") @@ -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}") @@ -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()