commit
bcafbeb3cf
12 changed files with 140 additions and 0 deletions
dockge_cli/components
0
dockge_cli/components/authentication.py
Normal file
0
dockge_cli/components/authentication.py
Normal file
0
dockge_cli/components/communication.py
Normal file
0
dockge_cli/components/communication.py
Normal file
26
dockge_cli/components/storage.py
Normal file
26
dockge_cli/components/storage.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
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()
|
Loading…
Add table
Add a link
Reference in a new issue