Comparison

util/prosodyctl/check.lua @ 13778:b6d0f1d79b60 13.0

prosodyctl check: Be more robust against invalid disco_items, and show warning
author Matthew Wild <mwild1@gmail.com>
date Mon, 17 Mar 2025 16:48:39 +0000
parent 13768:4365f0f03c33
child 13811:83478fc0806b
comparison
equal deleted inserted replaced
13776:977415e0122d 13778:b6d0f1d79b60
649 print(""); 649 print("");
650 print(" The 'default_storage' option is not needed if 'storage' is set to a string."); 650 print(" The 'default_storage' option is not needed if 'storage' is set to a string.");
651 break; 651 break;
652 end 652 end
653 end 653 end
654
655 for host, host_config in pairs(config) do --luacheck: ignore 213/host
656 if type(rawget(host_config, "storage")) == "string" and rawget(host_config, "default_storage") then
657 print("");
658 print(" The 'default_storage' option is not needed if 'storage' is set to a string.");
659 break;
660 end
661 end
662
654 local require_encryption = set.intersection(all_options, set.new({ 663 local require_encryption = set.intersection(all_options, set.new({
655 "require_encryption", "c2s_require_encryption", "s2s_require_encryption" 664 "require_encryption", "c2s_require_encryption", "s2s_require_encryption"
656 })):empty(); 665 })):empty();
657 local ssl = dependencies.softreq"ssl"; 666 local ssl = dependencies.softreq"ssl";
658 if not ssl then 667 if not ssl then
723 732
724 do 733 do
725 local orphan_components = {}; 734 local orphan_components = {};
726 local referenced_components = set.new(); 735 local referenced_components = set.new();
727 local enabled_hosts_set = set.new(); 736 local enabled_hosts_set = set.new();
737 local invalid_disco_items = {};
728 for host in it.filter("*", pairs(configmanager.getconfig())) do 738 for host in it.filter("*", pairs(configmanager.getconfig())) do
729 local hostapi = api(host); 739 local hostapi = api(host);
730 if hostapi:get_option_boolean("enabled", true) then 740 if hostapi:get_option_boolean("enabled", true) then
731 enabled_hosts_set:add(host); 741 enabled_hosts_set:add(host);
732 for _, disco_item in ipairs(hostapi:get_option_array("disco_items", {})) do 742 for _, disco_item in ipairs(hostapi:get_option_array("disco_items", {})) do
733 referenced_components:add(disco_item[1]); 743 if type(disco_item[1]) == "string" then
744 referenced_components:add(disco_item[1]);
745 else
746 invalid_disco_items[host] = true;
747 end
734 end 748 end
735 end 749 end
736 end 750 end
737 for host in it.filter(skip_bare_jid_hosts, enabled_hosts()) do 751 for host in it.filter(skip_bare_jid_hosts, enabled_hosts()) do
738 local is_component = not not select(2, modulemanager.get_modules_for_host(host)); 752 local is_component = not not select(2, modulemanager.get_modules_for_host(host));
742 if is_orphan then 756 if is_orphan then
743 table.insert(orphan_components, host); 757 table.insert(orphan_components, host);
744 end 758 end
745 end 759 end
746 end 760 end
761
762 if next(invalid_disco_items) ~= nil then
763 print("");
764 print(" Some hosts in your configuration file have an invalid 'disco_items' option.");
765 print(" This may cause further errors, such as unreferenced components.");
766 print("");
767 for host in it.sorted_pairs(invalid_disco_items) do
768 print(" - "..host);
769 end
770 print("");
771 end
772
747 if #orphan_components > 0 then 773 if #orphan_components > 0 then
748 table.sort(orphan_components); 774 table.sort(orphan_components);
749 print(""); 775 print("");
750 print(" Your configuration contains the following unreferenced components:\n"); 776 print(" Your configuration contains the following unreferenced components:\n");
751 print(" "..table.concat(orphan_components, "\n ")); 777 print(" "..table.concat(orphan_components, "\n "));
1598 end 1624 end
1599 1625
1600 -- And components linked explicitly 1626 -- And components linked explicitly
1601 for _, disco_item in ipairs(hostapi:get_option_array("disco_items", {})) do 1627 for _, disco_item in ipairs(hostapi:get_option_array("disco_items", {})) do
1602 local other_host = disco_item[1]; 1628 local other_host = disco_item[1];
1603 local component_module = configmanager.get(other_host, "component_module"); 1629 if type(other_host) == "string" then
1604 if component_module then 1630 local component_module = configmanager.get(other_host, "component_module");
1605 table.insert(host_components[component_module], other_host); 1631 if component_module then
1632 table.insert(host_components[component_module], other_host);
1633 end
1606 end 1634 end
1607 end 1635 end
1608 end 1636 end
1609 1637
1610 local current_feature; 1638 local current_feature;