aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pubsub
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2024-03-06 17:38:21 +0000
committerMatthew Wild <mwild1@gmail.com>2024-03-06 17:38:21 +0000
commit7ad4c88432ea19c00935e1624c17e3e56151de80 (patch)
treeab0fa2e84ec111492a14248c2f47b74bdf9b8df5 /plugins/mod_pubsub
parent72f1094ea4cea5302e213f46e7c446cf1c5e0b72 (diff)
downloadprosody-7ad4c88432ea19c00935e1624c17e3e56151de80.tar.gz
prosody-7ad4c88432ea19c00935e1624c17e3e56151de80.zip
mod_pubsub: Add shell commands to create and list nodes
Diffstat (limited to 'plugins/mod_pubsub')
-rw-r--r--plugins/mod_pubsub/mod_pubsub.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index de09ec7d..469b5a15 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -250,3 +250,45 @@ function module.load()
normalize_jid = jid_bare;
}));
end
+
+local function get_service(service_jid)
+ return assert(assert(prosody.hosts[service_jid], "Unknown pubsub service").modules.pubsub, "Not a pubsub service").service;
+end
+
+module:add_item("shell-command", {
+ section = "pubsub";
+ section_desc = "Manage publish/subscribe nodes";
+ name = "create_node";
+ desc = "Create a node with the specified name";
+ args = {
+ { name = "service_jid", type = "string" };
+ { name = "node_name", type = "string" };
+ };
+ host_selector = "service_jid";
+
+ handler = function (self, service_jid, node_name) --luacheck: ignore 212/self
+ return get_service(service_jid):create(node_name, true);
+ end;
+});
+
+module:add_item("shell-command", {
+ section = "pubsub";
+ section_desc = "Manage publish/subscribe nodes";
+ name = "list_nodes";
+ desc = "List nodes on a pubsub service";
+ args = {
+ { name = "service_jid", type = "string" };
+ };
+ host_selector = "service_jid";
+
+ handler = function (self, service_jid) --luacheck: ignore 212/self
+ local service = get_service(service_jid);
+ local nodes = select(2, assert(service:get_nodes(true)));
+ local count = 0;
+ for node_name in pairs(nodes) do
+ count = count + 1;
+ self.session.print(node_name);
+ end
+ return true, ("%d nodes"):format(count);
+ end;
+});