summaryrefslogtreecommitdiff
path: root/src/rabbit_mirror_queue_misc.erl
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2013-05-14 14:17:29 +0100
committerSimon MacMullen <simon@rabbitmq.com>2013-05-14 14:17:29 +0100
commit49471f5697ade1718eaa2d371219eb8d8e081965 (patch)
tree7068b76005aec517265a60f11211da0b93a10fe4 /src/rabbit_mirror_queue_misc.erl
parent3c5bcf94c52115ca9e49b98fabe16974abafb7d9 (diff)
downloadrabbitmq-server-49471f5697ade1718eaa2d371219eb8d8e081965.tar.gz
Tighten up HA policy validation.bug25555
Diffstat (limited to 'src/rabbit_mirror_queue_misc.erl')
-rw-r--r--src/rabbit_mirror_queue_misc.erl32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/rabbit_mirror_queue_misc.erl b/src/rabbit_mirror_queue_misc.erl
index 8787e966..5607bfa9 100644
--- a/src/rabbit_mirror_queue_misc.erl
+++ b/src/rabbit_mirror_queue_misc.erl
@@ -316,24 +316,30 @@ update_mirrors0(OldQ = #amqqueue{name = QName},
%%----------------------------------------------------------------------------
validate_policy(KeyList) ->
- Mode = proplists:get_value(<<"ha-mode">>, KeyList),
+ Mode = proplists:get_value(<<"ha-mode">>, KeyList, none),
Params = proplists:get_value(<<"ha-params">>, KeyList, none),
- case Mode of
- undefined -> ok;
- _ -> case module(Mode) of
- {ok, M} -> case M:validate_policy(Params) of
- ok -> validate_sync_mode(KeyList);
- E -> E
- end;
- _ -> {error,
- "~p is not a valid ha-mode value", [Mode]}
- end
+ SyncMode = proplists:get_value(<<"ha-sync-mode">>, KeyList, none),
+ case {Mode, Params, SyncMode} of
+ {none, none, none} ->
+ ok;
+ {none, _, _} ->
+ {error, "ha-mode must be specified to specify ha-params or "
+ "ha-sync-mode", []};
+ _ ->
+ case module(Mode) of
+ {ok, M} -> case M:validate_policy(Params) of
+ ok -> validate_sync_mode(SyncMode);
+ E -> E
+ end;
+ _ -> {error, "~p is not a valid ha-mode value", [Mode]}
+ end
end.
-validate_sync_mode(KeyList) ->
- case proplists:get_value(<<"ha-sync-mode">>, KeyList, <<"manual">>) of
+validate_sync_mode(SyncMode) ->
+ case SyncMode of
<<"automatic">> -> ok;
<<"manual">> -> ok;
+ none -> ok;
Mode -> {error, "ha-sync-mode must be \"manual\" "
"or \"automatic\", got ~p", [Mode]}
end.