return std::unique_ptr<RGWRole>(p);
}
-int DaosStore::get_roles(const DoutPrefixProvider* dpp, optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- vector<std::unique_ptr<RGWRole>>& roles) {
+int DaosStore::list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing) {
return DAOS_NOT_IMPLEMENTED_LOG(dpp);
}
std::multimap<std::string, std::string> tags = {}) override;
virtual std::unique_ptr<RGWRole> get_role(const RGWRoleInfo& info) override;
virtual std::unique_ptr<RGWRole> get_role(std::string id) override;
- virtual int get_roles(const DoutPrefixProvider* dpp, optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- std::vector<std::unique_ptr<RGWRole>>& roles) override;
+ int list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing) override;
virtual std::unique_ptr<RGWOIDCProvider> get_oidc_provider() override;
virtual int get_oidc_providers(
const DoutPrefixProvider* dpp, const std::string& tenant,
return std::unique_ptr<RGWRole>(p);
}
-int MotrStore::get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- vector<std::unique_ptr<RGWRole>>& roles)
+int MotrStore::list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing)
{
return 0;
}
std::multimap<std::string, std::string> tags={}) override;
virtual std::unique_ptr<RGWRole> get_role(const RGWRoleInfo& info) override;
virtual std::unique_ptr<RGWRole> get_role(std::string id) override;
- virtual int get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- std::vector<std::unique_ptr<RGWRole>>& roles) override;
+ int list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing) override;
virtual std::unique_ptr<RGWOIDCProvider> get_oidc_provider() override;
virtual int get_oidc_providers(const DoutPrefixProvider *dpp,
const std::string& tenant,
return std::make_unique<RadosRole>(this, info);
}
-int RadosStore::get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- vector<std::unique_ptr<RGWRole>>& roles)
+int RadosStore::list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing)
{
- auto pool = svc()->zone->get_zone_params().roles_pool;
+ listing.roles.clear();
+
+ const auto& pool = svc()->zone->get_zone_params().roles_pool;
std::string prefix;
// List all roles if path prefix is empty
}
//Get the filtered objects
- list<std::string> result;
- bool is_truncated;
RGWListRawObjsCtx ctx;
- do {
- list<std::string> oids;
- int r = rados->list_raw_objects(dpp, pool, prefix, 1000, ctx, oids, &is_truncated);
- if (r < 0) {
- ldpp_dout(dpp, 0) << "ERROR: listing filtered objects failed: "
- << prefix << ": " << cpp_strerror(-r) << dendl;
- return r;
- }
- for (const auto& iter : oids) {
- result.push_back(iter.substr(RGWRole::role_path_oid_prefix.size()));
- }
- } while (is_truncated);
+ int r = rados->list_raw_objects_init(dpp, pool, marker, &ctx);
+ if (r < 0) {
+ return r;
+ }
+
+ bool is_truncated = false;
+ list<std::string> oids;
+ r = rados->list_raw_objects(dpp, pool, prefix, max_items,
+ ctx, oids, &is_truncated);
+ if (r == -ENOENT) {
+ r = 0;
+ } else if (r < 0) {
+ return r;
+ }
+
+ for (const auto& oid : oids) {
+ const std::string key = oid.substr(RGWRole::role_path_oid_prefix.size());
- for (const auto& it : result) {
//Find the role oid prefix from the end
- size_t pos = it.rfind(RGWRole::role_oid_prefix);
+ size_t pos = key.rfind(RGWRole::role_oid_prefix);
if (pos == std::string::npos) {
- continue;
+ continue;
}
// Split the result into path and info_oid + id
- std::string path = it.substr(0, pos);
+ std::string path = key.substr(0, pos);
/*Make sure that prefix is part of path (False results could've been returned)
because of the role info oid + id appended to the path)*/
if(path_prefix.empty() || path.find(path_prefix) != std::string::npos) {
//Get id from info oid prefix + id
- std::string id = it.substr(pos + RGWRole::role_oid_prefix.length());
+ std::string id = key.substr(pos + RGWRole::role_oid_prefix.length());
std::unique_ptr<rgw::sal::RGWRole> role = get_role(id);
- int ret = role->read_info(dpp, y);
- if (ret < 0) {
- return ret;
+ r = role->read_info(dpp, y);
+ if (r < 0) {
+ return r;
}
- roles.push_back(std::move(role));
+ listing.roles.push_back(std::move(role->get_info()));
}
}
+ if (is_truncated) {
+ listing.next_marker = rados->list_raw_objs_get_cursor(ctx);
+ } else {
+ listing.next_marker.clear();
+ }
return 0;
}
std::multimap<std::string,std::string> tags={}) override;
virtual std::unique_ptr<RGWRole> get_role(std::string id) override;
virtual std::unique_ptr<RGWRole> get_role(const RGWRoleInfo& info) override;
- virtual int get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- std::vector<std::unique_ptr<RGWRole>>& roles) override;
+ int list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing) override;
virtual std::unique_ptr<RGWOIDCProvider> get_oidc_provider() override;
virtual int get_oidc_providers(const DoutPrefixProvider *dpp,
const std::string& tenant,
formatter->flush(cout);
}
-static void show_role_info(rgw::sal::RGWRole* role, Formatter* formatter)
-{
- formatter->open_object_section("role");
- role->dump(formatter);
- formatter->close_section();
- formatter->flush(cout);
-}
-
-static void show_roles_info(vector<std::unique_ptr<rgw::sal::RGWRole>>& roles, Formatter* formatter)
-{
- formatter->open_array_section("Roles");
- for (const auto& it : roles) {
- formatter->open_object_section("role");
- it->dump(formatter);
- formatter->close_section();
- }
- formatter->close_section();
- formatter->flush(cout);
-}
-
static void show_reshard_status(
const list<cls_rgw_bucket_instance_entry>& status, Formatter *formatter)
{
if (ret < 0) {
return -ret;
}
- show_role_info(role.get(), formatter.get());
+ encode_json("role", *role, formatter.get());
+ formatter->flush(cout);
return 0;
}
case OPT::ROLE_DELETE:
if (ret < 0) {
return -ret;
}
- show_role_info(role.get(), formatter.get());
+ encode_json("role", *role, formatter.get());
+ formatter->flush(cout);
return 0;
}
case OPT::ROLE_TRUST_POLICY_MODIFY:
}
case OPT::ROLE_LIST:
{
- vector<std::unique_ptr<rgw::sal::RGWRole>> result;
- ret = driver->get_roles(dpp(), null_yield, path_prefix, tenant, result);
- if (ret < 0) {
- return -ret;
+ rgw::sal::RoleList listing;
+ listing.next_marker = marker;
+
+ int32_t remaining = std::numeric_limits<int32_t>::max();
+ if (max_entries_specified) {
+ remaining = max_entries;
+ formatter->open_object_section("result");
}
- show_roles_info(result, formatter.get());
+ formatter->open_array_section("Roles");
+
+ do {
+ constexpr int32_t max_chunk = 100;
+ int32_t count = std::min(max_chunk, remaining);
+
+ ret = driver->list_roles(dpp(), null_yield, tenant, path_prefix,
+ listing.next_marker, count, listing);
+ if (ret < 0) {
+ return -ret;
+ }
+ for (const auto& info : listing.roles) {
+ encode_json("member", info, formatter.get());
+ }
+ formatter->flush(cout);
+ remaining -= listing.roles.size();
+ } while (!listing.next_marker.empty() && remaining > 0);
+
+ formatter->close_section(); // Roles
+
+ if (max_entries_specified) {
+ if (!listing.next_marker.empty()) {
+ encode_json("next-marker", listing.next_marker, formatter.get());
+ }
+ formatter->close_section(); // result
+ }
+ formatter->flush(cout);
return 0;
}
case OPT::ROLE_POLICY_PUT:
int RGWListRoles::init_processing(optional_yield y)
{
path_prefix = s->info.args.get("PathPrefix");
+ marker = s->info.args.get("Marker");
+
+ int r = s->info.args.get_int("MaxItems", &max_items, max_items);
+ if (r < 0 || max_items > 1000) {
+ s->err.message = "Invalid value for MaxItems";
+ return -EINVAL;
+ }
return 0;
}
void RGWListRoles::execute(optional_yield y)
{
// TODO: list_account_roles() for account owner
- vector<std::unique_ptr<rgw::sal::RGWRole>> result;
- op_ret = driver->get_roles(s, y, path_prefix, s->user->get_tenant(), result);
+ rgw::sal::RoleList listing;
+ op_ret = driver->list_roles(s, y, s->user->get_tenant(), path_prefix,
+ marker, max_items, listing);
if (op_ret == 0) {
- s->formatter->open_array_section("ListRolesResponse");
- s->formatter->open_array_section("ListRolesResult");
- s->formatter->open_object_section("Roles");
- for (const auto& it : result) {
- s->formatter->open_object_section("member");
- it->dump(s->formatter);
- s->formatter->close_section();
+ s->formatter->open_object_section("ListRolesResponse");
+ s->formatter->open_object_section("ListRolesResult");
+ s->formatter->open_array_section("Roles");
+ for (const auto& info : listing.roles) {
+ encode_json("member", info, s->formatter);
}
- s->formatter->close_section();
- s->formatter->close_section();
+ s->formatter->close_section(); // Roles
+
+ const bool truncated = !listing.next_marker.empty();
+ encode_json("IsTruncated", truncated, s->formatter);
+ if (truncated) {
+ encode_json("Marker", listing.next_marker, s->formatter);
+ }
+
+ s->formatter->close_section(); // ListRolesResult
s->formatter->open_object_section("ResponseMetadata");
s->formatter->dump_string("RequestId", s->trans_id);
- s->formatter->close_section();
- s->formatter->close_section();
+ s->formatter->close_section(); // ResponseMetadata
+ s->formatter->close_section(); // ListRolesResponse
}
}
class RGWListRoles : public RGWRestRole {
std::string path_prefix;
+ std::string marker;
+ int max_items = 100;
+ std::string next_marker;
public:
RGWListRoles() : RGWRestRole(rgw::IAM::iamListRoles, RGW_CAP_READ) {}
int init_processing(optional_yield y) override;
virtual std::unique_ptr<RGWRole> get_role(std::string id) = 0;
virtual std::unique_ptr<RGWRole> get_role(const RGWRoleInfo& info) = 0;
/** Get all IAM Roles optionally filtered by path */
- virtual int get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- std::vector<std::unique_ptr<RGWRole>>& roles) = 0;
+ virtual int list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing) = 0;
/** Get an empty Open ID Connector provider */
virtual std::unique_ptr<RGWOIDCProvider> get_oidc_provider() = 0;
/** Get all Open ID Connector providers, optionally filtered by tenant */
return std::unique_ptr<RGWRole>(p);
}
- int DBStore::get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- vector<std::unique_ptr<RGWRole>>& roles)
+ int DBStore::list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing)
{
return 0;
}
std::multimap<std::string,std::string> tags={}) override;
virtual std::unique_ptr<RGWRole> get_role(std::string id) override;
virtual std::unique_ptr<RGWRole> get_role(const RGWRoleInfo& info) override;
- virtual int get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- std::vector<std::unique_ptr<RGWRole>>& roles) override;
+ int list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing) override;
virtual std::unique_ptr<RGWOIDCProvider> get_oidc_provider() override;
virtual int get_oidc_providers(const DoutPrefixProvider *dpp,
const std::string& tenant,
return next->get_role(info);
}
-int FilterDriver::get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- std::vector<std::unique_ptr<RGWRole>>& roles)
-{
- return next->get_roles(dpp, y, path_prefix, tenant, roles);
+int FilterDriver::list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing)
+{
+ return next->list_roles(dpp, y, tenant, path_prefix,
+ marker, max_items, listing);
}
std::unique_ptr<RGWOIDCProvider> FilterDriver::get_oidc_provider()
std::multimap<std::string,std::string> tags={}) override;
virtual std::unique_ptr<RGWRole> get_role(std::string id) override;
virtual std::unique_ptr<RGWRole> get_role(const RGWRoleInfo& info) override;
- virtual int get_roles(const DoutPrefixProvider *dpp,
- optional_yield y,
- const std::string& path_prefix,
- const std::string& tenant,
- std::vector<std::unique_ptr<RGWRole>>& roles) override;
+ virtual int list_roles(const DoutPrefixProvider *dpp,
+ optional_yield y,
+ const std::string& tenant,
+ const std::string& path_prefix,
+ const std::string& marker,
+ uint32_t max_items,
+ RoleList& listing) override;
virtual std::unique_ptr<RGWOIDCProvider> get_oidc_provider() override;
virtual int get_oidc_providers(const DoutPrefixProvider *dpp,
const std::string& tenant,