From ade871e280cdfe0057e8f0b1f6ab0b3d152cc1f2 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 16 Nov 2023 13:33:30 -0500 Subject: [PATCH] rgw/acl/swift: format_container_acls() as free function Signed-off-by: Casey Bodley --- src/rgw/rgw_acl_swift.cc | 13 +++++-------- src/rgw/rgw_acl_swift.h | 6 ++++-- src/rgw/rgw_rest_swift.cc | 4 +--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/rgw/rgw_acl_swift.cc b/src/rgw/rgw_acl_swift.cc index 4bf0ba9251774..e948e859162bf 100644 --- a/src/rgw/rgw_acl_swift.cc +++ b/src/rgw/rgw_acl_swift.cc @@ -226,15 +226,10 @@ void merge_policy(uint32_t rw_mask, const RGWAccessControlPolicy& src, } } -} // namespace rgw::swift - -void RGWAccessControlPolicy_SWIFT::to_str(string& read, string& write) +void format_container_acls(const RGWAccessControlPolicy& policy, + std::string& read, std::string& write) { - multimap& m = acl.get_grant_map(); - multimap::iterator iter; - - for (iter = m.begin(); iter != m.end(); ++iter) { - ACLGrant& grant = iter->second; + for (const auto& [k, grant] : policy.get_acl().get_grant_map()) { const uint32_t perm = grant.get_permission().get_permissions(); rgw_user id; string url_spec; @@ -269,6 +264,8 @@ void RGWAccessControlPolicy_SWIFT::to_str(string& read, string& write) } } +} // namespace rgw::swift + void RGWAccessControlPolicy_SWIFTAcct::add_grants(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver, const std::vector& uids, diff --git a/src/rgw/rgw_acl_swift.h b/src/rgw/rgw_acl_swift.h index bf983ba2b8c27..8bc70eac7b0ef 100644 --- a/src/rgw/rgw_acl_swift.h +++ b/src/rgw/rgw_acl_swift.h @@ -32,12 +32,14 @@ int create_container_policy(const DoutPrefixProvider *dpp, void merge_policy(uint32_t rw_mask, const RGWAccessControlPolicy& src, RGWAccessControlPolicy& dest); +/// Format the policy in terms of X-Container-Read/X-Container-Write strings. +void format_container_acls(const RGWAccessControlPolicy& policy, + std::string& read, std::string& write); + } // namespace rgw::swift class RGWAccessControlPolicy_SWIFT : public RGWAccessControlPolicy { -public: - void to_str(std::string& read, std::string& write); }; class RGWAccessControlPolicy_SWIFTAcct : public RGWAccessControlPolicy diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index b486042e00f85..930156d4b5127 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -470,10 +470,8 @@ static void dump_container_metadata(req_state *s, } if (rgw::sal::Object::empty(s->object.get())) { - auto swift_policy = \ - static_cast(s->bucket_acl.get()); std::string read_acl, write_acl; - swift_policy->to_str(read_acl, write_acl); + rgw::swift::format_container_acls(*s->bucket_acl, read_acl, write_acl); if (read_acl.size()) { dump_header(s, "X-Container-Read", read_acl); -- 2.39.5