1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 17:06:17 +00:00

Fixed potential error/freeze when getting a secret key

This commit is contained in:
spl0k 2019-04-10 21:21:25 +02:00
parent afbd84a5b9
commit 57aea188c2

View File

@ -9,15 +9,19 @@
from base64 import b64encode, b64decode
from os import urandom
from pony.orm import db_session, ObjectNotFound
from pony.orm import db_session, commit, ObjectNotFound
from supysonic.db import Meta
@db_session
def get_secret_key(keyname):
# Commit both at enter and exit. The metadb/db split (from supysonic.db)
# confuses Pony which can either error or hang when this method is called
commit()
try:
key = b64decode(Meta[keyname].value)
except ObjectNotFound:
key = urandom(128)
Meta(key = keyname, value = b64encode(key).decode())
commit()
return key