]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: role: backend handler definition
authorAbhishek Lekshmanan <abhishek@suse.com>
Thu, 15 Oct 2020 13:55:45 +0000 (15:55 +0200)
committerPritha Srivastava <prsrivas@redhat.com>
Mon, 5 Sep 2022 15:36:08 +0000 (21:06 +0530)
Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
(cherry picked from commit ceb7cf9fb07023fbab976ca26c4f1437e97a8d3a)

src/rgw/rgw_role.h
src/rgw/rgw_service.cc
src/rgw/services/svc_role.cc
src/rgw/services/svc_role.h
src/rgw/services/svc_role_rados.cc
src/rgw/services/svc_role_rados.h

index d0cbb072f0c831d1e92c184b3d7b999cb4a930d7..5156a95533cbd6e176aa406ef5e0ab3fd4e6cb7b 100644 (file)
@@ -225,6 +225,7 @@ public:
             RGWRoleMetadataHandler *_rmhandler) {
     svc.role = _role_svc;
     rmhandler = _rmhandler;
+    be_handler = _rmhandler->get_be_handler();
   }
 
   struct PutParams {
index 9fd6a74a361a96dea456f67a1708509b2067253e..33cc903603ee45b2b6841adbfbbb1e3284d0ac8c 100644 (file)
@@ -371,6 +371,7 @@ int RGWCtlDef::init(RGWServices& svc, const DoutPrefixProvider *dpp)
   }
 
   meta.otp.reset(RGWOTPMetaHandlerAllocator::alloc());
+  meta.role = std::make_unique<RGWRoleMetadataHandler>(svc.role);
 
   user.reset(new RGWUserCtl(svc.zone, svc.user, (RGWUserMetadataHandler *)meta.user.get()));
   bucket.reset(new RGWBucketCtl(svc.zone,
@@ -417,10 +418,12 @@ int RGWCtl::init(RGWServices *_svc, const DoutPrefixProvider *dpp)
   meta.bucket = _ctl.meta.bucket.get();
   meta.bucket_instance = _ctl.meta.bucket_instance.get();
   meta.otp = _ctl.meta.otp.get();
+  meta.role = _ctl.meta.role.get();
 
   user = _ctl.user.get();
   bucket = _ctl.bucket.get();
   otp = _ctl.otp.get();
+  role = _ctl.role.get();
 
   r = meta.user->attach(meta.mgr);
   if (r < 0) {
@@ -446,6 +449,11 @@ int RGWCtl::init(RGWServices *_svc, const DoutPrefixProvider *dpp)
     return r;
   }
 
+  r = meta.role->attach(meta.mgr);
+  if (r < 0) {
+    ldout(cct, 0) << "ERROR: failed to start init otp ctl (" << cpp_strerror(-r) << dendl;
+    return r;
+  }
   return 0;
 }
 
index 58bafd7785d5c6ba7370b13fefa3041f789a0b17..6ba09214df03674f3e52a87937d34735358b932e 100644 (file)
@@ -1,10 +1,5 @@
 #include "svc_role.h"
 
-const std::string role_name_oid_prefix = "role_names.";
-const std::string role_oid_prefix = "roles.";
-const std::string role_path_oid_prefix = "role_paths.";
-const std::string role_arn_prefix = "arn:aws:iam::";
-
 std::string RGWSI_Role::get_role_meta_key(const std::string& role_id)
 {
   return role_oid_prefix + role_id;
index c33da97c1b842671ab10541b2909b393ffbf07a8..8ca2d242601986f350f2aa80bc55bf4fb86f64db 100644 (file)
@@ -106,3 +106,8 @@ class RGWSI_Role: public RGWServiceInstance
                          const DoutPrefixProvider *dpp) = 0;
 
 };
+
+const std::string role_name_oid_prefix = "role_names.";
+const std::string role_oid_prefix = "roles.";
+const std::string role_path_oid_prefix = "role_paths.";
+const std::string role_arn_prefix = "arn:aws:iam::";
index 4974de5d36aa6d4f5e4f8e7b95576dae5ae49856..62a9d6a131567947c2c014c56c292679163af20c 100644 (file)
@@ -1,10 +1,50 @@
 #include "svc_role_rados.h"
 #include "svc_meta_be_sobj.h"
+#include "svc_meta.h"
 #include "rgw_role.h"
 #include "rgw_zone.h"
+#include "svc_zone.h"
 
 #define dout_subsys ceph_subsys_rgw
 
+class RGWSI_Role_Module : public RGWSI_MBSObj_Handler_Module {
+  RGWSI_Role_RADOS::Svc& svc;
+  std::string prefix;
+public:
+  RGWSI_Role_Module(RGWSI_Role_RADOS::Svc& _svc): RGWSI_MBSObj_Handler_Module("Role"),
+                                                  svc(_svc) {}
+
+  void get_pool_and_oid(const std::string& key,
+                        rgw_pool *pool,
+                        std::string *oid) override
+  {
+    if (pool) {
+      *pool = svc.zone->get_zone_params().roles_pool;
+    }
+
+    if (oid) {
+      *oid = key;
+    }
+  }
+
+  bool is_valid_oid(const std::string& oid) override {
+    return !boost::algorithm::starts_with(oid, role_name_oid_prefix) ||
+      !boost::algorithm::starts_with(oid, role_path_oid_prefix);
+  }
+
+  std::string key_to_oid(const std::string& key) override {
+    return key;
+  }
+
+  std::string oid_to_key(const std::string& oid) override {
+    return oid;
+  }
+
+  const std::string& get_oid_prefix() {
+    return prefix;
+  }
+};
+
 RGWSI_MetaBackend_Handler* RGWSI_Role_RADOS::get_be_handler()
 {
   return be_handler;
@@ -21,6 +61,24 @@ void RGWSI_Role_RADOS::init(RGWSI_Zone *_zone_svc,
   svc.sysobj = _sysobj_svc;
 }
 
+int RGWSI_Role_RADOS::do_start(optional_yield y, const DoutPrefixProvider *dpp)
+{
+
+  int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ,
+                                      &be_handler);
+  if (r < 0) {
+    ldout(ctx(), 0) << "ERROR: failed to create be_handler for Roles: r="
+                    << r <<dendl;
+    return r;
+  }
+
+  auto module = new RGWSI_Role_Module(svc);
+  RGWSI_MetaBackend_Handler_SObj* bh= static_cast<RGWSI_MetaBackend_Handler_SObj *>(be_handler);
+  be_module.reset(module);
+  bh->set_module(module);
+  return 0;
+}
+
 int RGWSI_Role_RADOS::store_info(RGWSI_MetaBackend::Context *ctx,
                                  const rgw::sal::RGWRole& role,
                                  RGWObjVersionTracker * const objv_tracker,
index cb79d9a797aa19f71544ebf86e6c142d0732145a..4ab74d4719ec012c4f733e48e9d165105d430e56 100644 (file)
@@ -37,6 +37,7 @@ class RGWSI_Role_RADOS: public RGWSI_Role
            RGWSI_SysObj *_sysobj_svc);
 
   RGWSI_MetaBackend_Handler * get_be_handler() override;
+  int do_start(optional_yield y, const DoutPrefixProvider *dpp) override;
 
   int store_info(RGWSI_MetaBackend::Context *ctx,
                 const rgw::sal::RGWRole& role,