From f646ebf543686f5fc01ae60b9ad1a72324da54ba Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 16 Nov 2023 13:59:57 -0500 Subject: [PATCH] rgw/acl/swift: format_account_acl() as free function Signed-off-by: Casey Bodley --- src/rgw/rgw_acl_swift.cc | 13 ++++++++----- src/rgw/rgw_acl_swift.h | 8 +++++--- src/rgw/rgw_rest_swift.cc | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_acl_swift.cc b/src/rgw/rgw_acl_swift.cc index 16b03e41ab6c7..048f7b4915215 100644 --- a/src/rgw/rgw_acl_swift.cc +++ b/src/rgw/rgw_acl_swift.cc @@ -324,16 +324,17 @@ int create_account_policy(const DoutPrefixProvider* dpp, return 0; } -} // namespace rgw::swift - -boost::optional RGWAccessControlPolicy_SWIFTAcct::to_str() const +auto format_account_acl(const RGWAccessControlPolicy& policy) + -> std::optional { + const ACLOwner& owner = policy.get_owner(); + std::vector admin; std::vector readwrite; std::vector readonly; /* Partition the grant map into three not-overlapping groups. */ - for (const auto& item : get_acl().get_grant_map()) { + for (const auto& item : policy.get_acl().get_grant_map()) { const ACLGrant& grant = item.second; const uint32_t perm = grant.get_permission().get_permissions(); @@ -361,7 +362,7 @@ boost::optional RGWAccessControlPolicy_SWIFTAcct::to_str() const /* If there is no grant to serialize, let's exit earlier to not return * an empty JSON object which brakes the functional tests of Swift. */ if (admin.empty() && readwrite.empty() && readonly.empty()) { - return boost::none; + return std::nullopt; } /* Serialize the groups. */ @@ -384,3 +385,5 @@ boost::optional RGWAccessControlPolicy_SWIFTAcct::to_str() const return oss.str(); } + +} // namespace rgw::swift diff --git a/src/rgw/rgw_acl_swift.h b/src/rgw/rgw_acl_swift.h index dbe89efef796d..9eeb9cb6caeaf 100644 --- a/src/rgw/rgw_acl_swift.h +++ b/src/rgw/rgw_acl_swift.h @@ -8,7 +8,6 @@ #include #include -#include #include "rgw_acl.h" @@ -44,6 +43,11 @@ int create_account_policy(const DoutPrefixProvider* dpp, const std::string& acl_str, RGWAccessControlPolicy& policy); +/// Format the policy in terms of the X-Account-Access-Control string. Returns +/// std::nullopt if there are no admin/read-write/read-only entries. +auto format_account_acl(const RGWAccessControlPolicy& policy) + -> std::optional; + } // namespace rgw::swift class RGWAccessControlPolicy_SWIFT : public RGWAccessControlPolicy @@ -52,6 +56,4 @@ class RGWAccessControlPolicy_SWIFT : public RGWAccessControlPolicy class RGWAccessControlPolicy_SWIFTAcct : public RGWAccessControlPolicy { -public: - boost::optional to_str() const; }; diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index b5ac5a427c3fb..a752e827b12c2 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -164,8 +164,8 @@ static void dump_account_metadata(req_state * const s, } } - /* Dump account ACLs */ - auto account_acls = policy.to_str(); + /* Dump account ACLs, if any */ + auto account_acls = rgw::swift::format_account_acl(policy); if (account_acls) { dump_header(s, "X-Account-Access-Control", std::move(*account_acls)); } -- 2.39.5