Support importing users with arrays of tags

as opposed to a comma-separated binary.

Part of #2667.
This commit is contained in:
Michael Klishin 2020-12-08 18:22:56 +03:00
parent db5a5f57e8
commit e4c37db689
No known key found for this signature in database
GPG Key ID: E80EDCFA0CDB21EE
3 changed files with 67 additions and 4 deletions

View File

@ -39,6 +39,8 @@
%% for testing
-export([hashing_module_for_user/1, expand_topic_permission/2]).
-import(rabbit_data_coercion, [to_atom/1, to_list/1, to_binary/1]).
%%----------------------------------------------------------------------------
-type regexp() :: binary().
@ -662,9 +664,9 @@ put_user(User, Version, ActingUser) ->
true -> [administrator];
false -> []
end;
{TagsS, _} ->
[list_to_atom(string:strip(T)) ||
T <- string:tokens(binary_to_list(TagsS), ",")]
{TagsVal, _} ->
rabbit_log:debug("TagsVal: ~p", [TagsVal]),
tag_list_from(TagsVal)
end,
%% pre-configured, only applies to newly created users
@ -813,6 +815,11 @@ clear_user_limits(Username, LimitType, ActingUser) ->
end),
notify_limit_clear(Username, ActingUser).
tag_list_from(Tags) when is_list(Tags) ->
[to_atom(string:strip(to_list(T))) || T <- Tags];
tag_list_from(Tags) when is_binary(Tags) ->
[to_atom(string:strip(T)) || T <- string:tokens(to_list(Tags), ",")].
flatten_errors(L) ->
case [{F, A} || I <- lists:flatten([L]), {error, F, A} <- [I]] of
[] -> ok;

View File

@ -40,7 +40,8 @@ groups() ->
import_case11,
import_case12,
import_case13,
import_case14
import_case14,
import_case15
]},
{boot_time_import, [], [
import_on_a_booting_node
@ -143,6 +144,8 @@ import_case13(Config) ->
end.
import_case14(Config) -> import_file_case(Config, "case14").
%% contains a user with tags as a list
import_case15(Config) -> import_file_case(Config, "case15").
export_import_round_trip_case1(Config) ->
%% case 6 has runtime parameters that do not depend on any plugins

View File

@ -0,0 +1,53 @@
{
"bindings": [],
"exchanges": [],
"global_parameters": [
{
"name": "cluster_name",
"value": "rabbit@rabbitmq"
}
],
"parameters": [],
"permissions": [
{
"configure": ".*",
"read": ".*",
"user": "guest",
"vhost": "/",
"write": ".*"
}
],
"policies": [],
"queues": [],
"rabbit_version": "3.8.9",
"rabbitmq_version": "3.8.9",
"topic_permissions": [],
"users": [
{
"hashing_algorithm": "rabbit_password_hashing_sha256",
"name": "guest",
"password_hash": "BYipq3D94qlyiZVOAAYLVdN1v8H0BOrOpM9SH6ma5aB354FA",
"tags": "administrator"
},
{
"hashing_algorithm": "rabbit_password_hashing_sha256",
"name": "tagged-user",
"password_hash": "t/Ah03PwU/ol8vkarb+oEYpylRSBWXFAau3eXz3lrjGxtGEK",
"tags": [
"monitoring",
"policymaker",
"impersonator"
]
}
],
"vhosts": [
{
"limits": [],
"metadata": {
"description": "Default virtual host",
"tags": []
},
"name": "/"
}
]
}