🐛 fix(base.py): fix issue with loading and saving secret key in Settings class

🐛 fix(utils.py): fix issue with writing secret key to file in write_secret_to_file function
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-30 17:39:51 -03:00
commit a8b9c08a9d
2 changed files with 5 additions and 1 deletions

View file

@ -72,6 +72,10 @@ class Settings(BaseSettings):
if secret_key_path.exists():
value = read_secret_from_file(secret_key_path)
logger.debug("Loaded secret key")
if not value:
value = secrets.token_urlsafe(32)
write_secret_to_file(secret_key_path, value)
logger.debug("Saved secret key")
else:
value = secrets.token_urlsafe(32)
write_secret_to_file(secret_key_path, value)

View file

@ -35,7 +35,7 @@ def set_secure_permissions(file_path):
def write_secret_to_file(path: Path, value: str) -> None:
with path.open("wb") as f:
f.write(value)
f.write(value.encode("utf-8"))
try:
set_secure_permissions(path)
except Exception: