ejabberd icon indicating copy to clipboard operation
ejabberd copied to clipboard

Wildcard support for include_config_file

Open toastie89 opened this issue 3 years ago • 2 comments

Hi! Would you please consider to support wildcards for the include_config_file option in the ejabberd configuration?

Desired functionality: All yml files in /etc/ejabberd/conf.d get the imported.

Actual functionality: include_config_file: /etc/ejabberd/conf.d/*.yml does not expand the wildcard

BTW, the certfiles option supports wildcards, what is very convenient :-)

toastie89 avatar Apr 18 '22 18:04 toastie89

The minimal implementation could be something like this, in the yconf library that ejabberd uses to parse the yaml configuration files:

diff --git a/src/yconf.erl b/src/yconf.erl
index 8967067..d93868d 100644
--- a/src/yconf.erl
+++ b/src/yconf.erl
@@ -951,7 +951,15 @@ read_include_files(Includes, Opts, Paths) ->
 		end, Y);
 	 (File) ->
 	      read_yaml(File, Opts, Paths)
-      end, Includes).
+      end, wildcard(Includes)).
+
+wildcard(Paths) when is_list(Paths) ->
+    lists:flatten([wildcard(Path) || Path <- Paths]);
+wildcard({Path, Opt}) ->
+    [{P, Opt} || P <- wildcard(Path)];
+wildcard(Path) when is_binary(Path) ->
+    Files = filelib:wildcard(binary_to_list(Path)),
+    [unicode:characters_to_binary(File) || File <- Files].
 
 %%%===================================================================
 %%% Auxiliary functions

badlop avatar May 25 '22 00:05 badlop

For testing purposes, if you can't apply the patch to yconf, compile yconf and compile ejabberd, there's a simple solution: use this container image https://github.com/badlop/ejabberd/pkgs/container/ejabberd/24688553?tag=3804 which includes patched yconf and ejabberd.

badlop avatar Jun 09 '22 11:06 badlop