dataset/seed/vaultwarden/funcs/vaultwarden.py

23 lines
708 B
Python
Raw Normal View History

2022-07-17 23:00:21 +02:00
import __main__
from os.path import dirname as _dirname, abspath as _abspath, join as _join, isfile as _isfile, isdir as _isdir
from os import makedirs as _makedirs
2022-03-08 19:42:28 +01:00
from uuid import uuid4 as _uuid4
2022-07-17 23:00:21 +02:00
_HERE = _dirname(_abspath(__main__.__file__))
_PASSWORD_DIR = _join(_HERE, 'password')
2022-03-08 19:42:28 +01:00
2022-07-17 23:00:21 +02:00
def get_uuid(server_name: str) -> str:
dir_name = _join(_PASSWORD_DIR, server_name)
if not _isdir(dir_name):
_makedirs(dir_name)
file_name = _join(dir_name, 'uuid')
if not _isfile(file_name):
uuid = str(_uuid4())
with open(file_name, 'w') as fh:
fh.write(uuid)
with open(file_name, 'r') as fh:
file_content = fh.read().strip()
return file_content