[inspect] Added get_enabled_plugins and get_enabled_backends actions.

This commit is contained in:
Fabio Manganiello 2023-10-18 22:10:32 +02:00
parent c05d887551
commit c7acc03c8f
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 38 additions and 0 deletions

View file

@ -15,6 +15,7 @@ from platypush.plugins import Plugin, action
from platypush.message import Message
from platypush.message.event import Event
from platypush.message.response import Response
from platypush.utils import get_enabled_backends, get_enabled_plugins
from platypush.utils.mock import auto_mocks
from platypush.utils.manifest import Manifest, Manifests
@ -270,5 +271,19 @@ class InspectPlugin(Plugin):
return Config.get()
@action
def get_enabled_plugins(self) -> List[str]:
"""
Get the list of enabled plugins.
"""
return list(get_enabled_plugins().keys())
@action
def get_enabled_backends(self) -> List[str]:
"""
Get the list of enabled backends.
"""
return list(get_enabled_backends().keys())
# vim:sw=4:ts=4:et:

View file

@ -564,6 +564,29 @@ def get_enabled_plugins() -> dict:
return plugins
def get_enabled_backends() -> dict:
"""
Get the enabled backends.
:return: A dictionary with the enabled backends, in the format ``name`` ->
:class:`platypush.backend.Backend` instance.
"""
from platypush.config import Config
from platypush.context import get_backend
backends = {}
for name in Config.get_backends():
try:
backend = get_backend(name.removeprefix('backend.'))
if backend:
backends[name] = backend
except Exception as e:
logger.warning('Could not initialize backend %s', name)
logger.exception(e)
return backends
def get_redis_conf() -> dict:
"""
Get the Redis connection arguments from the configuration.