summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rabbit_cluster_config.erl19
-rw-r--r--src/rabbit_cluster_config_item.erl26
-rw-r--r--src/rabbit_registry.erl3
3 files changed, 46 insertions, 2 deletions
diff --git a/src/rabbit_cluster_config.erl b/src/rabbit_cluster_config.erl
index 55db588256..ca2e60373c 100644
--- a/src/rabbit_cluster_config.erl
+++ b/src/rabbit_cluster_config.erl
@@ -23,12 +23,15 @@
%%---------------------------------------------------------------------------
set(AppName, Key, Value) ->
+ Module = lookup_app(AppName),
+ Term = parse(Value),
+ Module:validate(Term),
rabbit_misc:execute_mnesia_transaction(
fun () ->
ok = mnesia:write(
rabbit_cluster_config,
#cluster_config{key = {AppName, Key},
- value = parse(Value)},
+ value = Term},
write)
end).
@@ -47,6 +50,20 @@ list() ->
info_keys() -> [app_name, key, value].
+%%---------------------------------------------------------------------------
+
+lookup_app(AppBin) ->
+ case rabbit_registry:binary_to_type(AppBin) of
+ {error, not_found} ->
+ exit({not_found, AppBin});
+ T ->
+ case rabbit_registry:lookup_module(cluster_config, T) of
+ {error, not_found} -> exit({not_found, T});
+ {ok, Module} -> Module
+ end
+ end.
+
+
parse(Bin) ->
case erl_scan:string(binary_to_list(Bin)) of
{ok, Scanned, _} ->
diff --git a/src/rabbit_cluster_config_item.erl b/src/rabbit_cluster_config_item.erl
new file mode 100644
index 0000000000..deccc1d432
--- /dev/null
+++ b/src/rabbit_cluster_config_item.erl
@@ -0,0 +1,26 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is VMware, Inc.
+%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved.
+%%
+
+-module(rabbit_cluster_config_item).
+
+-export([behaviour_info/1]).
+
+behaviour_info(callbacks) ->
+ [
+ {validate, 1}
+ ];
+behaviour_info(_Other) ->
+ undefined.
diff --git a/src/rabbit_registry.erl b/src/rabbit_registry.erl
index 8c0ebcbe94..5ed992e0e5 100644
--- a/src/rabbit_registry.erl
+++ b/src/rabbit_registry.erl
@@ -96,7 +96,8 @@ sanity_check_module(ClassModule, Module) ->
end.
class_module(exchange) -> rabbit_exchange_type;
-class_module(auth_mechanism) -> rabbit_auth_mechanism.
+class_module(auth_mechanism) -> rabbit_auth_mechanism;
+class_module(cluster_config) -> rabbit_cluster_config_item.
%%---------------------------------------------------------------------------