From: lishuhao Date: Mon, 28 Jan 2019 08:05:52 +0000 (+0800) Subject: rgw: make rgw admin ops api get user info consistent with the command line X-Git-Tag: v14.2.1~18^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e8afdeaeb35355e7e6b717fba59687dabe5a512f;p=ceph.git rgw: make rgw admin ops api get user info consistent with the command line GET /{admin}/user?format=json HTTP/1.1 Host: {fqdn} This api gets the information is incomplete relative to radosgw-admin user info --uid xxxx This modification will change the information returned by the three calls : RGWUserAdminOp_User::info RGWUserAdminOp_User::create RGWUserAdminOp_User::modify Signed-off-by: Li Shuhao (cherry picked from commit d2c02b37e3a7f7cdd48334d7451930b4db391eec) --- diff --git a/qa/tasks/radosgw_admin_rest.py b/qa/tasks/radosgw_admin_rest.py index b77a73cde3dd..12d3ac046cfc 100644 --- a/qa/tasks/radosgw_admin_rest.py +++ b/qa/tasks/radosgw_admin_rest.py @@ -236,7 +236,26 @@ def task(ctx, config): assert out['keys'][0]['access_key'] == access_key assert out['keys'][0]['secret_key'] == secret_key assert not out['suspended'] - + assert out['tenant'] == '' + assert out['max_buckets'] == 4 + assert out['caps'] == [] + assert out['op_mask'] == 'read, write, delete' + assert out['default_placement'] == '' + assert out['default_storage_class'] == '' + assert out['placement_tags'] == [] + assert not out['bucket_quota']['enabled'] + assert not out['bucket_quota']['check_on_raw'] + assert out['bucket_quota']['max_size'] == -1 + assert out['bucket_quota']['max_size_kb'] == 0 + assert out['bucket_quota']['max_objects'] == -1 + assert not out['user_quota']['enabled'] + assert not out['user_quota']['check_on_raw'] + assert out['user_quota']['max_size'] == -1 + assert out['user_quota']['max_size_kb'] == 0 + assert out['user_quota']['max_objects'] == -1 + assert out['temp_url_keys'] == [] + assert out['type'] == 'rgw' + assert out['mfa_ids'] == [] # TESTCASE 'info-existing','user','info','existing user query with wrong uid but correct access key','returns correct info' (ret, out) = rgwadmin_rest(admin_conn, ['user', 'info'], {'access-key' : access_key, 'uid': 'uid_not_exist'}) @@ -247,6 +266,26 @@ def task(ctx, config): assert out['keys'][0]['access_key'] == access_key assert out['keys'][0]['secret_key'] == secret_key assert not out['suspended'] + assert out['tenant'] == '' + assert out['max_buckets'] == 4 + assert out['caps'] == [] + assert out['op_mask'] == "read, write, delete" + assert out['default_placement'] == '' + assert out['default_storage_class'] == '' + assert out['placement_tags'] == [] + assert not out['bucket_quota']['enabled'] + assert not out['bucket_quota']['check_on_raw'] + assert out ['bucket_quota']['max_size'] == -1 + assert out ['bucket_quota']['max_size_kb'] == 0 + assert out ['bucket_quota']['max_objects'] == -1 + assert not out['user_quota']['enabled'] + assert not out['user_quota']['check_on_raw'] + assert out['user_quota']['max_size'] == -1 + assert out['user_quota']['max_size_kb'] == 0 + assert out['user_quota']['max_objects'] == -1 + assert out['temp_url_keys'] == [] + assert out['type'] == 'rgw' + assert out['mfa_ids'] == [] # TESTCASE 'suspend-ok','user','suspend','active user','succeeds' (ret, out) = rgwadmin_rest(admin_conn, ['user', 'modify'], {'uid' : user1, 'suspended' : True}) diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index e6d58f6c45fd..7cecbbee26c9 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -726,25 +726,53 @@ static void dump_user_info(Formatter *f, RGWUserInfo &info, RGWStorageStats *stats = NULL) { f->open_object_section("user_info"); + encode_json("tenant", info.user_id.tenant, f); + encode_json("user_id", info.user_id.id, f); + encode_json("display_name", info.display_name, f); + encode_json("email", info.user_email, f); + encode_json("suspended", (int)info.suspended, f); + encode_json("max_buckets", (int)info.max_buckets, f); - f->dump_string("tenant", info.user_id.tenant); - f->dump_string("user_id", info.user_id.id); - f->dump_string("display_name", info.display_name); - f->dump_string("email", info.user_email); - 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); - info.caps.dump(f); + + encode_json("caps", info.caps, f); + + char buf[256]; + op_type_to_str(info.op_mask, buf, sizeof(buf)); + encode_json("op_mask", (const char *)buf, f); + encode_json("system", (bool)info.system, f); + encode_json("default_placement", info.default_placement.name, f); + encode_json("default_storage_class", info.default_placement.storage_class, f); + encode_json("placement_tags", info.placement_tags, f); + encode_json("bucket_quota", info.bucket_quota, f); + encode_json("user_quota", info.user_quota, f); + encode_json("temp_url_keys", info.temp_url_keys, f); + + string user_source_type; + switch ((RGWIdentityType)info.type) { + case TYPE_RGW: + user_source_type = "rgw"; + break; + case TYPE_KEYSTONE: + user_source_type = "keystone"; + break; + case TYPE_LDAP: + user_source_type = "ldap"; + break; + case TYPE_NONE: + user_source_type = "none"; + break; + default: + user_source_type = "none"; + break; + } + encode_json("type", user_source_type, f); + encode_json("mfa_ids", info.mfa_ids, f); if (stats) { encode_json("stats", *stats, f); } - f->close_section(); }