]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: clarify the error message when trying to create an existed user 5938/head
authorceph <zhuang.zeqiang@h3c.com>
Thu, 17 Sep 2015 06:46:09 +0000 (14:46 +0800)
committerceph <zhuang.zeqiang@h3c.com>
Thu, 17 Sep 2015 07:04:58 +0000 (15:04 +0800)
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 <zhuang.zeqiang@h3c.com>
src/rgw/rgw_user.cc
src/rgw/rgw_user.h

index 47475c3d8b5ea61da17a3a97d4eb39022f6024c1..d51063b7d6cb2d2b6655286aea2ffc5e21f3cee3 100644 (file)
@@ -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;
index 93666bd0db03b3fead51d73dc46c65bebf7c6fcc..af684335095394cdf58a604418d104e186607ce6 100644 (file)
@@ -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;
   }
 };