dataset/seed/vaultwarden/funcs/vaultwarden.py

24 lines
704 B
Python

import __main__
from os.path import join as _join, isfile as _isfile, isdir as _isdir
from os import makedirs as _makedirs, environ as _environ
from uuid import uuid4 as _uuid4
_HERE = _environ['PWD']
_PASSWORD_DIR = _join(_HERE, 'password')
def get_uuid(server_name: str) -> str:
if not server_name:
return
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