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:
|
2022-08-18 10:19:43 +02:00
|
|
|
if not server_name:
|
|
|
|
return
|
2022-07-17 23:00:21 +02:00
|
|
|
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
|
2022-08-18 10:19:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
def calc_vaulwarden_location(index):
|
|
|
|
if not index:
|
|
|
|
return '/'
|
|
|
|
return '/notifications/hub'
|