From 4d69b8facf2f23abf885ed749aabd22dd03e45aa Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 17 Sep 2015 16:51:36 -0700 Subject: [PATCH] rgw: extend list bucket versions api System user can now provide 'objs-container=true' in conjuction with 'format=json' so that response is json and entries are encoded correctly as array. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rest_s3.cc | 16 ++++++++++++++-- src/rgw/rgw_rest_s3.h | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index fd66417628c7d..6979522fa8bc7 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -279,6 +279,7 @@ int RGWListBucket_ObjStore_S3::get_params() delimiter = s->info.args.get("delimiter"); encoding_type = s->info.args.get("encoding-type"); if (s->system_request) { + s->info.args.get_bool("objs-container", &objs_container, false); const char *shard_id_str = s->info.env->get("HTTP_RGWX_SHARD_ID"); if (shard_id_str) { string err; @@ -314,11 +315,18 @@ void RGWListBucket_ObjStore_S3::send_versioned_response() encode_key = true; if (op_ret >= 0) { + if (objs_container) { + s->formatter->open_array_section("Entries"); + } + vector::iterator iter; for (iter = objs.begin(); iter != objs.end(); ++iter) { time_t mtime = iter->mtime.sec(); const char *section_name = (iter->is_delete_marker() ? "DeleteMarker" : "Version"); - s->formatter->open_array_section(section_name); + s->formatter->open_object_section(section_name); + if (objs_container) { + s->formatter->dump_bool("IsDeleteMarker", iter->is_delete_marker()); + } if (encode_key) { string key_name; url_encode(iter->key.name, key_name); @@ -347,6 +355,10 @@ void RGWListBucket_ObjStore_S3::send_versioned_response() dump_owner(s, iter->owner, iter->owner_display_name); s->formatter->close_section(); } + if (objs_container) { + s->formatter->close_section(); + } + if (!common_prefixes.empty()) { map::iterator pref_iter; for (pref_iter = common_prefixes.begin(); pref_iter != common_prefixes.end(); ++pref_iter) { @@ -2868,7 +2880,7 @@ int RGWHandler_Auth_S3::init(RGWRados *store, struct req_state *state, RGWClient RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) { bool is_s3website = enable_s3website && (s->prot_flags & RGW_REST_WEBSITE); - int ret = RGWHandler_ObjStore_S3::init_from_header(s, is_s3website ? RGW_FORMAT_HTML : RGW_FORMAT_XML, false); + int ret = RGWHandler_ObjStore_S3::init_from_header(s, is_s3website ? RGW_FORMAT_HTML : RGW_FORMAT_XML, true); if (ret < 0) return NULL; diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 561261a0b8e7c..b718a27827513 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -41,8 +41,9 @@ public: }; class RGWListBucket_ObjStore_S3 : public RGWListBucket_ObjStore { + bool objs_container; public: - RGWListBucket_ObjStore_S3() { + RGWListBucket_ObjStore_S3() : objs_container(false) { default_max = 1000; } ~RGWListBucket_ObjStore_S3() {} -- 2.39.5