Skip to content

Commit

Permalink
Naming
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Feb 26, 2023
1 parent c3c31a6 commit 5e9e2f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
%% Copyright (c) 2023-2023 VMware, Inc. or its affiliates. All rights reserved.
%%

-module(rabbit_vhost_defaults).
-module(rabbit_db_vhost_defaults).

-export([apply/2]).
-export([list_limits/1, list_operator_policies/1, list_users/1]).

-type definitions() :: [{binary(), term()}].

-record(policy, {
-record(seeding_policy, {
name :: binary(),
queue_pattern = <<".*">> :: binary(),
definition = [] :: definitions()
}).

-type user() :: #{
-type seeded_user_properties() :: #{
name := binary(),
configure := binary(),
read := binary(),
Expand All @@ -40,7 +40,7 @@ apply(VHost, ActingUser) ->
end,
lists:foreach(
fun(P) ->
ok = rabbit_policy:set_op(VHost, P#policy.name, P#policy.queue_pattern, P#policy.definition,
ok = rabbit_policy:set_op(VHost, P#seeding_policy.name, P#seeding_policy.queue_pattern, P#seeding_policy.definition,
undefined, undefined, ActingUser),
rabbit_log:info("Applied default operator policy to vhost '~tp': ~tp", [VHost, P])
end,
Expand Down Expand Up @@ -80,7 +80,7 @@ list_limits(VHost) ->
end.

%% Operator policies that were configured with a matching vhost pattern.
-spec list_operator_policies(vhost:name()) -> [#policy{}].
-spec list_operator_policies(vhost:name()) -> [#seeding_policy{}].
list_operator_policies(VHost) ->
AllPolicies = application:get_env(rabbit, default_policies, []),
OpPolicies = proplists:get_value(operator, AllPolicies, []),
Expand All @@ -92,7 +92,7 @@ list_operator_policies(VHost) ->
QPattern = proplists:get_value(<<"queue_pattern">>, Ss, <<".*">>),
Ss1 = proplists:delete(<<"queue_pattern">>, Ss),
Ss2 = proplists:delete(<<"vhost_pattern">>, Ss1),
{true, #policy{
{true, #seeding_policy{
name = PolicyName,
queue_pattern = QPattern,
definition = underscore_to_dash(Ss2)
Expand All @@ -105,7 +105,7 @@ list_operator_policies(VHost) ->
).

%% Users (permissions) that were configured with a matching vhost pattern.
-spec list_users(vhost:name()) -> [user()].
-spec list_users(vhost:name()) -> [seeded_user_properties()].
list_users(VHost) ->
Users = application:get_env(rabbit, default_users, []),
lists:filtermap(
Expand Down Expand Up @@ -160,7 +160,7 @@ underscore_to_dash(Props) ->
).

%% Add user iff it doesn't exist & set permissions per vhost.
-spec add_user(rabbit_types:vhost(), user(), rabbit_types:username()) -> ok.
-spec add_user(rabbit_types:vhost(), seeded_user_properties(), rabbit_types:username()) -> ok.
add_user(VHost, #{name := Name, configure := C, write := W, read := R} = User, ActingUser) ->
%% put_user has its own existence check, but it still updates password if the user exists.
%% We want only the newly created users to have password set from the config.
Expand Down
4 changes: 2 additions & 2 deletions deps/rabbit/src/rabbit_vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ do_add(Name, Metadata, ActingUser) ->
rabbit_log:info("Adding vhost '~ts' (description: '~ts', tags: ~tp)",
[Name, Description, Tags])
end,
DefaultLimits = rabbit_vhost_defaults:list_limits(Name),
DefaultLimits = rabbit_db_vhost_defaults:list_limits(Name),
{NewOrNot, VHost} = rabbit_db_vhost:create_or_get(Name, DefaultLimits, Metadata),
case NewOrNot of
new ->
rabbit_log:info("Inserted a virtual host record ~tp", [VHost]);
existing ->
ok
end,
rabbit_vhost_defaults:apply(Name, ActingUser),
rabbit_db_vhost_defaults:apply(Name, ActingUser),
_ = [begin
Resource = rabbit_misc:r(Name, exchange, ExchangeName),
rabbit_log:debug("Will declare an exchange ~tp", [Resource]),
Expand Down

0 comments on commit 5e9e2f2

Please sign in to comment.