diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-06-06 15:17:12 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-06-06 15:17:12 +0100 |
commit | 5a132aa4adae657eef9439279c6e2e3ea16a1ab0 (patch) | |
tree | a5d10e297f74fd6c1434404263bdf2326e2a08f7 | |
parent | a6c04df9b55944ec8f947d77697acf31dfd3626a (diff) | |
download | rabbitmq-server-5a132aa4adae657eef9439279c6e2e3ea16a1ab0.tar.gz |
Be more consistent about returning infos from rabbit_auth_backend_internal:list_*_permissions, fix rabbit_vhost:delete. Note that some of the info keys have changed to match those in mgmt, so we avoid a translation layer.
-rw-r--r-- | src/rabbit_auth_backend_internal.erl | 67 | ||||
-rw-r--r-- | src/rabbit_vhost.erl | 6 |
2 files changed, 38 insertions, 35 deletions
diff --git a/src/rabbit_auth_backend_internal.erl b/src/rabbit_auth_backend_internal.erl index 7cbd5dca..2a42ff88 100644 --- a/src/rabbit_auth_backend_internal.erl +++ b/src/rabbit_auth_backend_internal.erl @@ -28,7 +28,9 @@ hash_password/1]). -export([set_permissions/5, clear_permissions/2, list_permissions/0, list_vhost_permissions/1, list_user_permissions/1, - list_user_vhost_permissions/2, vhost_perms_info_keys/0]). + list_user_vhost_permissions/2, perms_info_keys/0, + vhost_perms_info_keys/0, user_perms_info_keys/0, + user_vhost_perms_info_keys/0]). -include("rabbit_auth_backend_spec.hrl"). @@ -58,25 +60,23 @@ regexp(), regexp(), regexp()) -> 'ok'). -spec(clear_permissions/2 :: (rabbit_types:username(), rabbit_types:vhost()) -> 'ok'). --spec(list_permissions/0 :: - () -> [{rabbit_types:username(), rabbit_types:vhost(), - regexp(), regexp(), regexp()}]). +-spec(list_permissions/0 :: () -> rabbit_types:infos()). -spec(list_vhost_permissions/1 :: - (rabbit_types:vhost()) -> [{rabbit_types:username(), - regexp(), regexp(), regexp()}]). + (rabbit_types:vhost()) -> rabbit_types:infos()). -spec(list_user_permissions/1 :: - (rabbit_types:username()) -> [{rabbit_types:vhost(), - regexp(), regexp(), regexp()}]). + (rabbit_types:username()) -> rabbit_types:infos()). -spec(list_user_vhost_permissions/2 :: (rabbit_types:username(), rabbit_types:vhost()) - -> [{regexp(), regexp(), regexp()}]). + -> rabbit_types:infos()). +-spec(perms_info_keys/0 :: () -> rabbit_types:info_keys()). -spec(vhost_perms_info_keys/0 :: () -> rabbit_types:info_keys()). - +-spec(user_perms_info_keys/0 :: () -> rabbit_types:info_keys()). +-spec(user_vhost_perms_info_keys/0 :: () -> rabbit_types:info_keys()). -endif. %%---------------------------------------------------------------------------- --define(PERMS_INFO_KEYS, [configure_perms, write_perms, read_perms]). +-define(PERMS_INFO_KEYS, [configure, write, read]). %% Implementation of rabbit_auth_backend @@ -286,35 +286,38 @@ clear_permissions(Username, VHostPath) -> virtual_host = VHostPath}}) end)). -vhost_perms_info_keys() -> [username] ++ ?PERMS_INFO_KEYS. +perms_info_keys() -> [user, vhost | ?PERMS_INFO_KEYS]. +vhost_perms_info_keys() -> [user | ?PERMS_INFO_KEYS]. +user_perms_info_keys() -> [vhost | ?PERMS_INFO_KEYS]. +user_vhost_perms_info_keys() -> ?PERMS_INFO_KEYS. list_permissions() -> - [{Username, VHostPath, ConfigurePerm, WritePerm, ReadPerm} || - {Username, VHostPath, ConfigurePerm, WritePerm, ReadPerm} <- - list_permissions(match_user_vhost('_', '_'))]. + list_permissions(perms_info_keys(), match_user_vhost('_', '_')). list_vhost_permissions(VHostPath) -> - InfoKeys = vhost_perms_info_keys(), - [lists:zip(InfoKeys, [Username, ConfigurePerm, WritePerm, ReadPerm]) || - {Username, _, ConfigurePerm, WritePerm, ReadPerm} <- - list_permissions(rabbit_vhost:with( - VHostPath, match_user_vhost('_', VHostPath)))]. + list_permissions( + vhost_perms_info_keys(), + rabbit_vhost:with(VHostPath, match_user_vhost('_', VHostPath))). list_user_permissions(Username) -> - [{VHostPath, ConfigurePerm, WritePerm, ReadPerm} || - {_, VHostPath, ConfigurePerm, WritePerm, ReadPerm} <- - list_permissions(rabbit_misc:with_user( - Username, match_user_vhost(Username, '_')))]. + list_permissions( + user_perms_info_keys(), + rabbit_misc:with_user(Username, match_user_vhost(Username, '_'))). list_user_vhost_permissions(Username, VHostPath) -> - [{ConfigurePerm, WritePerm, ReadPerm} || - {_, _, ConfigurePerm, WritePerm, ReadPerm} <- - list_permissions(rabbit_misc:with_user_and_vhost( - Username, VHostPath, - match_user_vhost(Username, VHostPath)))]. - -list_permissions(QueryThunk) -> - [{Username, VHostPath, ConfigurePerm, WritePerm, ReadPerm} || + list_permissions( + user_vhost_perms_info_keys(), + rabbit_misc:with_user_and_vhost( + Username, VHostPath, match_user_vhost(Username, VHostPath))). + +filter_props(Keys, Props) -> [T || T = {K, _} <- Props, lists:member(K, Keys)]. + +list_permissions(Keys, QueryThunk) -> + [filter_props(Keys, [{user, Username}, + {vhost, VHostPath}, + {configure, ConfigurePerm}, + {write, WritePerm}, + {read, ReadPerm}]) || #user_permission{user_vhost = #user_vhost{username = Username, virtual_host = VHostPath}, permission = #permission{ configure = ConfigurePerm, diff --git a/src/rabbit_vhost.erl b/src/rabbit_vhost.erl index 5270d80b..08d6c99a 100644 --- a/src/rabbit_vhost.erl +++ b/src/rabbit_vhost.erl @@ -91,9 +91,9 @@ delete(VHostPath) -> internal_delete(VHostPath) -> lists:foreach( - fun ({Username, _, _, _}) -> - ok = rabbit_auth_backend_internal:clear_permissions(Username, - VHostPath) + fun (Info) -> + ok = rabbit_auth_backend_internal:clear_permissions( + proplists:get_value(user, Info), VHostPath) end, rabbit_auth_backend_internal:list_vhost_permissions(VHostPath)), ok = mnesia:delete({rabbit_vhost, VHostPath}), |