]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/iam: ListUserPolicies supports Marker/MaxItems
authorCasey Bodley <cbodley@redhat.com>
Sun, 11 Feb 2024 17:17:14 +0000 (12:17 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 12 Apr 2024 19:34:28 +0000 (15:34 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit 6284745661f25c6db0ba5077237c035002153948)

src/rgw/rgw_rest_user_policy.cc
src/rgw/rgw_rest_user_policy.h

index 79d7912d12a3da031ce4bbca7d1e1ad4c67ebf9e..2dc10711ea599ab79aefbd6a90891cefabbecff8 100644 (file)
@@ -243,6 +243,19 @@ RGWListUserPolicies::RGWListUserPolicies()
 {
 }
 
+int RGWListUserPolicies::get_params()
+{
+  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 RGWRestUserPolicy::get_params();
+}
+
 void RGWListUserPolicies::execute(optional_yield y)
 {
   std::map<std::string, std::string> policies;
@@ -262,10 +275,16 @@ void RGWListUserPolicies::execute(optional_yield y)
   s->formatter->close_section();
   s->formatter->open_object_section("ListUserPoliciesResult");
   s->formatter->open_array_section("PolicyNames");
-  for (const auto& p : policies) {
-    s->formatter->dump_string("member", p.first);
+  auto policy = policies.lower_bound(marker);
+  for (; policy != policies.end() && max_items > 0; ++policy, --max_items) {
+    s->formatter->dump_string("member", policy->first);
   }
   s->formatter->close_section(); // PolicyNames
+  const bool is_truncated = (policy != policies.end());
+  encode_json("IsTruncated", is_truncated, s->formatter);
+  if (is_truncated) {
+    encode_json("Marker", policy->first, s->formatter);
+  }
   s->formatter->close_section(); // ListUserPoliciesResult
   s->formatter->close_section(); // ListUserPoliciesResponse
 }
index f4188687f86edbddf40131aeea39ed5a6c3cac4b..117226edc27d2c84fb4d28a914b120a976891fa2 100644 (file)
@@ -50,6 +50,9 @@ public:
 };
 
 class RGWListUserPolicies : public RGWRestUserPolicy {
+  std::string marker;
+  int max_items = 100;
+  int get_params() override;
 public:
   RGWListUserPolicies();
   void execute(optional_yield y) override;