Skip to content

Commit

Permalink
rabbit_db: Move missed vhost and user Mnesia-specific code
Browse files Browse the repository at this point in the history
This should have been handled in #6430 but was missed unfortunately.
  • Loading branch information
dcorbacho authored and dumbbell committed Jan 13, 2023
1 parent 3bd5e25 commit f323a02
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 4 additions & 1 deletion deps/rabbit/src/rabbit_auth_backend_internal.erl
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ delete_user(Username, ActingUser) ->
rabbit_types:error('not_found').

lookup_user(Username) ->
rabbit_misc:dirty_read({rabbit_user, Username}).
case rabbit_db_user:get(Username) of
undefined -> {error, not_found};
User -> {ok, User}
end.

-spec exists(rabbit_types:username()) -> boolean().

Expand Down
25 changes: 25 additions & 0 deletions deps/rabbit/src/rabbit_db_user.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

-export([create/1,
update/2,
get/1,
get_all/0,
with_fun_in_mnesia_tx/2,
get_user_permissions/2,
Expand Down Expand Up @@ -89,6 +90,30 @@ update_in_mnesia_tx(Username, UpdateFun) ->
mnesia:abort({no_such_user, Username})
end.

%% -------------------------------------------------------------------
%% get().
%% -------------------------------------------------------------------

-spec get(Username) -> User | undefined when
Username :: vhost:name(),
User :: vhost:vhost().
%% @doc Returns the record of the internal user named `Username'.
%%
%% @returns the internal user record or `undefined' if no internal user is named
%% `Username'.
%%
%% @private

get(Username) when is_binary(Username) ->
rabbit_db:run(
#{mnesia => fun() -> get_in_mnesia(Username) end}).

get_in_mnesia(Username) ->
case ets:lookup(?MNESIA_TABLE, Username) of
[User] -> User;
[] -> undefined
end.

%% -------------------------------------------------------------------
%% get_all().
%% -------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions deps/rabbit/src/rabbit_vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ default_name() ->

-spec lookup(vhost:name()) -> vhost:vhost() | rabbit_types:ok_or_error(any()).
lookup(VHostName) ->
case rabbit_misc:dirty_read({rabbit_vhost, VHostName}) of
{error, not_found} -> {error, {no_such_vhost, VHostName}};
{ok, Record} -> Record
case rabbit_db_vhost:get(VHostName) of
undefined -> {error, {no_such_vhost, VHostName}};
VHost -> VHost
end.

-spec assert(vhost:name()) -> 'ok'.
Expand Down

0 comments on commit f323a02

Please sign in to comment.