]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
RGW Zipper - Clean up get_user* APIs.
authorDaniel Gryniewicz <dang@redhat.com>
Tue, 19 Jan 2021 18:13:37 +0000 (13:13 -0500)
committerDaniel Gryniewicz <dang@redhat.com>
Tue, 2 Mar 2021 12:35:05 +0000 (07:35 -0500)
The main get_user() function doesn't query the cluster, but the rest of
them do.  Rename the functions to match, and add comments to clarify.

Signed-off-by: Daniel Gryniewicz <dang@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_file.h
src/rgw/rgw_lua.cc
src/rgw/rgw_lua.h
src/rgw/rgw_op.cc
src/rgw/rgw_process.cc
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_sal.h
src/rgw/rgw_sal_rados.cc
src/rgw/rgw_sal_rados.h
src/rgw/rgw_user.cc

index 373f7300d35a1c847dde1e7c5eb5f532bc0807a3..94ee98bbbf3f00473f758f6ec310e2aae8c9f228 100644 (file)
@@ -9255,7 +9255,7 @@ next:
       return EINVAL;
     }
     std::string script;
-    const auto rc = rgw::lua::read_script(store, tenant, null_yield, script_ctx, script);
+    const auto rc = rgw::lua::read_script(dpp(), store, tenant, null_yield, script_ctx, script);
     if (rc == -ENOENT) {
       std::cout << "no script exists for context: " << *str_script_ctx << 
         (tenant.empty() ? "" : (" in tenant: " + tenant)) << std::endl;
index b43eff8f17aa7a681e6d7cb7389451a02fa73d53..b63bca1047104370e2cf29df5195c3825bf49600 100644 (file)
@@ -985,7 +985,7 @@ namespace rgw {
     }
 
     int authorize(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store) {
-      int ret = store->get_user(dpp, key, null_yield, &user);
+      int ret = store->get_user_by_access_key(dpp, key.id, null_yield, &user);
       if (ret == 0) {
        RGWAccessKey* k = user->get_info().get_key(key.id);
        if (!k || (k->key != key.key))
@@ -1297,7 +1297,7 @@ namespace rgw {
     RGWUserInfo* get_user() { return &user->get_info(); }
 
     void update_user(const DoutPrefixProvider *dpp) {
-      (void) rgwlib.get_store()->get_user(dpp, key, null_yield, &user);
+      (void) rgwlib.get_store()->get_user_by_access_key(dpp, key.id, null_yield, &user);
     }
 
     void close();
index c86642181e4be18f8a5f9cfd5115f52fa40d2cd2..8eed171da7fb5df21e7fba65d6835bc3f8565bd5 100644 (file)
@@ -63,17 +63,16 @@ std::string script_oid(context ctx, const std::string& tenant) {
 }
 
 
-int read_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, std::string& script)
+int read_script(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, std::string& script)
 {
-  RGWSysObjectCtx obj_ctx(static_cast<rgw::sal::RGWRadosStore*>(store)->svc()->sysobj->init_obj_ctx());
   RGWObjVersionTracker objv_tracker;
 
   rgw_raw_obj obj(store->get_zone_params().log_pool, script_oid(ctx, tenant));
 
   bufferlist bl;
   
-  const auto rc = rgw_get_system_obj(
-      obj_ctx,
+  const auto rc = store->get_system_obj(
+      dpp,
       obj.pool, 
       obj.oid,
       bl,
@@ -99,7 +98,6 @@ int read_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_y
 
 int write_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, const std::string& script)
 {
-  RGWSysObjectCtx obj_ctx(static_cast<rgw::sal::RGWRadosStore*>(store)->svc()->sysobj->init_obj_ctx());
   RGWObjVersionTracker objv_tracker;
 
   rgw_raw_obj obj(store->get_zone_params().log_pool, script_oid(ctx, tenant));
@@ -107,8 +105,7 @@ int write_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_
   bufferlist bl;
   ceph::encode(script, bl);
 
-  const auto rc = rgw_put_system_obj(
-      obj_ctx,
+  const auto rc = store->put_system_obj(
       obj.pool,
       obj.oid,
       bl,
@@ -130,8 +127,7 @@ int delete_script(rgw::sal::RGWStore* store, const std::string& tenant, optional
 
   rgw_raw_obj obj(store->get_zone_params().log_pool, script_oid(ctx, tenant));
 
-  const auto rc = rgw_delete_system_obj(
-      static_cast<rgw::sal::RGWRadosStore*>(store)->svc()->sysobj,
+  const auto rc = store->delete_system_obj(
       obj.pool,
       obj.oid,
       &objv_tracker,
index 296b9a71d57ddaf45efe02965a4ef8c5c86beda7..73ed5178702e53566e84e27fdc10419dcf1d1562 100644 (file)
@@ -29,7 +29,7 @@ bool verify(const std::string& script, std::string& err_msg);
 int write_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, const std::string& script);
 
 // read the stored lua script from a context
-int read_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, std::string& script);
+int read_script(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, std::string& script);
 
 // delete the stored lua script from a context
 int delete_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx);
index 8ccbfce34670b373e1236066a7c757a9b70e62b2..335399324d4f45645d2f85629d273ad2a18b3a64 100644 (file)
@@ -4405,10 +4405,11 @@ int RGWPutMetadataAccount::verify_permission(optional_yield y)
 void RGWPutMetadataAccount::execute(optional_yield y)
 {
   /* Params have been extracted earlier. See init_processing(). */
-  op_ret = s->user->load_by_id(this, y, RGWUserCtl::GetParams().set_objv_tracker(&acct_op_tracker));
+  op_ret = s->user->load_by_id(this, y);
   if (op_ret < 0) {
     return;
   }
+  acct_op_tracker = s->user->get_version_tracker();
 
   /* Handle the TempURL-related stuff. */
   if (!temp_url_keys.empty()) {
index d60c9c5a11c8436cdf4978d9c7fd0986466eb541..6800ff0e5e04926d21b2d1b2eff99a45b24d53da 100644 (file)
@@ -240,7 +240,7 @@ int process_request(rgw::sal::RGWStore* const store,
   }
   {
     std::string script;
-    auto rc = rgw::lua::read_script(store, s->bucket_tenant, s->yield, rgw::lua::context::preRequest, script);
+    auto rc = rgw::lua::read_script(s, store, s->bucket_tenant, s->yield, rgw::lua::context::preRequest, script);
     if (rc == -ENOENT) {
       // no script, nothing to do
     } else if (rc < 0) {
@@ -308,7 +308,7 @@ int process_request(rgw::sal::RGWStore* const store,
 done:
   if (op) {
     std::string script;
-    auto rc = rgw::lua::read_script(store, s->bucket_tenant, s->yield, rgw::lua::context::postRequest, script);
+    auto rc = rgw::lua::read_script(s, store, s->bucket_tenant, s->yield, rgw::lua::context::postRequest, script);
     if (rc == -ENOENT) {
       // no script, nothing to do
     } else if (rc < 0) {
index 989c8fe31a44874b3bdb09670f76d57348614f2b..85c55ba1071c0467ea74311b47abdaf45158c0f5 100644 (file)
@@ -5721,11 +5721,10 @@ rgw::auth::s3::LocalEngine::authenticate(
 {
   /* get the user info */
   std::unique_ptr<rgw::sal::RGWUser> user;
+  const std::string access_key_id(_access_key_id);
   /* TODO(rzarzynski): we need to have string-view taking variant. */
-  RGWAccessKey access_key;
-  access_key.id = _access_key_id;
-  if (store->get_user(dpp, access_key, y, &user) < 0) {
-      ldpp_dout(dpp, 5) << "error reading user info, uid=" << access_key.id
+  if (store->get_user_by_access_key(dpp, access_key_id, y, &user) < 0) {
+      ldpp_dout(dpp, 5) << "error reading user info, uid=" << access_key_id
               << " can't authenticate" << dendl;
       return result_t::deny(-ERR_INVALID_ACCESS_KEY);
   }
@@ -5738,7 +5737,7 @@ rgw::auth::s3::LocalEngine::authenticate(
     }
   }*/
 
-  const auto iter = user->get_info().access_keys.find(access_key.id);
+  const auto iter = user->get_info().access_keys.find(access_key_id);
   if (iter == std::end(user->get_info().access_keys)) {
     ldpp_dout(dpp, 0) << "ERROR: access key not encoded in user info" << dendl;
     return result_t::deny(-EPERM);
index eaa090ac9ff9f51a720552a77efeb2512f7a931f..7a742f3c9c4137d1cdd2bd19b953d56c04b94462 100644 (file)
@@ -126,8 +126,10 @@ class RGWStore {
     RGWStore() {}
     virtual ~RGWStore() = default;
 
+    /* This one does not query the cluster for info */
     virtual std::unique_ptr<RGWUser> get_user(const rgw_user& u) = 0;
-    virtual int get_user(const DoutPrefixProvider *dpp, const RGWAccessKey& key, optional_yield y, std::unique_ptr<RGWUser>* user) = 0;
+    /* These three do query the cluster for info */
+    virtual int get_user_by_access_key(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y, std::unique_ptr<RGWUser>* user) = 0;
     virtual int get_user_by_email(const DoutPrefixProvider *dpp, const std::string& email, optional_yield y, std::unique_ptr<RGWUser>* user) = 0;
     virtual int get_user_by_swift(const DoutPrefixProvider *dpp, const std::string& user_str, optional_yield y, std::unique_ptr<RGWUser>* user) = 0;
     virtual std::unique_ptr<RGWObject> get_object(const rgw_obj_key& k) = 0;
@@ -228,6 +230,7 @@ class RGWStore {
 class RGWUser {
   protected:
     RGWUserInfo info;
+    RGWObjVersionTracker objv_tracker;
 
   public:
     RGWUser() : info() {}
@@ -265,9 +268,10 @@ class RGWUser {
                           bool *is_truncated, RGWUsageIter& usage_iter,
                           map<rgw_user_bucket, rgw_usage_log_entry>& usage) = 0;
     virtual int trim_usage(uint64_t start_epoch, uint64_t end_epoch) = 0;
+    virtual RGWObjVersionTracker& get_version_tracker() { return objv_tracker; }
 
     /* Placeholders */
-    virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::GetParams& params = {}) = 0;
+    virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y) = 0;
     virtual int store_info(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::PutParams& params = {}) = 0;
 
     /* dang temporary; will be removed when User is complete */
index 3fc2e12e3133b992dc84e3d5cfebaabc37eefc68..5f4b385bc2f3d80a37c2bba791a94f8477174ede 100644 (file)
@@ -187,9 +187,9 @@ int RGWRadosUser::trim_usage(uint64_t start_epoch, uint64_t end_epoch)
   return store->getRados()->trim_usage(get_id(), bucket_name, start_epoch, end_epoch);
 }
 
-int RGWRadosUser::load_by_id(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::GetParams& params)
+int RGWRadosUser::load_by_id(const DoutPrefixProvider *dpp, optional_yield y)
 {
-    return store->ctl()->user->get_info_by_uid(dpp, info.user_id, &info, y, params);
+    return store->ctl()->user->get_info_by_uid(dpp, info.user_id, &info, y, RGWUserCtl::GetParams().set_objv_tracker(&objv_tracker));
 }
 
 int RGWRadosUser::store_info(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::PutParams& params)
@@ -573,12 +573,13 @@ std::unique_ptr<RGWUser> RGWRadosStore::get_user(const rgw_user &u)
   return std::unique_ptr<RGWUser>(new RGWRadosUser(this, u));
 }
 
-int RGWRadosStore::get_user(const DoutPrefixProvider *dpp, const RGWAccessKey& key, optional_yield y, std::unique_ptr<RGWUser>* user)
+int RGWRadosStore::get_user_by_access_key(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y, std::unique_ptr<RGWUser>* user)
 {
   RGWUserInfo uinfo;
   RGWUser *u;
+  RGWObjVersionTracker objv_tracker;
 
-  int r = ctl()->user->get_info_by_access_key(dpp, key.id, &uinfo, y);
+  int r = ctl()->user->get_info_by_access_key(dpp, key, &uinfo, y, RGWUserCtl::GetParams().set_objv_tracker(&objv_tracker));
   if (r < 0)
     return r;
 
@@ -586,6 +587,8 @@ int RGWRadosStore::get_user(const DoutPrefixProvider *dpp, const RGWAccessKey& k
   if (!u)
     return -ENOMEM;
 
+  u->get_version_tracker() = objv_tracker;
+
   user->reset(u);
   return 0;
 }
@@ -594,8 +597,9 @@ int RGWRadosStore::get_user_by_email(const DoutPrefixProvider *dpp, const std::s
 {
   RGWUserInfo uinfo;
   RGWUser *u;
+  RGWObjVersionTracker objv_tracker;
 
-  int r = ctl()->user->get_info_by_email(dpp, email, &uinfo, y);
+  int r = ctl()->user->get_info_by_email(dpp, email, &uinfo, y, RGWUserCtl::GetParams().set_objv_tracker(&objv_tracker));
   if (r < 0)
     return r;
 
@@ -603,6 +607,8 @@ int RGWRadosStore::get_user_by_email(const DoutPrefixProvider *dpp, const std::s
   if (!u)
     return -ENOMEM;
 
+  u->get_version_tracker() = objv_tracker;
+
   user->reset(u);
   return 0;
 }
@@ -611,8 +617,9 @@ int RGWRadosStore::get_user_by_swift(const DoutPrefixProvider *dpp, const std::s
 {
   RGWUserInfo uinfo;
   RGWUser *u;
+  RGWObjVersionTracker objv_tracker;
 
-  int r = ctl()->user->get_info_by_swift(dpp, user_str, &uinfo, y);
+  int r = ctl()->user->get_info_by_swift(dpp, user_str, &uinfo, y, RGWUserCtl::GetParams().set_objv_tracker(&objv_tracker));
   if (r < 0)
     return r;
 
@@ -620,6 +627,8 @@ int RGWRadosStore::get_user_by_swift(const DoutPrefixProvider *dpp, const std::s
   if (!u)
     return -ENOMEM;
 
+  u->get_version_tracker() = objv_tracker;
+
   user->reset(u);
   return 0;
 }
index 9464b5252b55d6c44fa0edb43989d60eaafb99a1..9899cbb4456b4ff5c8729689b3ea5c2aa2e3112b 100644 (file)
@@ -62,7 +62,7 @@ class RGWRadosUser : public RGWUser {
     virtual int trim_usage(uint64_t start_epoch, uint64_t end_epoch) override;
 
     /* Placeholders */
-    virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::GetParams& params = {}) override;
+    virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y) override;
     virtual int store_info(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::PutParams& params = {}) override;
 
     friend class RGWRadosBucket;
@@ -343,7 +343,7 @@ class RGWRadosStore : public RGWStore {
     }
 
     virtual std::unique_ptr<RGWUser> get_user(const rgw_user& u) override;
-    virtual int get_user(const DoutPrefixProvider *dpp, const RGWAccessKey& key, optional_yield y, std::unique_ptr<RGWUser>* user) override;
+    virtual int get_user_by_access_key(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y, std::unique_ptr<RGWUser>* user) override;
     virtual int get_user_by_email(const DoutPrefixProvider *dpp, const std::string& email, optional_yield y, std::unique_ptr<RGWUser>* user) override;
     virtual int get_user_by_swift(const DoutPrefixProvider *dpp, const std::string& user_str, optional_yield y, std::unique_ptr<RGWUser>* user) override;
     virtual std::unique_ptr<RGWObject> get_object(const rgw_obj_key& k) override;
index 93de8df5d1f0e40a355115ac452814977cb3d786..643258a9410ffe67be6a8b19f3f4af7baac9365a 100644 (file)
@@ -1472,7 +1472,7 @@ int RGWUser::init(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state,
     access_key.clear();
   }
 
-  RGWUserInfo user_info;
+  std::unique_ptr<rgw::sal::RGWUser> user;
 
   clear_populated();
 
@@ -1485,35 +1485,37 @@ int RGWUser::init(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state,
   }
 
   if (!user_id.empty() && (user_id.compare(RGW_USER_ANON_ID) != 0)) {
-    found = (rgw_get_user_info_by_uid(dpp, user_ctl, user_id, user_info, y, &op_state.objv) >= 0);
+    user = store->get_user(user_id);
+    found = (user->load_by_id(dpp, y) >= 0);
     op_state.found_by_uid = found;
   }
   if (store->ctx()->_conf.get_val<bool>("rgw_user_unique_email")) {
     if (!user_email.empty() && !found) {
-      found = (rgw_get_user_info_by_email(dpp, user_ctl, user_email, user_info, y, &op_state.objv) >= 0);
+      found = (store->get_user_by_email(dpp, user_email, y, &user) >= 0);
       op_state.found_by_email = found;
     }
   }
   if (!swift_user.empty() && !found) {
-    found = (rgw_get_user_info_by_swift(dpp, user_ctl, swift_user, user_info, y, &op_state.objv) >= 0);
+    found = (store->get_user_by_swift(dpp, swift_user, y, &user) >= 0);
     op_state.found_by_key = found;
   }
   if (!access_key.empty() && !found) {
-    found = (rgw_get_user_info_by_access_key(dpp, user_ctl, access_key, user_info, y, &op_state.objv) >= 0);
+    found = (store->get_user_by_access_key(dpp, access_key, y, &user) >= 0);
     op_state.found_by_key = found;
   }
   
   op_state.set_existing_user(found);
   if (found) {
-    op_state.set_user_info(user_info);
+    op_state.set_user_info(user->get_info());
     op_state.set_populated();
+    op_state.objv = user->get_version_tracker();
 
-    old_info = user_info;
+    old_info = user->get_info();
     set_populated();
   }
 
   if (user_id.empty()) {
-    user_id = user_info.user_id;
+    user_id = user->get_id();
   }
   op_state.set_initialized();