|
| 1 | +%% The contents of this file are subject to the Mozilla Public License |
| 2 | +%% Version 1.1 (the "License"); you may not use this file except in |
| 3 | +%% compliance with the License. You may obtain a copy of the License |
| 4 | +%% at http://www.mozilla.org/MPL/ |
| 5 | +%% |
| 6 | +%% Software distributed under the License is distributed on an "AS IS" |
| 7 | +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 8 | +%% the License for the specific language governing rights and |
| 9 | +%% limitations under the License. |
| 10 | +%% |
| 11 | +%% The Original Code is RabbitMQ. |
| 12 | +%% |
| 13 | +%% The Initial Developer of the Original Code is GoPivotal, Inc. |
| 14 | +%% Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. |
| 15 | +%% |
| 16 | + |
| 17 | +-module(dummy_runtime_parameters). |
| 18 | +-behaviour(rabbit_runtime_parameter). |
| 19 | +-behaviour(rabbit_policy_validator). |
| 20 | + |
| 21 | +-include("rabbit.hrl"). |
| 22 | + |
| 23 | +-export([validate/5, notify/4, notify_clear/3]). |
| 24 | +-export([register/0, unregister/0]). |
| 25 | +-export([validate_policy/1]). |
| 26 | +-export([register_policy_validator/0, unregister_policy_validator/0]). |
| 27 | + |
| 28 | +%---------------------------------------------------------------------------- |
| 29 | + |
| 30 | +register() -> |
| 31 | + rabbit_registry:register(runtime_parameter, <<"test">>, ?MODULE). |
| 32 | + |
| 33 | +unregister() -> |
| 34 | + rabbit_registry:unregister(runtime_parameter, <<"test">>). |
| 35 | + |
| 36 | +validate(_, <<"test">>, <<"good">>, _Term, _User) -> ok; |
| 37 | +validate(_, <<"test">>, <<"maybe">>, <<"good">>, _User) -> ok; |
| 38 | +validate(_, <<"test">>, <<"admin">>, _Term, none) -> ok; |
| 39 | +validate(_, <<"test">>, <<"admin">>, _Term, User) -> |
| 40 | + case lists:member(administrator, User#user.tags) of |
| 41 | + true -> ok; |
| 42 | + false -> {error, "meh", []} |
| 43 | + end; |
| 44 | +validate(_, <<"test">>, _, _, _) -> {error, "meh", []}. |
| 45 | + |
| 46 | +notify(_, _, _, _) -> ok. |
| 47 | +notify_clear(_, _, _) -> ok. |
| 48 | + |
| 49 | +%---------------------------------------------------------------------------- |
| 50 | + |
| 51 | +register_policy_validator() -> |
| 52 | + rabbit_registry:register(policy_validator, <<"testeven">>, ?MODULE), |
| 53 | + rabbit_registry:register(policy_validator, <<"testpos">>, ?MODULE). |
| 54 | + |
| 55 | +unregister_policy_validator() -> |
| 56 | + rabbit_registry:unregister(policy_validator, <<"testeven">>), |
| 57 | + rabbit_registry:unregister(policy_validator, <<"testpos">>). |
| 58 | + |
| 59 | +validate_policy([{<<"testeven">>, Terms}]) when is_list(Terms) -> |
| 60 | + case length(Terms) rem 2 =:= 0 of |
| 61 | + true -> ok; |
| 62 | + false -> {error, "meh", []} |
| 63 | + end; |
| 64 | + |
| 65 | +validate_policy([{<<"testpos">>, Terms}]) when is_list(Terms) -> |
| 66 | + case lists:all(fun (N) -> is_integer(N) andalso N > 0 end, Terms) of |
| 67 | + true -> ok; |
| 68 | + false -> {error, "meh", []} |
| 69 | + end; |
| 70 | + |
| 71 | +validate_policy(_) -> |
| 72 | + {error, "meh", []}. |
0 commit comments