From b8c5d5b38e3aebfdda0a628608a2e68a5edde118 Mon Sep 17 00:00:00 2001 From: ceph Date: Thu, 17 Sep 2015 14:46:09 +0800 Subject: [PATCH] rgw: clarify the error message when trying to create an existed user Modify the error message when trying to create an existed user to indicate which of uid, email or key actually causes the conflict. Signed-off-by: Zeqiang Zhuang --- src/rgw/rgw_user.cc | 37 +++++++++++++++++++++---------------- src/rgw/rgw_user.h | 8 +++++++- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 47475c3d8b5e..d51063b7d6cb 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -1643,18 +1643,23 @@ int RGWUser::init(RGWUserAdminOpState& op_state) } } - if (!uid.empty() && (uid.compare(RGW_USER_ANON_ID) != 0)) + if (!uid.empty() && (uid.compare(RGW_USER_ANON_ID) != 0)) { found = (rgw_get_user_info_by_uid(store, uid, user_info, &op_state.objv) >= 0); - - if (!user_email.empty() && !found) + op_state.found_by_uid = found; + } + if (!user_email.empty() && !found) { found = (rgw_get_user_info_by_email(store, user_email, user_info, &op_state.objv) >= 0); - - if (!swift_user.empty() && !found) + op_state.found_by_email = found; + } + if (!swift_user.empty() && !found) { found = (rgw_get_user_info_by_swift(store, swift_user, user_info, &op_state.objv) >= 0); - - if (!access_key.empty() && !found) + op_state.found_by_key = found; + } + if (!access_key.empty() && !found) { found = (rgw_get_user_info_by_access_key(store, access_key, user_info, &op_state.objv) >= 0); - + op_state.found_by_key = found; + } + op_state.set_existing_user(found); if (found) { op_state.set_user_info(user_info); @@ -1779,8 +1784,13 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg) return execute_modify(op_state, err_msg); } - set_err_msg(err_msg, "user: " + op_state.user_id + " exists"); - + if (op_state.found_by_email) { + set_err_msg(err_msg, "email: " + user_email + " exists"); + } else if (op_state.found_by_key) { + set_err_msg(err_msg, "duplicate key provided"); + } else { + set_err_msg(err_msg, "user: " + op_state.user_id + " exists"); + } return -EEXIST; } @@ -1796,12 +1806,7 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg) return -EINVAL; } - // fail if the user email is a duplicate - if (op_state.has_existing_email()) { - set_err_msg(err_msg, "duplicate email provided"); - return -EEXIST; - } - + // set the user info user_id = uid; user_info.user_id = user_id; diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index 93666bd0db03..af6843350953 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -202,7 +202,10 @@ struct RGWUserAdminOpState { bool system_specified; bool key_op; bool temp_url_key_specified; - + bool found_by_uid; + bool found_by_email; + bool found_by_key; + // req parameters bool populated; bool initialized; @@ -477,6 +480,9 @@ struct RGWUserAdminOpState { bucket_quota_specified = false; temp_url_key_specified = false; user_quota_specified = false; + found_by_uid = false; + found_by_email = false; + found_by_key = false; } }; -- 2.47.3