From 1534f8f249bf679e1c520748c0b65ddca2535c35 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 12 Mar 2024 16:26:44 -0400 Subject: [PATCH] rgw/pubsub: return 404 NotFound instead of NoSuchKey repurpose the ERR_NOT_FOUND define which was otherwise unused to customize the error response for sns apis, which return the NotFound error code instead of NoSuchKey from s3: https://docs.aws.amazon.com/sns/latest/api/API_GetTopicAttributes.html#API_GetTopicAttributes_Errors this allows boto3 sns clients to catch the NotFoundException as expected Signed-off-by: Casey Bodley (cherry picked from commit 2cdddad82ecfc80e03a0b6269eee5981ab5b76f0) --- src/rgw/rgw_common.cc | 2 +- src/rgw/rgw_rest_pubsub.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 6e20c2b145c02..53244e4436668 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -96,7 +96,7 @@ rgw_http_errors rgw_http_s3_errors({ { ERR_NO_SUCH_BUCKET, {404, "NoSuchBucket" }}, { ERR_NO_SUCH_WEBSITE_CONFIGURATION, {404, "NoSuchWebsiteConfiguration" }}, { ERR_NO_SUCH_UPLOAD, {404, "NoSuchUpload" }}, - { ERR_NOT_FOUND, {404, "Not Found"}}, + { ERR_NOT_FOUND, {404, "NotFound"}}, { ERR_NO_SUCH_LC, {404, "NoSuchLifecycleConfiguration"}}, { ERR_NO_SUCH_BUCKET_POLICY, {404, "NoSuchBucketPolicy"}}, { ERR_NO_SUCH_USER, {404, "NoSuchUser"}}, diff --git a/src/rgw/rgw_rest_pubsub.cc b/src/rgw/rgw_rest_pubsub.cc index eeba1a060ae51..7db88ceddda3f 100644 --- a/src/rgw/rgw_rest_pubsub.cc +++ b/src/rgw/rgw_rest_pubsub.cc @@ -512,6 +512,10 @@ class RGWPSGetTopicOp : public RGWOp { ret = ps.get_topic(this, topic_name, result, y, nullptr); if (ret < 0) { ldpp_dout(this, 4) << "failed to get topic '" << topic_name << "', ret=" << ret << dendl; + if (ret == -ENOENT) { + s->err.message = "No such TopicArn"; + return -ERR_NOT_FOUND; // return NotFound instead of NoSuchKey + } return ret; } if (topic_has_endpoint_secret(result) && !verify_transport_security(s->cct, *(s->info.env))) { @@ -594,6 +598,10 @@ class RGWPSGetTopicAttributesOp : public RGWOp { ret = ps.get_topic(this, topic_name, result, y, nullptr); if (ret < 0) { ldpp_dout(this, 4) << "failed to get topic '" << topic_name << "', ret=" << ret << dendl; + if (ret == -ENOENT) { + s->err.message = "No such TopicArn"; + return -ERR_NOT_FOUND; // return NotFound instead of NoSuchKey + } return ret; } if (topic_has_endpoint_secret(result) && !verify_transport_security(s->cct, *(s->info.env))) { @@ -755,6 +763,10 @@ class RGWPSSetTopicAttributesOp : public RGWOp { if (ret < 0) { ldpp_dout(this, 4) << "failed to get topic '" << topic_name << "', ret=" << ret << dendl; + if (ret == -ENOENT) { + s->err.message = "No such TopicArn"; + return -ERR_NOT_FOUND; // return NotFound instead of NoSuchKey + } return ret; } topic_owner = result.owner; -- 2.39.5