2022-03-06 03:57:46 +03:00
|
|
|
### API KEYS
|
|
|
|
### symmetric keys are fine since we hopefully use HTTPS
|
|
|
|
|
|
|
|
from doreah.keystore import KeyStore
|
|
|
|
from doreah.logging import log
|
|
|
|
|
2022-04-09 22:39:04 +03:00
|
|
|
from ..pkg_global.conf import data_dir
|
2022-03-06 03:57:46 +03:00
|
|
|
|
|
|
|
apikeystore = KeyStore(file=data_dir['clients']("apikeys.yml"),save_endpoint="/apis/mlj_1/apikeys")
|
2022-04-07 23:50:08 +03:00
|
|
|
|
|
|
|
|
2022-03-06 03:57:46 +03:00
|
|
|
from .. import upgrade
|
|
|
|
upgrade.upgrade_apikeys()
|
|
|
|
|
2022-01-06 07:19:56 +03:00
|
|
|
|
|
|
|
# skip regular authentication if api key is present in request
|
|
|
|
# an api key now ONLY permits scrobbling tracks, no other admin tasks
|
2022-04-06 22:08:14 +03:00
|
|
|
def api_key_correct(request,args,kwargs):
|
|
|
|
if "key" in kwargs:
|
|
|
|
apikey = kwargs.pop("key")
|
|
|
|
elif "apikey" in kwargs:
|
|
|
|
apikey = kwargs.pop("apikey")
|
2022-01-06 07:19:56 +03:00
|
|
|
else: return False
|
2022-04-06 23:05:41 +03:00
|
|
|
|
|
|
|
client = apikeystore.check_and_identify_key(apikey)
|
|
|
|
if client:
|
2022-04-06 22:08:14 +03:00
|
|
|
return {'client':client}
|
2022-02-14 08:07:54 +03:00
|
|
|
else:
|
|
|
|
return False
|