]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: admin rest api support op-mask 24869/head
authoryuliyang <yuliyang@cmss.chinamobile.com>
Thu, 1 Nov 2018 00:23:26 +0000 (08:23 +0800)
committeryuliyang <yuliyang@cmss.chinamobile.com>
Thu, 1 Nov 2018 01:09:50 +0000 (09:09 +0800)
Signed-off-by: yuliyang <yuliyang@cmss.chinamobile.com>
src/rgw/rgw_json_enc.cc
src/rgw/rgw_rest_user.cc
src/rgw/rgw_user.cc

index 04d11f4d73d1504ca67054d61c757622bf72753e..4fa2ad6a5294cb7713a37416696bb6f1c5999476 100644 (file)
@@ -381,7 +381,7 @@ static struct rgw_flags_desc op_type_flags[] = {
  { 0, NULL }
 };
 
-static void op_type_to_str(uint32_t mask, char *buf, int len)
+extern void op_type_to_str(uint32_t mask, char *buf, int len)
 {
   return mask_to_str(op_type_flags, mask, buf, len);
 }
index b6737f25504be6fb7a74c103a891c36359c44d5c..a69cc6e6b2e21df0c0c1da3531cabdafe80bbc50 100644 (file)
@@ -83,6 +83,7 @@ void RGWOp_User_Create::execute()
   std::string key_type_str;
   std::string caps;
   std::string tenant_name;
+  std::string op_mask_str;
 
   bool gen_key;
   bool suspended;
@@ -109,6 +110,7 @@ void RGWOp_User_Create::execute()
   RESTArgs::get_int32(s, "max-buckets", default_max_buckets, &max_buckets);
   RESTArgs::get_bool(s, "system", false, &system);
   RESTArgs::get_bool(s, "exclusive", false, &exclusive);
+  RESTArgs::get_string(s, "op-mask", op_mask_str, &op_mask_str);
 
   if (!s->user->system && system) {
     ldout(s->cct, 0) << "cannot set system flag by non-system user" << dendl;
@@ -128,6 +130,17 @@ void RGWOp_User_Create::execute()
   op_state.set_access_key(access_key);
   op_state.set_secret_key(secret_key);
 
+  if (!op_mask_str.empty()) {
+    uint32_t op_mask;
+    int ret = rgw_parse_op_type_list(op_mask_str, &op_mask);
+    if (ret < 0) {
+      ldout(s->cct, 0) << "failed to parse op_mask: " << ret << dendl;
+      http_ret = -EINVAL;
+      return;
+    }
+    op_state.set_op_mask(op_mask);
+  }
+
   if (!key_type_str.empty()) {
     int32_t key_type = KEY_TYPE_UNDEFINED;
     if (key_type_str.compare("swift") == 0)
@@ -179,6 +192,7 @@ void RGWOp_User_Modify::execute()
   std::string secret_key;
   std::string key_type_str;
   std::string caps;
+  std::string op_mask_str;
 
   bool gen_key;
   bool suspended;
@@ -203,6 +217,7 @@ void RGWOp_User_Modify::execute()
   RESTArgs::get_string(s, "key-type", key_type_str, &key_type_str);
 
   RESTArgs::get_bool(s, "system", false, &system);
+  RESTArgs::get_string(s, "op-mask", op_mask_str, &op_mask_str);
 
   if (!s->user->system && system) {
     ldout(s->cct, 0) << "cannot set system flag by non-system user" << dendl;
@@ -242,6 +257,17 @@ void RGWOp_User_Modify::execute()
   if (s->info.args.exists("system"))
     op_state.set_system(system);
 
+  if (!op_mask_str.empty()) {
+    uint32_t op_mask;
+    int ret = rgw_parse_op_type_list(op_mask_str, &op_mask);
+    if (ret < 0) {
+      ldout(s->cct, 0) << "failed to parse op_mask: " << ret << dendl;
+      http_ret = -EINVAL;
+      return;
+    }
+    op_state.set_op_mask(op_mask);
+  }
+
   http_ret = RGWUserAdminOp_User::modify(store, op_state, flusher);
 }
 
index 54d874c596e3c9a0fd40850bafae60433476ca79..10cf24cddbfacdb0114f5778c60b610f9024f91d 100644 (file)
@@ -29,7 +29,7 @@
 
 
 static RGWMetadataHandler *user_meta_handler = NULL;
-
+extern void op_type_to_str(uint32_t mask, char *buf, int len);
 
 /**
  * Get the anonymous (ie, unauthenticated) user info.
@@ -722,6 +722,9 @@ static void dump_user_info(Formatter *f, RGWUserInfo &info,
   f->dump_int("suspended", (int)info.suspended);
   f->dump_int("max_buckets", (int)info.max_buckets);
   f->dump_bool("system", (bool)info.system);
+  char buf[256];
+  op_type_to_str(info.op_mask, buf, sizeof(buf));
+  f->dump_string("op_mask", (const char *)buf);
   dump_subusers_info(f, info);
   dump_access_keys_info(f, info);
   dump_swift_keys_info(f, info);