#include "account.h"
#include "buckets.h"
+#include "users.h"
#include "rgw_pubsub.h"
#include "topic.h"
return 0;
}
-
int RadosStore::load_account_by_id(const DoutPrefixProvider* dpp,
optional_yield y,
std::string_view id,
return 0;
}
+int RadosStore::load_account_user_by_name(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view username,
+ std::unique_ptr<User>* user)
+{
+ rgw_user uid;
+ uid.tenant = tenant;
+
+ librados::Rados& rados = *getRados()->get_rados_handle();
+ const RGWZoneParams& zone = svc()->zone->get_zone_params();
+ const rgw_raw_obj& obj = rgwrados::account::get_users_obj(zone, account_id);
+ int r = rgwrados::users::get(dpp, y, rados, obj, username, uid.id);
+ if (r < 0) {
+ ldpp_dout(dpp, 20) << "failed to find account username " << username
+ << ": " << cpp_strerror(r) << dendl;
+ return r;
+ }
+
+ std::unique_ptr<User> u = get_user(uid);
+ r = u->load_user(dpp, y);
+ if (r < 0) {
+ ldpp_dout(dpp, 20) << "failed to load account user " << uid
+ << ": " << cpp_strerror(r) << dendl;
+ return r;
+ }
+ *user = std::move(u);
+ return 0;
+}
+
+int RadosStore::count_account_users(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_users_obj(zone, account_id);
+ return rgwrados::account::resource_count(dpp, y, rados, obj, count);
+}
+
+int RadosStore::list_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view path_prefix,
+ std::string_view marker,
+ uint32_t max_items,
+ UserList& listing)
+{
+ // fetch the list of user ids from cls_user
+ librados::Rados& rados = *getRados()->get_rados_handle();
+ const RGWZoneParams& zone = svc()->zone->get_zone_params();
+ const rgw_raw_obj& obj = rgwrados::account::get_users_obj(zone, account_id);
+ std::vector<std::string> ids;
+ int r = rgwrados::users::list(dpp, y, rados, obj, marker, path_prefix,
+ max_items, ids, listing.next_marker);
+ if (r < 0) {
+ return r;
+ }
+
+ // load the user metadata for each
+ for (auto& id : ids) {
+ rgw_user uid;
+ uid.tenant = tenant;
+ uid.id = std::move(id);
+
+ RGWUserInfo info;
+ r = ctl()->user->get_info_by_uid(dpp, uid, &info, y);
+ if (r == -ENOENT) {
+ continue;
+ }
+ if (r < 0) {
+ return r;
+ }
+ listing.users.push_back(std::move(info));
+ }
+
+ return 0;
+}
+
std::unique_ptr<Object> RadosStore::get_object(const rgw_obj_key& k)
{
return std::make_unique<RadosObject>(this, k);
std::string_view email,
rgw_owner& owner) override;
+ int load_account_user_by_name(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view username,
+ std::unique_ptr<User>* user) override;
+ int count_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ uint32_t& count) override;
+ int list_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view path_prefix,
+ std::string_view marker,
+ uint32_t max_items,
+ UserList& listing) override;
+
virtual std::unique_ptr<Object> get_object(const rgw_obj_key& k) override;
std::unique_ptr<Bucket> get_bucket(const RGWBucketInfo& i) override;
int load_bucket(const DoutPrefixProvider* dpp, const rgw_bucket& b,
std::string next_marker;
};
+/// A list of users
+struct UserList {
+ /// The list of results, sorted by name
+ std::vector<RGWUserInfo> users;
+ /// The next marker to resume listing, or empty
+ std::string next_marker;
+};
+
/** A list of key-value attributes */
using Attrs = std::map<std::string, ceph::buffer::list>;
std::string_view email,
rgw_owner& owner) = 0;
+ /** Load an account's user by username. */
+ virtual int load_account_user_by_name(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view username,
+ std::unique_ptr<User>* user) = 0;
+ /** Count the number of users belonging to the given account. */
+ virtual int count_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ uint32_t& count) = 0;
+ /** Return a paginated listing of the account's users. */
+ virtual int list_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view path_prefix,
+ std::string_view marker,
+ uint32_t max_items,
+ UserList& listing) = 0;
+
/** Get a basic Object. This Object is not looked up, and is incomplete, since is
* does not have a bucket. This should only be used when an Object is needed before
* there is a Bucket, otherwise use the get_object() in the Bucket class. */
return 0;
}
+ int DBStore::load_account_user_by_name(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view username,
+ std::unique_ptr<User>* user)
+ {
+ return -ENOTSUP;
+ }
+
+ int DBStore::count_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ uint32_t& count)
+ {
+ return -ENOTSUP;
+ }
+
+ int DBStore::list_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view path_prefix,
+ std::string_view marker,
+ uint32_t max_items,
+ UserList& listing)
+ {
+ return -ENOTSUP;
+ }
+
std::string DBStore::get_cluster_id(const DoutPrefixProvider* dpp, optional_yield y)
{
return "PLACEHOLDER"; // for instance unique identifier
optional_yield y,
std::string_view email,
rgw_owner& owner) override;
+
+ int load_account_user_by_name(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view username,
+ std::unique_ptr<User>* user) override;
+ int count_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ uint32_t& count) override;
+ int list_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view path_prefix,
+ std::string_view marker,
+ uint32_t max_items,
+ UserList& listing) override;
+
virtual std::unique_ptr<Object> get_object(const rgw_obj_key& k) override;
virtual std::string get_cluster_id(const DoutPrefixProvider* dpp, optional_yield y);
std::unique_ptr<Bucket> get_bucket(const RGWBucketInfo& i) override;
return next->load_owner_by_email(dpp, y, email, owner);
}
+int FilterDriver::load_account_user_by_name(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view username,
+ std::unique_ptr<User>* user)
+{
+ std::unique_ptr<User> nu;
+ int ret = next->load_account_user_by_name(dpp, y, account_id, tenant,
+ username, &nu);
+ if (ret >= 0) {
+ *user = std::make_unique<FilterUser>(std::move(nu));
+ }
+ return ret;
+}
+
+int FilterDriver::count_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ uint32_t& count)
+{
+ return next->count_account_users(dpp, y, account_id, count);
+}
+
+int FilterDriver::list_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view path_prefix,
+ std::string_view marker,
+ uint32_t max_items,
+ UserList& listing)
+{
+ return next->list_account_users(dpp, y, account_id, tenant, path_prefix,
+ marker, max_items, listing);
+}
+
std::unique_ptr<Object> FilterDriver::get_object(const rgw_obj_key& k)
{
std::unique_ptr<Object> o = next->get_object(k);
optional_yield y,
std::string_view email,
rgw_owner& owner) override;
+ int load_account_user_by_name(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view username,
+ std::unique_ptr<User>* user) override;
+ int count_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ uint32_t& count) override;
+ int list_account_users(const DoutPrefixProvider* dpp,
+ optional_yield y,
+ std::string_view account_id,
+ std::string_view tenant,
+ std::string_view path_prefix,
+ std::string_view marker,
+ uint32_t max_items,
+ UserList& listing) override;
+
virtual std::unique_ptr<Object> get_object(const rgw_obj_key& k) override;
std::unique_ptr<Bucket> get_bucket(const RGWBucketInfo& i) override;
int load_bucket(const DoutPrefixProvider* dpp, const rgw_bucket& b,
class Driver;
class User;
+ struct UserList;
class Bucket;
- class BucketList;
+ struct BucketList;
class Object;
class MultipartUpload;
class Lifecycle;