dockge-cli/dockge_cli/components/storage.py
Firq bcafbeb3cf
All checks were successful
/ backend-pylint (push) Successful in 9s
Initial Commit
2024-06-29 14:14:18 +02:00

27 lines
805 B
Python

import pathlib
import base64
import yaml
_storagepath = pathlib.Path(__file__).parents[1] / ".temp"
_file = _storagepath / "storage.yaml"
_storagepath.mkdir(exist_ok=True, parents=True)
def set(key: str, value: str):
with open(_file, "w+") as file:
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader) or {}
content.update({ key: base64.b64encode(value.encode()) })
yaml.dump(content, file, Dumper=yaml.SafeDumper)
def get(key: str):
value: str = None
if not _file.exists():
return None
with open(_file, "r") as file:
content: dict[str, str] = yaml.load(file, Loader=yaml.SafeLoader)
value = content.get(key, None)
return base64.b64decode(value).decode() if value is not None else None
def clear():
_file.unlink()