22
22
23
23
-export ([federate /1 , for /1 , for /2 , params_to_string /1 , to_params /2 ]).
24
24
% % For testing
25
- -export ([from_set /2 , remove_credentials /1 ]).
25
+ -export ([from_set /2 , from_re / 2 , remove_credentials /1 ]).
26
26
27
27
-import (rabbit_misc , [pget /2 , pget /3 ]).
28
28
-import (rabbit_federation_util , [name /1 , vhost /1 , r /1 ]).
31
31
32
32
federate (XorQ ) ->
33
33
rabbit_policy :get (<<" federation-upstream" >>, XorQ ) =/= undefined orelse
34
- rabbit_policy :get (<<" federation-upstream-set" >>, XorQ ) =/= undefined .
34
+ rabbit_policy :get (<<" federation-upstream-set" >>, XorQ ) =/= undefined orelse
35
+ rabbit_policy :get (<<" federation-upstream-regex" >>, XorQ ) =/= undefined .
35
36
36
37
for (XorQ ) ->
37
38
case federate (XorQ ) of
@@ -49,11 +50,13 @@ for(XorQ, UpstreamName) ->
49
50
upstreams (XorQ ) ->
50
51
UName = rabbit_policy :get (<<" federation-upstream" >>, XorQ ),
51
52
USetName = rabbit_policy :get (<<" federation-upstream-set" >>, XorQ ),
52
- % % Cannot define both, see rabbit_federation_parameters:validate_policy/1
53
- case {UName , USetName } of
54
- {undefined , undefined } -> [];
55
- {undefined , _ } -> set_contents (USetName , vhost (XorQ ));
56
- {_ , undefined } -> [[{<<" upstream" >>, UName }]]
53
+ UReValue = rabbit_policy :get (<<" federation-upstream-regex" >>, XorQ ),
54
+ % % Cannot define 2 at a time, see rabbit_federation_parameters:validate_policy/1
55
+ case {UName , USetName , UReValue } of
56
+ {undefined , undefined , undefined } -> [];
57
+ {undefined , undefined , _ } -> find_contents (UReValue , vhost (XorQ ));
58
+ {undefined , _ , undefined } -> set_contents (USetName , vhost (XorQ ));
59
+ {_ , undefined , undefined } -> [[{<<" upstream" >>, UName }]]
57
60
end .
58
61
59
62
params_table (SafeURI , XorQ ) ->
@@ -87,6 +90,9 @@ print(Fmt, Args) -> iolist_to_binary(io_lib:format(Fmt, Args)).
87
90
from_set (SetName , XorQ ) ->
88
91
from_set_contents (set_contents (SetName , vhost (XorQ )), XorQ ).
89
92
93
+ from_re (SetName , XorQ ) ->
94
+ from_set_contents (find_contents (SetName , vhost (XorQ )), XorQ ).
95
+
90
96
set_contents (<<" all" >>, VHost ) ->
91
97
Upstreams0 = rabbit_runtime_parameters :list (
92
98
VHost , <<" federation-upstream" >>),
@@ -100,6 +106,13 @@ set_contents(SetName, VHost) ->
100
106
Set -> Set
101
107
end .
102
108
109
+ find_contents (RegExp , VHost ) ->
110
+ Upstreams0 = rabbit_runtime_parameters :list (
111
+ VHost , <<" federation-upstream" >>),
112
+ Upstreams = [rabbit_data_coercion :to_list (U ) || U <- Upstreams0 ,
113
+ re :run (pget (name , U ), RegExp ) =/= nomatch ],
114
+ [[{<<" upstream" >>, pget (name , U )}] || U <- Upstreams ].
115
+
103
116
from_set_contents (Set , XorQ ) ->
104
117
Results = [from_set_element (P , XorQ ) || P <- Set ],
105
118
[R || R <- Results , R =/= not_found ].
0 commit comments