diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-10-16 17:33:04 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-10-16 17:33:04 +0100 |
commit | dffb2c08c87cc5bc977379eb519e32530f18e4d0 (patch) | |
tree | d5daddd12985c8aa8cd8f32b8d66619555e9068f | |
parent | 0b3978c4b05f6c99943efd66c243ead0c71ea3dd (diff) | |
download | rabbitmq-server-dffb2c08c87cc5bc977379eb519e32530f18e4d0.tar.gz |
As far as I could tell validation for "exactly" was completely broken. Remove attempt at abstraction. Also validate that mode=all does *not* have any params.
-rw-r--r-- | src/rabbit_mirror_queue_misc.erl | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/rabbit_mirror_queue_misc.erl b/src/rabbit_mirror_queue_misc.erl index 1b487534..187388a5 100644 --- a/src/rabbit_mirror_queue_misc.erl +++ b/src/rabbit_mirror_queue_misc.erl @@ -346,32 +346,25 @@ validate_policy(KeyList) -> proplists:get_value(<<"ha-mode">>, KeyList), proplists:get_value(<<"ha-params">>, KeyList)). -validate_policy(<<"all">>, _Params) -> +validate_policy(<<"all">>, undefined) -> ok; +validate_policy(<<"all">>, _Params) -> + {error, "ha-mode=\"all\" does not take parameters", []}; + +validate_policy(<<"nodes">>, []) -> + {error, "ha-mode=\"nodes\" list must be non-empty", []}; +validate_policy(<<"nodes">>, Nodes) when is_list(Nodes) -> + case [I || I <- Nodes, not is_binary(I)] of + [] -> ok; + _ -> {error, "ha-mode=\"nodes\" takes a list of strings", []} + end; validate_policy(<<"nodes">>, Params) -> - validate_params(lists:append(Params), - fun erlang:is_binary/1, - "~p has invalid node names when ha-mode=nodes", - fun (N) -> N > 0 end, - "at least one node expected when ha-mode=nodes"); + {error, "ha-mode=\"nodes\" takes a list, ~p given", [Params]}; + +validate_policy(<<"exactly">>, N) when is_integer(N) andalso N > 0 -> + ok; validate_policy(<<"exactly">>, Params) -> - validate_params(Params, - fun (N) -> is_integer(N) andalso N > 0 end, - "~p must be a positive integer", - fun (N) -> N == 1 end, - "ha-params must be supplied with one number " - "when ha-mode=exactly"); + {error, "ha-mode=\"exactly\" takes an integer, ~p given", [Params]}; validate_policy(Mode, _Params) -> {error, "~p is not a valid ha-mode value", [Mode]}. -validate_params(Params, FilterPred, FilterMsg, SizePred, SizeMsg) - when is_list(Params) -> - case SizePred(length(Params)) of - true -> case lists:filter(fun (P) -> not FilterPred(P) end, Params) of - [] -> ok; - X -> {error, FilterMsg, [X]} - end; - false -> {error, SizeMsg, []} - end; -validate_params(Params, _, _, _, _) -> - {error, "~p was expected to be a list", [Params]}. |