]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/acl/swift: format_account_acl() as free function
authorCasey Bodley <cbodley@redhat.com>
Thu, 16 Nov 2023 18:59:57 +0000 (13:59 -0500)
committerCasey Bodley <cbodley@redhat.com>
Thu, 30 Nov 2023 15:58:48 +0000 (10:58 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_acl_swift.cc
src/rgw/rgw_acl_swift.h
src/rgw/rgw_rest_swift.cc

index 16b03e41ab6c798341647510ab14bb4d90583ada..048f7b4915215c3de06230c17383314d5df7deb6 100644 (file)
@@ -324,16 +324,17 @@ int create_account_policy(const DoutPrefixProvider* dpp,
   return 0;
 }
 
-} // namespace rgw::swift
-
-boost::optional<std::string> RGWAccessControlPolicy_SWIFTAcct::to_str() const
+auto format_account_acl(const RGWAccessControlPolicy& policy)
+  -> std::optional<std::string>
 {
+  const ACLOwner& owner = policy.get_owner();
+
   std::vector<std::string> admin;
   std::vector<std::string> readwrite;
   std::vector<std::string> 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<std::string> 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<std::string> RGWAccessControlPolicy_SWIFTAcct::to_str() const
 
   return oss.str();
 }
+
+} // namespace rgw::swift
index dbe89efef796d583227119e4c8dd5a7df7a8c866..9eeb9cb6caeafdfbca8972ab42e88ffa7f19f946 100644 (file)
@@ -8,7 +8,6 @@
 #include <string>
 #include <include/types.h>
 
-#include <boost/optional.hpp>
 
 #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<std::string>;
+
 } // 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<std::string> to_str() const;
 };
index b5ac5a427c3fba549499cdf9695887f4310c74e1..a752e827b12c2e4ed55d6acbde7bb3f3a06ce518 100644 (file)
@@ -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));
   }