Refactor configuration management: migrate to per-user storage, update encryption handling, and enhance versioning in CI

This commit is contained in:
SitiWeb
2026-01-23 17:17:25 +01:00
parent 43c5bdac8c
commit 428e3306a0
11 changed files with 570 additions and 279 deletions

View File

@@ -1,62 +1,28 @@
"""
Module for decrypting configuration files using Fernet symmetric encryption.
"""Deprecated legacy module.
Historically this project stored settings and credentials in an encrypted file in the working directory.
The application now uses per-user storage (options.json under the user config directory) and stores
credentials via OS keyring with an encrypted-file fallback.
This module is kept only to avoid breaking old imports.
"""
import json
import os
from cryptography.fernet import Fernet
from __future__ import annotations
from typing import Any, Dict, Optional
from config.encrypt_config import ConfigEncryptor
DECRYPTION_KEY = None
class ConfigDecryptor:
"""
Class to handle decryption of configuration files.
"""
def __init__(self, decryption_key):
"""
Initialize the ConfigDecryptor with a given decryption key.
Args:
decryption_key (bytes): The key to use for decryption.
"""
def __init__(self, decryption_key=None):
self.decryption_key = decryption_key
def decrypt(self):
"""
Decrypt the 'config.enc' file and return the configuration data.
def decrypt(self) -> Optional[Dict[str, Any]]:
return ConfigEncryptor().load_config()
Returns:
dict: The decrypted configuration data.
Raises:
FileNotFoundError: If the 'config.enc' file does not exist.
Exception: If any other error occurs during decryption.
"""
if not os.path.exists("config.enc"):
raise FileNotFoundError(
"The encrypted configuration file 'config.enc' does not exist."
)
fernet = Fernet(self.decryption_key)
with open("config.enc", "rb") as encrypted_file:
encrypted = encrypted_file.read()
decrypted = fernet.decrypt(encrypted).decode()
return json.loads(decrypted)
def hello_world(self):
"""
Placeholder
"""
def hello_world(self) -> str:
return "Hello world"
# Define your key here
# Replace with your actual key
DECRYPTION_KEY = b"u4xTBY5Ns4WYdLvqMjEr138mpMmDEhhqTszKCcDy2cI="
if __name__ == "__main__":
decryptor = ConfigDecryptor(DECRYPTION_KEY)
try:
config = decryptor.decrypt()
except FileNotFoundError as e:
print(e)