]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/sal: add interfaces for account roles
authorCasey Bodley <cbodley@redhat.com>
Sun, 31 Dec 2023 04:35:53 +0000 (23:35 -0500)
committerCasey Bodley <cbodley@redhat.com>
Wed, 10 Apr 2024 17:09:14 +0000 (13:09 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/driver/rados/rgw_sal_rados.cc
src/rgw/driver/rados/rgw_sal_rados.h
src/rgw/rgw_sal.h
src/rgw/rgw_sal_dbstore.cc
src/rgw/rgw_sal_dbstore.h
src/rgw/rgw_sal_filter.cc
src/rgw/rgw_sal_filter.h
src/rgw/rgw_sal_fwd.h

index 5b3ddfefec7899bf802f94e943cb5fb37406c736..79431b3521e0d63802f4fec0f89773e841da230e 100644 (file)
@@ -70,6 +70,7 @@
 
 #include "account.h"
 #include "buckets.h"
+#include "roles.h"
 #include "users.h"
 #include "rgw_pubsub.h"
 #include "topic.h"
@@ -1199,6 +1200,80 @@ int RadosStore::load_owner_by_email(const DoutPrefixProvider* dpp,
   return 0;
 }
 
+int RadosStore::load_account_role_by_name(const DoutPrefixProvider* dpp,
+                                          optional_yield y,
+                                          std::string_view account_id,
+                                          std::string_view rolename,
+                                          std::unique_ptr<RGWRole>* role)
+{
+  std::string id;
+  librados::Rados& rados = *getRados()->get_rados_handle();
+  const RGWZoneParams& zone = svc()->zone->get_zone_params();
+  const rgw_raw_obj& obj = rgwrados::account::get_roles_obj(zone, account_id);
+  int r = rgwrados::roles::get(dpp, y, rados, obj, rolename, id);
+  if (r < 0) {
+    ldpp_dout(dpp, 20) << "failed to find account rolename " << rolename
+        << ": " << cpp_strerror(r) << dendl;
+    return r;
+  }
+
+  std::unique_ptr<RGWRole> p = get_role(id);
+  r = p->read_info(dpp, y);
+  if (r < 0) {
+    ldpp_dout(dpp, 20) << "failed to load account role " << id
+        << ": " << cpp_strerror(r) << dendl;
+    return r;
+  }
+  *role = std::move(p);
+  return 0;
+}
+
+int RadosStore::count_account_roles(const DoutPrefixProvider* dpp,
+                                    optional_yield y,
+                                    std::string_view account_id,
+                                    uint32_t& count)
+{
+  librados::Rados& rados = *getRados()->get_rados_handle();
+  const RGWZoneParams& zone = svc()->zone->get_zone_params();
+  const rgw_raw_obj& obj = rgwrados::account::get_roles_obj(zone, account_id);
+  return rgwrados::account::resource_count(dpp, y, rados, obj, count);
+}
+
+int RadosStore::list_account_roles(const DoutPrefixProvider* dpp,
+                                   optional_yield y,
+                                   std::string_view account_id,
+                                   std::string_view path_prefix,
+                                   std::string_view marker,
+                                   uint32_t max_items,
+                                   RoleList& listing)
+{
+  // fetch the list of role ids from cls_role
+  librados::Rados& rados = *getRados()->get_rados_handle();
+  const RGWZoneParams& zone = svc()->zone->get_zone_params();
+  const rgw_raw_obj& obj = rgwrados::account::get_roles_obj(zone, account_id);
+  std::vector<std::string> ids;
+  int r = rgwrados::roles::list(dpp, y, rados, obj, marker, path_prefix,
+                                max_items, ids, listing.next_marker);
+  if (r < 0) {
+    return r;
+  }
+
+  // load the role metadata for each
+  for (const auto& id : ids) {
+    std::unique_ptr<rgw::sal::RGWRole> role = get_role(id);
+    r = role->read_info(dpp, y);
+    if (r == -ENOENT) {
+      continue;
+    }
+    if (r < 0) {
+      return r;
+    }
+    listing.roles.push_back(std::move(role->get_info()));
+  }
+
+  return 0;
+}
+
 int RadosStore::load_account_user_by_name(const DoutPrefixProvider* dpp,
                                           optional_yield y,
                                           std::string_view account_id,
index b152fadc3c8c63a427e285a74edf1147739f5a4d..7702fd3a8f2ec818cb747c18057c9c4065487091 100644 (file)
@@ -196,6 +196,23 @@ class RadosStore : public StoreDriver {
                             std::string_view email,
                             rgw_owner& owner) override;
 
+    int load_account_role_by_name(const DoutPrefixProvider* dpp,
+                                  optional_yield y,
+                                  std::string_view account_id,
+                                  std::string_view name,
+                                  std::unique_ptr<RGWRole>* role) override;
+    int count_account_roles(const DoutPrefixProvider* dpp,
+                            optional_yield y,
+                            std::string_view account_id,
+                            uint32_t& count) override;
+    int list_account_roles(const DoutPrefixProvider* dpp,
+                           optional_yield y,
+                           std::string_view account_id,
+                           std::string_view path_prefix,
+                           std::string_view marker,
+                           uint32_t max_items,
+                           RoleList& listing) override;
+
     int load_account_user_by_name(const DoutPrefixProvider* dpp,
                                   optional_yield y,
                                   std::string_view account_id,
index b775a48f4eed87d9c674633a1584ac0c34efb124..d2e0e0f03d2ad78abbfd8de458dde370bad9ad09 100644 (file)
@@ -243,6 +243,14 @@ struct BucketList {
   std::string next_marker;
 };
 
+/// A list of roles
+struct RoleList {
+  /// The list of results, sorted by name
+  std::vector<RGWRoleInfo> roles;
+  /// The next marker to resume listing, or empty
+  std::string next_marker;
+};
+
 /// A list of users
 struct UserList {
   /// The list of results, sorted by name
@@ -350,6 +358,26 @@ class Driver {
                                     std::string_view email,
                                     rgw_owner& owner) = 0;
 
+    /** Load an account's role by name. */
+    virtual int load_account_role_by_name(const DoutPrefixProvider* dpp,
+                                          optional_yield y,
+                                          std::string_view account_id,
+                                          std::string_view name,
+                                          std::unique_ptr<RGWRole>* role) = 0;
+    /** Count the number of roles belonging to the given account. */
+    virtual int count_account_roles(const DoutPrefixProvider* dpp,
+                                    optional_yield y,
+                                    std::string_view account_id,
+                                    uint32_t& count) = 0;
+    /** Return a paginated listing of the account's roles. */
+    virtual int list_account_roles(const DoutPrefixProvider* dpp,
+                                   optional_yield y,
+                                   std::string_view account_id,
+                                   std::string_view path_prefix,
+                                   std::string_view marker,
+                                   uint32_t max_items,
+                                   RoleList& listing) = 0;
+
     /** Load an account's user by username. */
     virtual int load_account_user_by_name(const DoutPrefixProvider* dpp,
                                           optional_yield y,
index 972becb391aaadf6abac05c7f69f7bd9dff43683..bfd05e5d51112aa03eeb9c3919416aa073c2a582 100644 (file)
@@ -1617,6 +1617,34 @@ namespace rgw::sal {
     return 0;
   }
 
+  int DBStore::load_account_role_by_name(const DoutPrefixProvider* dpp,
+                                         optional_yield y,
+                                         std::string_view account_id,
+                                         std::string_view name,
+                                         std::unique_ptr<RGWRole>* role)
+  {
+    return -ENOTSUP;
+  }
+
+  int DBStore::count_account_roles(const DoutPrefixProvider* dpp,
+                                   optional_yield y,
+                                   std::string_view account_id,
+                                   uint32_t& count)
+  {
+    return -ENOTSUP;
+  }
+
+  int DBStore::list_account_roles(const DoutPrefixProvider* dpp,
+                                  optional_yield y,
+                                  std::string_view account_id,
+                                  std::string_view path_prefix,
+                                  std::string_view marker,
+                                  uint32_t max_items,
+                                  RoleList& listing)
+  {
+    return -ENOTSUP;
+  }
+
   int DBStore::load_account_user_by_name(const DoutPrefixProvider* dpp,
                                          optional_yield y,
                                          std::string_view account_id,
index a278fd8c593b980e0d5da2b773701c69d09c2788..7a28bcc1a4f64cdacb8c5174a3a8badcff853794 100644 (file)
@@ -795,6 +795,23 @@ public:
                               std::string_view email,
                               rgw_owner& owner) override;
 
+      int load_account_role_by_name(const DoutPrefixProvider* dpp,
+                                    optional_yield y,
+                                    std::string_view account_id,
+                                    std::string_view name,
+                                    std::unique_ptr<RGWRole>* role) override;
+      int count_account_roles(const DoutPrefixProvider* dpp,
+                              optional_yield y,
+                              std::string_view account_id,
+                              uint32_t& count) override;
+      int list_account_roles(const DoutPrefixProvider* dpp,
+                             optional_yield y,
+                             std::string_view account_id,
+                             std::string_view path_prefix,
+                             std::string_view marker,
+                             uint32_t max_items,
+                             RoleList& listing) override;
+
       int load_account_user_by_name(const DoutPrefixProvider* dpp,
                                     optional_yield y,
                                     std::string_view account_id,
index eca1529b2beb1f9e8a19e565e595df2026edccbd..4fe26e1c7e27fc19b58cd31eb178eb22a823c479 100644 (file)
@@ -243,6 +243,35 @@ int FilterDriver::load_owner_by_email(const DoutPrefixProvider* dpp,
   return next->load_owner_by_email(dpp, y, email, owner);
 }
 
+int FilterDriver::load_account_role_by_name(const DoutPrefixProvider* dpp,
+                                            optional_yield y,
+                                            std::string_view account_id,
+                                            std::string_view name,
+                                            std::unique_ptr<RGWRole>* role)
+{
+  return next->load_account_role_by_name(dpp, y, account_id, name, role);
+}
+
+int FilterDriver::count_account_roles(const DoutPrefixProvider* dpp,
+                                      optional_yield y,
+                                      std::string_view account_id,
+                                      uint32_t& count)
+{
+  return next->count_account_roles(dpp, y, account_id, count);
+}
+
+int FilterDriver::list_account_roles(const DoutPrefixProvider* dpp,
+                                     optional_yield y,
+                                     std::string_view account_id,
+                                     std::string_view path_prefix,
+                                     std::string_view marker,
+                                     uint32_t max_items,
+                                     RoleList& listing)
+{
+  return next->list_account_roles(dpp, y, account_id, path_prefix,
+                                  marker, max_items, listing);
+}
+
 int FilterDriver::load_account_user_by_name(const DoutPrefixProvider* dpp,
                                             optional_yield y,
                                             std::string_view account_id,
index 09dbe8efb0cfabc47002dbdc16e5059697b4aa52..5dfa6c209a93388e7c207ccfc7fbafe393de3529 100644 (file)
@@ -206,6 +206,22 @@ public:
                           optional_yield y,
                           std::string_view email,
                           rgw_owner& owner) override;
+  int load_account_role_by_name(const DoutPrefixProvider* dpp,
+                                optional_yield y,
+                                std::string_view account_id,
+                                std::string_view name,
+                                std::unique_ptr<RGWRole>* role) override;
+  int count_account_roles(const DoutPrefixProvider* dpp,
+                          optional_yield y,
+                          std::string_view account_id,
+                          uint32_t& count) override;
+  int list_account_roles(const DoutPrefixProvider* dpp,
+                         optional_yield y,
+                         std::string_view account_id,
+                         std::string_view path_prefix,
+                         std::string_view marker,
+                         uint32_t max_items,
+                         RoleList& listing) override;
   int load_account_user_by_name(const DoutPrefixProvider* dpp,
                                 optional_yield y,
                                 std::string_view account_id,
index 1ba59dc821f4344a317e9c25d1b8e915f9937e52..3019c06c5188edf88274c7f1d5c97274411f23d7 100644 (file)
@@ -46,6 +46,8 @@ namespace sal {
   class Zone;
   class LuaManager;
   struct RGWRoleInfo;
+  class RGWRole;
+  struct RoleList;
   class DataProcessor;
   class ObjectProcessor;
   class ReadStatsCB;