From 0debfea02c027a5dfe92947fa6131f28eead92d0 Mon Sep 17 00:00:00 2001 From: Jane Zhu Date: Mon, 1 May 2023 19:09:18 -0400 Subject: [PATCH] rgw/notification: remove non x-amz-meta-* attributes from the metadata section of the regular notifications Signed-off-by: Juan Zhu (cherry picked from commit 4ca7643bf623b4dd18e112956af36fcb0c86d30a) Conflicts: src/rgw/rgw_notify.cc --- src/rgw/rgw_notify.cc | 19 ++++++++++++++++++- src/rgw/rgw_notify.h | 3 +-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/rgw/rgw_notify.cc b/src/rgw/rgw_notify.cc index 8d86b493bd37c..1f859dc52ac75 100644 --- a/src/rgw/rgw_notify.cc +++ b/src/rgw/rgw_notify.cc @@ -630,6 +630,14 @@ rgw::sal::RGWObject* get_object_with_atttributes(const req_state* s, rgw::sal::R return src_obj; } +static inline void filter_amz_meta(meta_map_t& dest, const meta_map_t& src) { + std::copy_if(src.cbegin(), src.cend(), + std::inserter(dest, dest.end()), + [](const auto& m) { + return (boost::algorithm::starts_with(m.first, RGW_AMZ_META_PREFIX)); + }); +} + void metadata_from_attributes(const req_state* s, rgw::sal::RGWObject* obj, KeyValueMap& metadata) { const auto src_obj = get_object_with_atttributes(s, obj); if (!src_obj) { @@ -726,7 +734,7 @@ bool notification_match(reservation_t& res, const rgw_pubsub_topic_filter& filte const auto s = res.s; if (!filter.s3_filter.metadata_filter.kv.empty()) { // metadata filter exists - res.cached_metadata = s->info.x_meta_map; + filter_amz_meta(res.cached_metadata, s->info.x_meta_map); metadata_from_attributes(s, obj, res.cached_metadata); if (!match(filter.s3_filter.metadata_filter, res.cached_metadata)) { return false; @@ -929,6 +937,15 @@ int publish_abort(const DoutPrefixProvider *dpp, reservation_t& res) { return 0; } +reservation_t::reservation_t(const DoutPrefixProvider *_dpp, + rgw::sal::RGWRadosStore* _store, + const req_state* _s, + rgw::sal::RGWObject* _object, + const std::string* _object_name) : + dpp(_dpp), store(_store), s(_s), object(_object), object_name(_object_name) { + filter_amz_meta(cached_metadata, _s->info.x_meta_map); +} + reservation_t::~reservation_t() { publish_abort(dpp, *this); } diff --git a/src/rgw/rgw_notify.h b/src/rgw/rgw_notify.h index 4aa8f0855501e..9aee8fafe01ae 100644 --- a/src/rgw/rgw_notify.h +++ b/src/rgw/rgw_notify.h @@ -62,8 +62,7 @@ struct reservation_t { KeyValueMap cached_metadata; reservation_t(const DoutPrefixProvider *_dpp, rgw::sal::RGWRadosStore* _store, const req_state* _s, - rgw::sal::RGWObject* _object, const std::string* _object_name=nullptr) : - dpp(_dpp), store(_store), s(_s), object(_object), object_name(_object_name) {} + rgw::sal::RGWObject* _object, const std::string* _object_name=nullptr); // dtor doing resource leak guarding // aborting the reservation if not already committed or aborted -- 2.39.5