Keepass outline
This commit is contained in:
parent
b18488a6d3
commit
162c0adf13
9 changed files with 115 additions and 3 deletions
38
app/services/passwords.py
Normal file
38
app/services/passwords.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import os.path
|
||||
|
||||
from pykeepass import PyKeePass, create_database, Group
|
||||
|
||||
|
||||
class Passwords:
|
||||
def __init__(self):
|
||||
from app.config import get_settings
|
||||
settings = get_settings()
|
||||
|
||||
with open(settings.kp.secret, "r") as fh:
|
||||
secret = fh.read()
|
||||
|
||||
self._kp_org = self.__get_or_create_store(settings.kp.file, secret)
|
||||
self._kp = self.__get_lock(settings.kp.file, secret)
|
||||
|
||||
@staticmethod
|
||||
def __get_or_create_store(path, passwd) -> PyKeePass:
|
||||
if os.path.exists(path):
|
||||
return PyKeePass(
|
||||
path,
|
||||
password=passwd,
|
||||
)
|
||||
return create_database(path, passwd)
|
||||
|
||||
@staticmethod
|
||||
def __get_lock(path, passwd) -> PyKeePass:
|
||||
lock_path = path + ".lock"
|
||||
import shutil
|
||||
shutil.copyfile(path, lock_path)
|
||||
return Passwords.__get_or_create_store(lock_path, passwd)
|
||||
|
||||
@property
|
||||
def store(self):
|
||||
return self._kp.root_group
|
||||
|
||||
def save(self, group: Group):
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue