From 01e695cebb494b402de16744fba328339f3232f8 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 14 Jul 2024 16:45:17 +0200 Subject: [PATCH] plugin XEP-0060: add a `force` options for publish options in `send_items`: The new `force` option can be used to force the update of configuration is `publish-option` fails. Use this new `force` option in XEP-0384. --- libervia/backend/plugins/plugin_xep_0060.py | 16 ++++++++++++++++ libervia/backend/plugins/plugin_xep_0384.py | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libervia/backend/plugins/plugin_xep_0060.py b/libervia/backend/plugins/plugin_xep_0060.py index a8567367..a6a8b1e4 100644 --- a/libervia/backend/plugins/plugin_xep_0060.py +++ b/libervia/backend/plugins/plugin_xep_0060.py @@ -602,6 +602,9 @@ class XEP_0060(object): - self.EXTRA_ON_PRECOND_NOT_MET(str): policy to have when publishing is failing du to failing precondition. Value can be: * raise (default): raise the exception + * force: try to re-configure the node with the given option. Be sure to + use this option carefully, and not not give public access to a node + which has not on purpose. * publish_without_options: re-publish without the publish-options. A warning will be logged showing that the publish-options could not be used @@ -638,6 +641,19 @@ class XEP_0060(object): policy = extra.get(self.EXTRA_ON_PRECOND_NOT_MET, "raise") if policy == "raise": raise e + elif policy == "force": + log.debug( + f"[{client.profile}] Force configuration for {nodeIdentifier!r} " + f"at {service}: {publish_options}" + ) + await self.setConfiguration( + client, service, nodeIdentifier, publish_options + ) + log.debug("Configuration updated.") + return await self.send_items( + client, service, nodeIdentifier, items, sender, extra + ) + elif policy == "publish_without_options": log.warning( _( diff --git a/libervia/backend/plugins/plugin_xep_0384.py b/libervia/backend/plugins/plugin_xep_0384.py index f42ef9e8..dbd0491b 100644 --- a/libervia/backend/plugins/plugin_xep_0384.py +++ b/libervia/backend/plugins/plugin_xep_0384.py @@ -891,7 +891,7 @@ def make_session_manager( XEP_0060.OPT_ACCESS_MODEL: "open", XEP_0060.OPT_MAX_ITEMS: "max", }, - XEP_0060.EXTRA_ON_PRECOND_NOT_MET: "raise", + XEP_0060.EXTRA_ON_PRECOND_NOT_MET: "force", }, ) except (error.StanzaError, Exception) as e: @@ -1059,7 +1059,7 @@ def make_session_manager( XEP_0060.OPT_MAX_ITEMS: 1, XEP_0060.OPT_ACCESS_MODEL: "open", }, - XEP_0060.EXTRA_ON_PRECOND_NOT_MET: "raise", + XEP_0060.EXTRA_ON_PRECOND_NOT_MET: "force", }, ) except (error.StanzaError, Exception) as e: