From 6aee8c7a48e57df8e83cd803e1cd1787dd546588 Mon Sep 17 00:00:00 2001 From: krateng Date: Sat, 25 Dec 2021 03:30:39 +0100 Subject: [PATCH] Implemented web interface for API key management, close GH-24 --- maloja/apis/native_v1.py | 10 +++++++--- maloja/globalconf.py | 2 +- maloja/web/jinja/admin_apikeys.jinja | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index a046a0a..31acac2 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -1,5 +1,5 @@ from ..database import * -from ..globalconf import malojaconfig +from ..globalconf import malojaconfig, apikeystore from ..__pkginfo__ import version from ..malojauri import uri_to_internal from .. import utilities @@ -331,5 +331,9 @@ def newrule(**keys): @api.post("settings") @authenticated_api def set_settings(**keys): - from .. import globalconf - globalconf.malojaconfig.update(keys) + malojaconfig.update(keys) + +@api.post("apikeys") +@authenticated_api +def set_settings(**keys): + apikeystore.update(keys) diff --git a/maloja/globalconf.py b/maloja/globalconf.py index 8dc37ea..a4cf65b 100644 --- a/maloja/globalconf.py +++ b/maloja/globalconf.py @@ -313,7 +313,7 @@ config( ### symmetric keys are fine for now since we hopefully use HTTPS -apikeystore = KeyStore(file=data_dir['clients']("apikeys.yml"),save_endpoint="/apis/mlj_1/api_keys") +apikeystore = KeyStore(file=data_dir['clients']("apikeys.yml"),save_endpoint="/apis/mlj_1/apikeys") oldfile = pthj(dir_settings['config'],"clients","authenticated_machines.tsv") if os.path.exists(oldfile): diff --git a/maloja/web/jinja/admin_apikeys.jinja b/maloja/web/jinja/admin_apikeys.jinja index bc16fb4..a3b3fa4 100644 --- a/maloja/web/jinja/admin_apikeys.jinja +++ b/maloja/web/jinja/admin_apikeys.jinja @@ -4,5 +4,7 @@ {% block maincontent %} +Here you can add and remove API keys used by your scrobblers. It is recommended to use +a different key for each scrobbler.

{{ apikeys.html() }} {% endblock %}