From 9134a50365b4280f3383a910e47c346ba7c55ebf Mon Sep 17 00:00:00 2001 From: yuliyang Date: Thu, 1 Nov 2018 08:23:26 +0800 Subject: [PATCH] rgw: admin rest api support op-mask Signed-off-by: yuliyang --- src/rgw/rgw_json_enc.cc | 2 +- src/rgw/rgw_rest_user.cc | 26 ++++++++++++++++++++++++++ src/rgw/rgw_user.cc | 5 ++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 04d11f4d73d1..4fa2ad6a5294 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -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); } diff --git a/src/rgw/rgw_rest_user.cc b/src/rgw/rgw_rest_user.cc index b6737f25504b..a69cc6e6b2e2 100644 --- a/src/rgw/rgw_rest_user.cc +++ b/src/rgw/rgw_rest_user.cc @@ -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); } diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 54d874c596e3..10cf24cddbfa 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -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); -- 2.47.3