From 48771fa0b799edf3f52989bb25b1c46d72b129f4 Mon Sep 17 00:00:00 2001 From: kchheda3 Date: Tue, 27 Feb 2024 15:59:15 -0500 Subject: [PATCH] rgw/notification: Fix the filter_rules to be array vs dict in json output. FilterRules when processed as dict in json, emits samy key name for prefix, suffix causing failure while parsing the json notification output. So change the type FilterRules from JsonDict to Array while dumping in json. Signed-off-by: kchheda3 (cherry picked from commit 0c37788f18cd51a712a2481f8f58a7ee00d359ae) --- src/rgw/rgw_pubsub.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_pubsub.cc b/src/rgw/rgw_pubsub.cc index 7031c2363f0b..79d9f989cc4f 100644 --- a/src/rgw/rgw_pubsub.cc +++ b/src/rgw/rgw_pubsub.cc @@ -23,20 +23,24 @@ void set_event_id(std::string& id, const std::string& hash, const utime_t& ts) { } void rgw_s3_key_filter::dump(Formatter *f) const { + if (!has_content()) { + return; + } + f->open_array_section("FilterRules"); if (!prefix_rule.empty()) { - f->open_object_section("FilterRule"); + f->open_object_section(""); ::encode_json("Name", "prefix", f); ::encode_json("Value", prefix_rule, f); f->close_section(); } if (!suffix_rule.empty()) { - f->open_object_section("FilterRule"); + f->open_object_section(""); ::encode_json("Name", "suffix", f); ::encode_json("Value", suffix_rule, f); f->close_section(); } if (!regex_rule.empty()) { - f->open_object_section("FilterRule"); + f->open_object_section(""); ::encode_json("Name", "regex", f); ::encode_json("Value", regex_rule, f); f->close_section(); @@ -97,8 +101,12 @@ bool rgw_s3_key_filter::has_content() const { } void rgw_s3_key_value_filter::dump(Formatter *f) const { + if (!has_content()) { + return; + } + f->open_array_section("FilterRules"); for (const auto& key_value : kv) { - f->open_object_section("FilterRule"); + f->open_object_section(""); ::encode_json("Name", key_value.first, f); ::encode_json("Value", key_value.second, f); f->close_section(); -- 2.47.3