Skip to content

Commit

Permalink
rgw/sfs: Lists only the buckets owned by the user.
Browse files Browse the repository at this point in the history
Returns only the buckets owned by the SFSUser being called.

It also includes SFSUser tests.

Fixes: aquarist-labs/s3gw-tools#33
Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
  • Loading branch information
0xavi0 authored and Marcel Lauhoff committed Mar 15, 2023
1 parent c03cbe5 commit 74d72df
Show file tree
Hide file tree
Showing 5 changed files with 471 additions and 85 deletions.
14 changes: 7 additions & 7 deletions src/rgw/driver/sfs/user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int SFSUser::remove_user(const DoutPrefixProvider *dpp,
rgw::sal::sfs::sqlite::SQLiteUsers sqlite_users(store->db_conn);
auto db_user = sqlite_users.get_user(info.user_id.id);
if (!db_user) {
return ECANCELED;
return -ECANCELED;
}
sqlite_users.remove_user(info.user_id.id);
return 0;
Expand All @@ -125,18 +125,18 @@ int SFSUser::list_buckets(const DoutPrefixProvider *dpp,
const std::string &end_marker, uint64_t max,
bool need_stats, BucketList &buckets,
optional_yield y) {
// TODO this should list buckets assigned to a user. for now we just get every
// bucket
ldpp_dout(dpp, 10) << __func__
<< ": marker (" << marker << ", " << end_marker
<< "), max=" << max << dendl;

std::list<sfs::BucketRef> lst = store->bucket_list();
for (const auto &bucketref : lst) {
buckets.add(
std::unique_ptr<Bucket>(
new SFSBucket{store, bucketref}
));
if (bucketref->get_owner().user_id.id == get_id().id) {
buckets.add(
std::unique_ptr<Bucket>(
new SFSBucket{store, bucketref}
));
}
}

ldpp_dout(dpp, 10) << __func__ << ": buckets=" << buckets.get_buckets()
Expand Down
4 changes: 4 additions & 0 deletions src/test/rgw/sfs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ target_link_libraries(unittest_rgw_sfs_sqlite_versioned_objects ${rgw_libs})
add_executable(unittest_rgw_sfs_sfs_bucket test_rgw_sfs_sfs_bucket.cc)
add_ceph_unittest(unittest_rgw_sfs_sfs_bucket)
target_link_libraries(unittest_rgw_sfs_sfs_bucket ${rgw_libs})

add_executable(unittest_rgw_sfs_sfs_user test_rgw_sfs_sfs_user.cc)
add_ceph_unittest(unittest_rgw_sfs_sfs_user)
target_link_libraries(unittest_rgw_sfs_sfs_user ${rgw_libs})
83 changes: 83 additions & 0 deletions src/test/rgw/sfs/rgw_sfs_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#pragma once

#include "rgw/rgw_sal_sfs.h"

#include <gtest/gtest.h>

template <typename T>
bool compare(const T & origin, const T & dest) {
return origin == dest;
}

bool compare(const RGWAccessKey & origin, const RGWAccessKey & dest) {
if (origin.id != dest.id) return false;
if (origin.key != dest.key) return false;
if (origin.subuser != dest.subuser) return false;
return true;
}

bool compare(const RGWSubUser & origin, const RGWSubUser & dest) {
if (origin.name != dest.name) return false;
if (origin.perm_mask != dest.perm_mask) return false;
return true;
}

template <typename T>
bool compareMaps(const T & origin, const T & dest) {
if (origin.size() != dest.size()) return false;
for (auto const& [key, val] : origin)
{
if (dest.find(key) == dest.end()) return false;
auto & dest_val = dest.at(key);
if (!compare(val, dest_val)) return false;
}
return true;
}

std::string getCapsString(const RGWUserCaps & caps) {
auto formatter = std::make_unique<ceph::JSONFormatter>(new ceph::JSONFormatter(true));
encode_json("caps", caps, formatter.get());
std::ostringstream oss;
formatter->flush(oss);
return oss.str();
}

void compareUsersRGWInfo(const RGWUserInfo & origin, const RGWUserInfo & dest) {
ASSERT_EQ(origin.user_id.id, dest.user_id.id);
ASSERT_EQ(origin.user_id.tenant, dest.user_id.tenant);
ASSERT_EQ(origin.user_id.ns, dest.user_id.ns);
ASSERT_EQ(origin.display_name, dest.display_name);
ASSERT_EQ(origin.user_email, dest.user_email);
ASSERT_TRUE(compareMaps(origin.access_keys, dest.access_keys));
ASSERT_TRUE(compareMaps(origin.swift_keys, dest.swift_keys));
ASSERT_TRUE(compareMaps(origin.subusers, dest.subusers));
ASSERT_EQ(origin.suspended, dest.suspended);
ASSERT_EQ(origin.max_buckets, dest.max_buckets);
ASSERT_EQ(origin.op_mask, dest.op_mask);
ASSERT_EQ(getCapsString(origin.caps), getCapsString(dest.caps));
ASSERT_EQ(origin.system, dest.system);
ASSERT_EQ(origin.default_placement.name, dest.default_placement.name);
ASSERT_EQ(origin.default_placement.storage_class, dest.default_placement.storage_class);
ASSERT_EQ(origin.placement_tags, dest.placement_tags);
ASSERT_EQ(origin.quota.bucket_quota.max_size, dest.quota.bucket_quota.max_size);
ASSERT_EQ(origin.quota.bucket_quota.max_objects, dest.quota.bucket_quota.max_objects);
ASSERT_EQ(origin.quota.bucket_quota.enabled, dest.quota.bucket_quota.enabled);
ASSERT_EQ(origin.quota.bucket_quota.check_on_raw, dest.quota.bucket_quota.check_on_raw);
ASSERT_TRUE(compareMaps(origin.temp_url_keys, dest.temp_url_keys));
ASSERT_EQ(origin.quota.user_quota.max_size, dest.quota.user_quota.max_size);
ASSERT_EQ(origin.quota.user_quota.max_objects, dest.quota.user_quota.max_objects);
ASSERT_EQ(origin.quota.user_quota.enabled, dest.quota.user_quota.enabled);
ASSERT_EQ(origin.quota.user_quota.check_on_raw, dest.quota.user_quota.check_on_raw);
ASSERT_EQ(origin.type, dest.type);
ASSERT_EQ(origin.mfa_ids, dest.mfa_ids);
ASSERT_EQ(origin.assumed_role_arn, dest.assumed_role_arn);
}

void compareUserAttrs(const rgw::sal::Attrs & origin, const rgw::sal::Attrs & dest) {
ASSERT_TRUE(compareMaps(origin, dest));
}

void compareUserVersion(const obj_version & origin, const obj_version & dest) {
ASSERT_EQ(origin.ver, dest.ver);
ASSERT_EQ(origin.tag, dest.tag);
}
Loading

0 comments on commit 74d72df

Please sign in to comment.