1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +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 base64 import b64encode, b64decode
from os import urandom from os import urandom
from pony.orm import db_session, ObjectNotFound from pony.orm import db_session, commit, ObjectNotFound
from supysonic.db import Meta from supysonic.db import Meta
@db_session @db_session
def get_secret_key(keyname): 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: try:
key = b64decode(Meta[keyname].value) key = b64decode(Meta[keyname].value)
except ObjectNotFound: except ObjectNotFound:
key = urandom(128) key = urandom(128)
Meta(key = keyname, value = b64encode(key).decode()) Meta(key = keyname, value = b64encode(key).decode())
commit()
return key return key