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
|
|
|
|
|
|
|
|
from ..globalconf import data_dir
|
|
|
|
|
|
|
|
apikeystore = KeyStore(file=data_dir['clients']("apikeys.yml"),save_endpoint="/apis/mlj_1/apikeys")
|
|
|
|
from .. import upgrade
|
|
|
|
upgrade.upgrade_apikeys()
|
|
|
|
|
|
|
|
log("Authenticated Machines: " + ", ".join([k for k in apikeystore]),module='apis')
|
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-02-14 08:07:54 +03:00
|
|
|
if checkAPIkey(apikey):
|
2022-04-06 22:08:14 +03:00
|
|
|
client = [c for c in apikeystore if apikeystore[c]==apikey][0]
|
|
|
|
return {'client':client}
|
2022-02-14 08:07:54 +03:00
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2022-01-06 07:19:56 +03:00
|
|
|
def checkAPIkey(key):
|
|
|
|
return apikeystore.check_key(key)
|
|
|
|
def allAPIkeys():
|
|
|
|
return [apikeystore[k] for k in apikeystore]
|