Skip to content

Commit

Permalink
limit runtime parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Valiushko committed Apr 17, 2023
1 parent 0533288 commit 29d7d63
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions deps/rabbit/src/rabbit_runtime_parameters.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,43 @@ set_any0(VHost, Component, Name, Term, User) ->
case flatten_errors(
Mod:validate(VHost, Component, Name, Term, get_user(User))) of
ok ->
case rabbit_db_rtparams:set(VHost, Component, Name, Term) of
{old, Term} ->
case is_within_limit(Component) of
ok ->
case rabbit_db_rtparams:set(VHost, Component, Name, Term) of
{old, Term} ->
ok;
_ ->
ActingUser = get_username(User),
event_notify(
parameter_set, VHost, Component,
[{name, Name},
{value, Term},
{user_who_performed_action, ActingUser}]),
Mod:notify(VHost, Component, Name, Term, ActingUser)
end,
ok;
_ ->
ActingUser = get_username(User),
event_notify(
parameter_set, VHost, Component,
[{name, Name},
{value, Term},
{user_who_performed_action, ActingUser}]),
Mod:notify(VHost, Component, Name, Term, ActingUser)
end,
ok;
E ->
E
end;
E ->
E
end;
E ->
E
end.

-spec is_within_limit(binary()) -> rabbit_types:ok_or_error(binary()).

is_within_limit(Component) ->
Limits = application:get_env(rabbit, runtime_parameter_limits, []),
Limit = proplists:get_value(Component, Limits, -1),
case Limit =< 0 orelse count_component(Component) < Limit of
true -> ok;
false -> {errors, [{"component ~ts is limited to ~tp per host", [Component, Limit]}]}
end.

count_component(Component) -> length(list_component(Component)).

%% Validate only an user record as expected by the API before #rabbitmq-event-exchange-10
get_user(#user{} = User) ->
User;
Expand Down

0 comments on commit 29d7d63

Please sign in to comment.