Plugins can now register .env settings
This commit is contained in:
parent
f52ae5228f
commit
ea83511d0a
|
@ -34,6 +34,7 @@ def get_plugin_config(
|
||||||
source=False,
|
source=False,
|
||||||
registry=_plugins,
|
registry=_plugins,
|
||||||
conf={},
|
conf={},
|
||||||
|
settings={},
|
||||||
description=None,
|
description=None,
|
||||||
version=None,
|
version=None,
|
||||||
label=None,
|
label=None,
|
||||||
|
@ -42,8 +43,12 @@ def get_plugin_config(
|
||||||
"name": name,
|
"name": name,
|
||||||
"label": label or name,
|
"label": label or name,
|
||||||
"logger": logger,
|
"logger": logger,
|
||||||
|
# conf is for dynamic settings
|
||||||
"conf": conf,
|
"conf": conf,
|
||||||
|
# settings is for settings hardcoded in .env
|
||||||
|
"settings": settings,
|
||||||
"user": True if source else user,
|
"user": True if source else user,
|
||||||
|
# source plugins are plugins that provide audio content
|
||||||
"source": source,
|
"source": source,
|
||||||
"description": description,
|
"description": description,
|
||||||
"version": version,
|
"version": version,
|
||||||
|
@ -52,6 +57,24 @@ def get_plugin_config(
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|
||||||
|
def load_settings(name, settings):
|
||||||
|
from django.conf import settings as django_settings
|
||||||
|
|
||||||
|
mapping = {
|
||||||
|
"boolean": django_settings.ENV.bool,
|
||||||
|
"text": django_settings.ENV,
|
||||||
|
}
|
||||||
|
values = {}
|
||||||
|
prefix = "FUNKWHALE_PLUGIN_{}".format(name.upper())
|
||||||
|
for s in settings:
|
||||||
|
key = "_".join([prefix, s["name"].upper()])
|
||||||
|
value = mapping[s["type"]](key, default=s.get("default", None))
|
||||||
|
values[s["name"]] = value
|
||||||
|
|
||||||
|
logger.debug("Plugin %s running with settings %s", name, values)
|
||||||
|
return values
|
||||||
|
|
||||||
|
|
||||||
def get_session():
|
def get_session():
|
||||||
from funkwhale_api.common import session
|
from funkwhale_api.common import session
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ ROOT_DIR = environ.Path(__file__) - 3 # (/a/b/myfile.py - 3 = /)
|
||||||
APPS_DIR = ROOT_DIR.path("funkwhale_api")
|
APPS_DIR = ROOT_DIR.path("funkwhale_api")
|
||||||
|
|
||||||
env = environ.Env()
|
env = environ.Env()
|
||||||
|
ENV = env
|
||||||
LOGLEVEL = env("LOGLEVEL", default="info").upper()
|
LOGLEVEL = env("LOGLEVEL", default="info").upper()
|
||||||
"""
|
"""
|
||||||
Default logging level for the Funkwhale processes""" # pylint: disable=W0105
|
Default logging level for the Funkwhale processes""" # pylint: disable=W0105
|
||||||
|
|
|
@ -17,3 +17,5 @@ class CommonConfig(AppConfig):
|
||||||
mutations.registry.autodiscover(app_names)
|
mutations.registry.autodiscover(app_names)
|
||||||
utils.monkey_patch_request_build_absolute_uri()
|
utils.monkey_patch_request_build_absolute_uri()
|
||||||
plugins.startup.autodiscover([p + ".funkwhale_ready" for p in settings.PLUGINS])
|
plugins.startup.autodiscover([p + ".funkwhale_ready" for p in settings.PLUGINS])
|
||||||
|
for p in plugins._plugins.values():
|
||||||
|
p["settings"] = plugins.load_settings(p["name"], p["settings"])
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
"""
|
||||||
|
A plugin that enables scrobbling to ListenBrainz and Last.fm.
|
||||||
|
|
||||||
|
If you're scrobbling to last.fm, you will need to create an `API account <https://www.last.fm/api/account/create>`_
|
||||||
|
and add two variables two your .env file:
|
||||||
|
|
||||||
|
- ``FUNKWHALE_PLUGIN_SCROBBLER_LASTFM_API_KEY=apikey``
|
||||||
|
- ``FUNKWHALE_PLUGIN_SCROBBLER_LASTFM_API_SECRET=apisecret``
|
||||||
|
|
||||||
|
"""
|
||||||
from config import plugins
|
from config import plugins
|
||||||
|
|
||||||
PLUGIN = plugins.get_plugin_config(
|
PLUGIN = plugins.get_plugin_config(
|
||||||
|
@ -24,4 +34,8 @@ PLUGIN = plugins.get_plugin_config(
|
||||||
{"name": "username", "type": "text", "label": "Your scrobbler username"},
|
{"name": "username", "type": "text", "label": "Your scrobbler username"},
|
||||||
{"name": "password", "type": "password", "label": "Your scrobbler password"},
|
{"name": "password", "type": "password", "label": "Your scrobbler password"},
|
||||||
],
|
],
|
||||||
|
# settings=[
|
||||||
|
# {"name": "lastfm_api_key", "type": "text"},
|
||||||
|
# {"name": "lastfm_api_secret", "type": "text"},
|
||||||
|
# ]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue