See #7323. Rename default policy for ha-* and add option to massage key/value for aggregate_props

This commit is contained in:
Simon Unge 2023-02-22 11:46:03 -08:00
parent 232c7faece
commit d66b38d333
3 changed files with 23 additions and 6 deletions

View File

@ -743,16 +743,22 @@ end}.
{datatype, integer}
]}.
{mapping, "default_policies.operator.$id.ha_mode", "rabbit.default_policies.operator", [
{mapping, "default_policies.operator.$id.classic_queues.ha_mode", "rabbit.default_policies.operator", [
{datatype, string}
]}.
{mapping, "default_policies.operator.$id.ha_params", "rabbit.default_policies.operator", [
{mapping, "default_policies.operator.$id.classic_queues.ha_params", "rabbit.default_policies.operator", [
{datatype, [integer, {list, string}]}
]}.
{translation, "rabbit.default_policies.operator", fun(Conf) ->
Props = rabbit_cuttlefish:aggregate_props(Conf, ["default_policies", "operator"]),
Props = rabbit_cuttlefish:aggregate_props(
Conf,
["default_policies", "operator"],
fun({["default_policies","operator",ID,"classic_queues"|T], V}) ->
{["default_policies","operator",ID|T],V};
(E) -> E
end),
Props1 = lists:map(
fun({K, Ss}) ->
{K,

View File

@ -8,7 +8,8 @@
-module(rabbit_cuttlefish).
-export([
aggregate_props/2
aggregate_props/2,
aggregate_props/3
]).
-type keyed_props() :: [{binary(), [{binary(), any()}]}].
@ -16,13 +17,19 @@
-spec aggregate_props([{string(), any()}], [string()]) ->
keyed_props().
aggregate_props(Conf, Prefix) ->
aggregate_props(Conf, Prefix, fun(E) -> E end).
-spec aggregate_props([{string(), any()}], [string()], function()) ->
keyed_props().
aggregate_props(Conf, Prefix, KeyFun) ->
Pattern = Prefix ++ ["$id", "$_"],
PrefixLen = length(Prefix),
FlatList = lists:filtermap(
fun({K, V}) ->
fun(E) ->
{K, V} = KeyFun(E),
case cuttlefish_variable:is_fuzzy_match(K, Pattern) of
true -> {true, {lists:nthtail(PrefixLen, K), V}};
_ -> false
false -> false
end
end,
Conf

View File

@ -123,9 +123,13 @@ ssl_options.fail_if_no_peer_cert = true",
default_policies.operator.a.expires = 1h
default_policies.operator.a.queue_pattern = apple
default_policies.operator.a.vhost_pattern = banana
default_policies.operator.a.classic_queues.ha_mode = exactly
default_policies.operator.a.classic_queues.ha_params = 2
",
[{rabbit, [{default_policies, [{operator, [
{<<"a">>, [{<<"expires">>, 3600000},
{<<"ha-mode">>, "exactly"},
{<<"ha-params">>, 2},
{<<"queue-pattern">>, "apple"},
{<<"vhost-pattern">>, "banana"}]}]}]}]}],
[]},