Skip to content

Commit

Permalink
rgw/notification: remove non x-amz-meta-* attributes from the metadat…
Browse files Browse the repository at this point in the history
…a section of the regular notifications

Signed-off-by: Juan Zhu <jzhu4@dev-10-34-20-139.pw1.bcc.bloomberg.com>
  • Loading branch information
jzhu116-bloomberg authored and Juan Zhu committed May 3, 2023
1 parent e55ae79 commit fb899c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/rgw/driver/rados/rgw_notify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ rgw::sal::Object* get_object_with_atttributes(
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));
});
}


static inline void metadata_from_attributes(
reservation_t& res, rgw::sal::Object* obj) {
auto& metadata = res.x_meta_map;
Expand Down Expand Up @@ -739,7 +748,7 @@ static inline bool notification_match(reservation_t& res,
if (!filter.s3_filter.metadata_filter.kv.empty()) {
// metadata filter exists
if (res.s) {
res.x_meta_map = res.s->info.x_meta_map;
filter_amz_meta(res.x_meta_map, res.s->info.x_meta_map)
}
metadata_from_attributes(res, obj);
if (!match(filter.s3_filter.metadata_filter, res.x_meta_map)) {
Expand Down Expand Up @@ -976,13 +985,14 @@ reservation_t::reservation_t(const DoutPrefixProvider* _dpp,
object(_object), src_object(_src_object), bucket(_s->bucket.get()),
object_name(_object_name),
tagset(_s->tagset),
x_meta_map(_s->info.x_meta_map),
metadata_fetched_from_attributes(false),
user_id(_s->user->get_id().id),
user_tenant(_s->user->get_id().tenant),
req_id(_s->req_id),
yield(y)
{}
{
filter_amz_meta(x_meta_map, _s->info.x_meta_map);
}

reservation_t::reservation_t(const DoutPrefixProvider* _dpp,
rgw::sal::RadosStore* _store,
Expand Down
12 changes: 9 additions & 3 deletions src/test/rgw/bucket_notification/test_bn.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ def verify_events_by_elements(events, keys, exact_match=False, deletions=False):
log.error(events)
assert False, err

META_PREFIX = 'x-amz-meta-'

def verify_s3_records_by_elements(records, keys, exact_match=False, deletions=False, expected_sizes={}, etags=[]):
""" verify there is at least one record per element """
err = ''
Expand All @@ -363,6 +365,9 @@ def verify_s3_records_by_elements(records, keys, exact_match=False, deletions=Fa
#assert_equal(key.etag[1:-1], record['s3']['object']['eTag'])
if etags:
assert_in(key.etag[1:-1], etags)
if len(record['s3']['object']['metadata']) > 0:
for meta in record['s3']['object']['metadata']:
assert(meta['key'].startswith(META_PREFIX))
if deletions and record['eventName'].startswith('ObjectRemoved'):
key_found = True
object_size = record['s3']['object']['size']
Expand All @@ -379,6 +384,9 @@ def verify_s3_records_by_elements(records, keys, exact_match=False, deletions=Fa
assert_equal(key.etag, record['s3']['object']['eTag'])
if etags:
assert_in(key.etag[1:-1], etags)
if len(record['s3']['object']['metadata']) > 0:
for meta in record['s3']['object']['metadata']:
assert(meta['key'].startswith(META_PREFIX))
if deletions and record['eventName'].startswith('ObjectRemoved'):
key_found = True
object_size = record['s3']['object']['size']
Expand Down Expand Up @@ -2345,8 +2353,6 @@ def test_ps_s3_multipart_on_master():
# delete the bucket
conn.delete_bucket(bucket_name)

META_PREFIX = 'x-amz-meta-'

@attr('amqp_test')
def test_ps_s3_metadata_filter_on_master():
""" test s3 notification of metadata on master """
Expand Down Expand Up @@ -2478,7 +2484,7 @@ def test_ps_s3_metadata_on_master():
notification_name = bucket_name + NOTIFICATION_SUFFIX
meta_key = 'meta1'
meta_value = 'This is my metadata value'
meta_prefix = 'x-amz-meta-'
meta_prefix = META_PREFIX
topic_conf_list = [{'Id': notification_name, 'TopicArn': topic_arn,
'Events': ['s3:ObjectCreated:*', 's3:ObjectRemoved:*'],
}]
Expand Down

0 comments on commit fb899c3

Please sign in to comment.