diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-10-16 16:08:52 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-10-16 16:08:52 +0100 |
commit | ad47942380b78d676568106e5b3bc5a462951c01 (patch) | |
tree | c7e50e79ed4c2a2395d14ca3c949380f8f717d02 /src | |
parent | 3c0d32a5a3fc9c53301cbc21d2e8a40c5ca2a9a3 (diff) | |
download | rabbitmq-server-ad47942380b78d676568106e5b3bc5a462951c01.tar.gz |
Refactor a little bit. And they're Keys, not Tags.
Diffstat (limited to 'src')
-rw-r--r-- | src/rabbit_mirror_queue_misc.erl | 2 | ||||
-rw-r--r-- | src/rabbit_policy.erl | 27 |
2 files changed, 15 insertions, 14 deletions
diff --git a/src/rabbit_mirror_queue_misc.erl b/src/rabbit_mirror_queue_misc.erl index f596e404..6976dbbc 100644 --- a/src/rabbit_mirror_queue_misc.erl +++ b/src/rabbit_mirror_queue_misc.erl @@ -27,7 +27,7 @@ -include("rabbit.hrl"). -rabbit_boot_step({?MODULE, - [{description, "HA policy validation capability"}, + [{description, "HA policy validation"}, {mfa, {rabbit_registry, register, [policy_validator, <<"ha-mode">>, ?MODULE]}}, {mfa, {rabbit_registry, register, diff --git a/src/rabbit_policy.erl b/src/rabbit_policy.erl index 3e7472cc..c938d1be 100644 --- a/src/rabbit_policy.erl +++ b/src/rabbit_policy.erl @@ -218,13 +218,12 @@ policy_validation() -> validation(_Name, []) -> {error, "no policy provided", []}; validation(_Name, Terms) when is_list(Terms) -> - {Tags, Modules} = lists:unzip( - rabbit_registry:lookup_all(policy_validator)), - [] = lists:usort(Tags -- lists:usort(Tags)), %% ASSERTION - Validators = lists:zipwith(fun (M, T) -> {M, a2b(T)} end, Modules, Tags), - + {Keys, Modules} = lists:unzip( + rabbit_registry:lookup_all(policy_validator)), + [] = dups(Keys), %% ASSERTION + Validators = lists:zipwith(fun (M, K) -> {M, a2b(K)} end, Modules, Keys), {TermKeys, _} = lists:unzip(Terms), - case TermKeys -- lists:usort(TermKeys) of + case dups(TermKeys) of [] -> validation0(Validators, Terms); Dup -> {error, "~p duplicate keys not allowed", [Dup]} end; @@ -233,15 +232,15 @@ validation(_Name, Term) -> validation0(Validators, Terms) -> case lists:foldl( - fun (_, {Error, _} = Acc) when Error /= ok -> - Acc; - (Mod, {ok, TermsLeft}) -> - ModTags = proplists:get_all_values(Mod, Validators), - case [T || {Tag, _} = T <- TermsLeft, - lists:member(Tag, ModTags)] of + fun (Mod, {ok, TermsLeft}) -> + ModKeys = proplists:get_all_values(Mod, Validators), + case [T || {Key, _} = T <- TermsLeft, + lists:member(Key, ModKeys)] of [] -> {ok, TermsLeft}; Scope -> {Mod:validate_policy(Scope), TermsLeft -- Scope} - end + end; + (_, Acc) -> + Acc end, {ok, Terms}, proplists:get_keys(Validators)) of {ok, []} -> ok; @@ -252,3 +251,5 @@ validation0(Validators, Terms) -> end. a2b(A) -> list_to_binary(atom_to_list(A)). + +dups(L) -> L -- lists:usort(L). |