From 2265309cd7e3bf3f3829698bf2765ec6b0f0c872 Mon Sep 17 00:00:00 2001 From: kchheda3 Date: Thu, 10 Aug 2023 18:36:12 +0530 Subject: [PATCH] rgw/notification: Store user info while creating notification topic Signed-off-by: kchheda3 --- src/rgw/rgw_pubsub.cc | 13 ++++++------- src/rgw/rgw_pubsub.h | 10 ++++------ src/rgw/rgw_rest_pubsub.cc | 7 +++++-- src/test/rgw/bucket_notification/test_bn.py | 7 +++++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/rgw/rgw_pubsub.cc b/src/rgw/rgw_pubsub.cc index 2b0cffd47c1fb..36bef95e68c43 100644 --- a/src/rgw/rgw_pubsub.cc +++ b/src/rgw/rgw_pubsub.cc @@ -676,12 +676,11 @@ int RGWPubSub::Bucket::remove_notifications(const DoutPrefixProvider *dpp, optio return 0; } -int RGWPubSub::create_topic(const DoutPrefixProvider *dpp, const std::string& name, optional_yield y) const { - return create_topic(dpp, name, rgw_pubsub_dest{}, "", "", y); -} - -int RGWPubSub::create_topic(const DoutPrefixProvider *dpp, const std::string& name, const rgw_pubsub_dest& dest, - const std::string& arn, const std::string& opaque_data, optional_yield y) const { +int RGWPubSub::create_topic(const DoutPrefixProvider* dpp, + const std::string& name, + const rgw_pubsub_dest& dest, const std::string& arn, + const std::string& opaque_data, + const rgw_user& user, optional_yield y) const { RGWObjVersionTracker objv_tracker; rgw_pubsub_topics topics; @@ -693,7 +692,7 @@ int RGWPubSub::create_topic(const DoutPrefixProvider *dpp, const std::string& na } rgw_pubsub_topic& new_topic = topics.topics[name]; - new_topic.user = rgw_user("", tenant); + new_topic.user = user; new_topic.name = name; new_topic.dest = dest; new_topic.arn = arn; diff --git a/src/rgw/rgw_pubsub.h b/src/rgw/rgw_pubsub.h index 290c52c2b8fe5..afab95ba37825 100644 --- a/src/rgw/rgw_pubsub.h +++ b/src/rgw/rgw_pubsub.h @@ -615,12 +615,10 @@ public: // create a topic with a name only // if the topic already exists it is a no-op (considered success) // return 0 on success, error code otherwise - int create_topic(const DoutPrefixProvider *dpp, const std::string& name, optional_yield y) const; - // create a topic with push destination information and ARN - // if the topic already exists the destination and ARN values may be updated (considered succsess) - // return 0 on success, error code otherwise - int create_topic(const DoutPrefixProvider *dpp, const std::string& name, const rgw_pubsub_dest& dest, - const std::string& arn, const std::string& opaque_data, optional_yield y) const; + int create_topic(const DoutPrefixProvider* dpp, const std::string& name, + const rgw_pubsub_dest& dest, const std::string& arn, + const std::string& opaque_data, const rgw_user& user, + optional_yield y) const; // remove a topic according to its name // if the topic does not exists it is a no-op (considered success) // return 0 on success, error code otherwise diff --git a/src/rgw/rgw_rest_pubsub.cc b/src/rgw/rgw_rest_pubsub.cc index 5ab22e63775ef..de898a0931721 100644 --- a/src/rgw/rgw_rest_pubsub.cc +++ b/src/rgw/rgw_rest_pubsub.cc @@ -166,7 +166,8 @@ void RGWPSCreateTopicOp::execute(optional_yield y) { } const RGWPubSub ps(driver, s->owner.get_id().tenant); - op_ret = ps.create_topic(this, topic_name, dest, topic_arn, opaque_data, y); + op_ret = ps.create_topic(this, topic_name, dest, topic_arn, opaque_data, + s->owner.get_id(), y); if (op_ret < 0) { ldpp_dout(this, 1) << "failed to create topic '" << topic_name << "', ret=" << op_ret << dendl; return; @@ -714,7 +715,9 @@ void RGWPSCreateNotifOp::execute(optional_yield y) { // generate the internal topic. destination is stored here for the "push-only" case // when no subscription exists // ARN is cached to make the "GET" method faster - op_ret = ps.create_topic(this, unique_topic_name, topic_info.dest, topic_info.arn, topic_info.opaque_data, y); + op_ret = ps.create_topic(this, unique_topic_name, topic_info.dest, + topic_info.arn, topic_info.opaque_data, + s->owner.get_id(), y); if (op_ret < 0) { ldpp_dout(this, 1) << "failed to auto-generate unique topic '" << unique_topic_name << "', ret=" << op_ret << dendl; diff --git a/src/test/rgw/bucket_notification/test_bn.py b/src/test/rgw/bucket_notification/test_bn.py index a51064dbb52a8..c950400c41178 100644 --- a/src/test/rgw/bucket_notification/test_bn.py +++ b/src/test/rgw/bucket_notification/test_bn.py @@ -35,7 +35,7 @@ from .api import PSTopicS3, \ admin from nose import SkipTest -from nose.tools import assert_not_equal, assert_equal, assert_in +from nose.tools import assert_not_equal, assert_equal, assert_in, assert_true import boto.s3.tagging # configure logging for the tests module @@ -43,6 +43,7 @@ log = logging.getLogger(__name__) TOPIC_SUFFIX = "_topic" NOTIFICATION_SUFFIX = "_notif" +UID_PREFIX = "superman" num_buckets = 0 @@ -531,7 +532,7 @@ def connection2(): def another_user(tenant=None): access_key = str(time.time()) secret_key = str(time.time()) - uid = 'superman' + str(time.time()) + uid = UID_PREFIX + str(time.time()) if tenant: _, result = admin(['user', 'create', '--uid', uid, '--tenant', tenant, '--access-key', access_key, '--secret-key', secret_key, '--display-name', '"Super Man"']) else: @@ -666,6 +667,8 @@ def test_ps_s3_topic_admin_on_master(): result = admin(['topic', 'get', '--topic', topic_name+'_3', '--tenant', tenant]) parsed_result = json.loads(result[0]) assert_equal(parsed_result['arn'], topic_arn3) + matches = [tenant, UID_PREFIX] + assert_true( all([x in parsed_result['user'] for x in matches])) # delete topic 3 _, result = admin(['topic', 'rm', '--topic', topic_name+'_3', '--tenant', tenant]) -- 2.39.5