From: Abhishek Lekshmanan Date: Thu, 15 Oct 2020 13:55:45 +0000 (+0200) Subject: rgw: role: backend handler definition X-Git-Tag: v17.2.6~119^2~33 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2cd67cad46fd578a78ff4228b71b27abea7a5f91;p=ceph.git rgw: role: backend handler definition Signed-off-by: Abhishek Lekshmanan (cherry picked from commit ceb7cf9fb07023fbab976ca26c4f1437e97a8d3a) --- diff --git a/src/rgw/rgw_role.h b/src/rgw/rgw_role.h index d0cbb072f0c8..5156a95533cb 100644 --- a/src/rgw/rgw_role.h +++ b/src/rgw/rgw_role.h @@ -225,6 +225,7 @@ public: RGWRoleMetadataHandler *_rmhandler) { svc.role = _role_svc; rmhandler = _rmhandler; + be_handler = _rmhandler->get_be_handler(); } struct PutParams { diff --git a/src/rgw/rgw_service.cc b/src/rgw/rgw_service.cc index 9fd6a74a361a..33cc903603ee 100644 --- a/src/rgw/rgw_service.cc +++ b/src/rgw/rgw_service.cc @@ -371,6 +371,7 @@ int RGWCtlDef::init(RGWServices& svc, const DoutPrefixProvider *dpp) } meta.otp.reset(RGWOTPMetaHandlerAllocator::alloc()); + meta.role = std::make_unique(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; } diff --git a/src/rgw/services/svc_role.cc b/src/rgw/services/svc_role.cc index 58bafd7785d5..6ba09214df03 100644 --- a/src/rgw/services/svc_role.cc +++ b/src/rgw/services/svc_role.cc @@ -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; diff --git a/src/rgw/services/svc_role.h b/src/rgw/services/svc_role.h index c33da97c1b84..8ca2d2426019 100644 --- a/src/rgw/services/svc_role.h +++ b/src/rgw/services/svc_role.h @@ -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::"; diff --git a/src/rgw/services/svc_role_rados.cc b/src/rgw/services/svc_role_rados.cc index 4974de5d36aa..62a9d6a13156 100644 --- a/src/rgw/services/svc_role_rados.cc +++ b/src/rgw/services/svc_role_rados.cc @@ -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 <(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, diff --git a/src/rgw/services/svc_role_rados.h b/src/rgw/services/svc_role_rados.h index cb79d9a797aa..4ab74d4719ec 100644 --- a/src/rgw/services/svc_role_rados.h +++ b/src/rgw/services/svc_role_rados.h @@ -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,