]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: send headers of quota settings 41419/head
authorOr Friedmann <ofriedma@redhat.com>
Thu, 15 Oct 2020 15:40:27 +0000 (18:40 +0300)
committerCory Snyder <csnyder@iland.com>
Fri, 28 May 2021 18:03:26 +0000 (14:03 -0400)
Make the quota settings visible to s3 and swift users
rgw send headers of quota settings

Fixes: https://tracker.ceph.com/issues/47752
Signed-off-by: Or Friedmann <ofriedma@redhat.com>
(cherry picked from commit 706e077a79306f9c1efd66af7e5d9fdb474f629b)

 Conflicts:
src/rgw/rgw_op.cc

examples/boto3/delete_notification.py
examples/boto3/get_notification.py
examples/boto3/list_unordered.py
examples/boto3/notification_filters.py
examples/boto3/service-2.sdk-extras.json
examples/boto3/topic_with_endpoint.py
src/rgw/rgw_op.cc
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_swift.cc

index 8e4d3d7b71935ecb5c0a31183f192140ca00d6d4..ca5958e52ec110f83ce22d1aa88e62e310cda512 100755 (executable)
@@ -13,7 +13,7 @@ elif len(sys.argv) == 2:
     bucketname = sys.argv[1]
     notification_name = ""
 else:
-    print 'Usage: ' + sys.argv[0] + ' <bucket> [notification]'
+    print('Usage: ' + sys.argv[0] + ' <bucket> [notification]')
     sys.exit(1)
 
 # endpoint and keys from vstart
@@ -30,7 +30,7 @@ client = boto3.client('s3',
 # deleting all notification configurations on a bucket (without deleting the bucket itself) are extension to AWS S3 API
 
 if notification_name == "":
-    print client.delete_bucket_notification_configuration(Bucket=bucketname)
+    print(client.delete_bucket_notification_configuration(Bucket=bucketname))
 else:
-    print client.delete_bucket_notification_configuration(Bucket=bucketname,
-                                                          Notification=notification_name)
+    print(client.delete_bucket_notification_configuration(Bucket=bucketname,
+                                                          Notification=notification_name))
index 6e32198950c633737d3ec2e141112d6e1ca4af80..490c018d4ca2f0e12815543ecfd91a23b94f956f 100755 (executable)
@@ -4,7 +4,7 @@ import boto3
 import sys
 
 if len(sys.argv) != 3:
-    print 'Usage: ' + sys.argv[0] + ' <bucket> <notification>'
+    print('Usage: ' + sys.argv[0] + ' <bucket> <notification>')
     sys.exit(1)
 
 # bucket name as first argument
@@ -24,5 +24,5 @@ client = boto3.client('s3',
 
 # getting a specific notification configuration is an extension to AWS S3 API
 
-print client.get_bucket_notification_configuration(Bucket=bucketname,
-                                                   Notification=notification_name)
+print(client.get_bucket_notification_configuration(Bucket=bucketname,
+                                                   Notification=notification_name))
index b2339eaa63690c4574c45789e5eee5ba2d1320ba..2aa5a8e0608d3775e0c75a942df93f31bb6050ab 100755 (executable)
@@ -4,7 +4,7 @@ import boto3
 import sys
 
 if len(sys.argv) != 2:
-    print 'Usage: ' + sys.argv[0] + ' <bucket>'
+    print('Usage: ' + sys.argv[0] + ' <bucket>')
     sys.exit(1)
 
 # bucket name as first argument
@@ -22,4 +22,4 @@ client = boto3.client('s3',
 
 # geting an unordered list of objets is an extension to AWS S3 API
 
-print client.list_objects(Bucket=bucketname, AllowUnordered=True)
+print(client.list_objects(Bucket=bucketname, AllowUnordered=True))
index a45393c74f9b81cf13ee0fbac87d8b470efe0c72..2687c8b3aad5f515e11644be1fdf7dbf8a21fcc3 100755 (executable)
@@ -4,7 +4,7 @@ import boto3
 import sys
 
 if len(sys.argv) != 4:
-    print 'Usage: ' + sys.argv[0] + ' <bucket> <topic ARN> <notification Id>'
+    print('Usage: ' + sys.argv[0] + ' <bucket> <topic ARN> <notification Id>')
     sys.exit(1)
 
 # bucket name as first argument
@@ -44,5 +44,5 @@ topic_conf_list = [{'Id': notification_id,
                          }
                     }}]
 
-print client.put_bucket_notification_configuration(Bucket=bucketname,
-                                                   NotificationConfiguration={'TopicConfigurations': topic_conf_list})
+print(client.put_bucket_notification_configuration(Bucket=bucketname,
+                                                   NotificationConfiguration={'TopicConfigurations': topic_conf_list}))
index 65883226366f871c2808d4ded1d2a10d39ca9d70..9ee66730e8522ec07a7337fa4e2a5309b2716469 100644 (file)
         "UsageStatsSummary": {
             "type": "structure",
             "members": {
-                "TotalBytes":{"shape":"TotalBytes"},
+                       "QuotaMaxBytes":{"shape":"QuotaMaxBytes"},
+                       "QuotaMaxBuckets":{"shape": "QuotaMaxBuckets"},
+                       "QuotaMaxObjCount":{"shape":"QuotaMaxObjCount"},
+                       "QuotaMaxBytesPerBucket":{"shape":"QuotaMaxBytesPerBucket"},
+                "QuotaMaxObjCountPerBucket":{"shape":"QuotaMaxObjCountPerBucket"},
+                       "TotalBytes":{"shape":"TotalBytes"},
                 "TotalBytesRounded":{"shape":"TotalBytesRounded"},
                 "TotalEntries":{"shape":"TotalEntries"}
             }
         },
-        "TotalBytesRounded":{"type":"integer"},
+        "QuotaMaxBytes":{"type":"integer"},
+           "QuotaMaxBuckets":{"type": "integer"},
+           "QuotaMaxObjCount":{"type":"integer"},
+           "QuotaMaxBytesPerBucket":{"type":"integer"},
+           "QuotaMaxObjCountPerBucket":{"type":"integer"},
+           "TotalBytesRounded":{"type":"integer"},
         "TotalBytes":{"type":"integer"},
         "TotalEntries":{"type":"integer"}
     },
index b6e626e0200263c46268222768a9ed38f5d44963..3137cee7d4069f6e1be3830d9a6ff3c9a15eedfa 100755 (executable)
@@ -15,7 +15,7 @@ elif len(sys.argv) == 2:
     topic_name = sys.argv[1]
     region_name = ""
 else:
-    print 'Usage: ' + sys.argv[0] + ' <topic name> [region name]'
+    print('Usage: ' + sys.argv[0] + ' <topic name> [region name]')
     sys.exit(1)
 
 # endpoint and keys from vstart
@@ -38,4 +38,4 @@ client = boto3.client('sns',
 endpoint_args = 'push-endpoint=amqp://127.0.0.1:5672&amqp-exchange=ex1&amqp-ack-level=broker'
 attributes = {nvp[0] : nvp[1] for nvp in urlparse.parse_qsl(endpoint_args, keep_blank_values=True)}
 
-print client.create_topic(Name=topic_name, Attributes=attributes)
+print(client.create_topic(Name=topic_name, Attributes=attributes))
index 627e1ca4dec95f7d3e3c3f835dd336cb5e769198..b4a1e9056519fe7151edbeff4f12015924c43904 100644 (file)
@@ -2537,11 +2537,10 @@ void RGWGetUsage::execute()
   bool is_truncated = true;
 
   RGWUsageIter usage_iter;
-  
+
   while (is_truncated) {
     op_ret = store->getRados()->read_usage(s->user->get_id(), s->bucket_name, start_epoch, end_epoch, max_entries,
                                 &is_truncated, usage_iter, usage);
-
     if (op_ret == -ENOENT) {
       op_ret = 0;
       is_truncated = false;
index f6697f92b8d57df3b152773cf56d6633d6ba461d..cf0de874f93125c19240bfd46747ef86c20d1b1b 100644 (file)
@@ -1407,6 +1407,14 @@ void RGWGetUsage_ObjStore_S3::send_response()
        formatter->open_object_section("Stats");
      }
 
+     // send info about quota config
+     auto user_info = s->user->get_info();
+     encode_json("QuotaMaxBytes", user_info.user_quota.max_size, formatter);
+     encode_json("QuotaMaxBuckets", user_info.max_buckets, formatter);
+     encode_json("QuotaMaxObjCount", user_info.user_quota.max_objects, formatter);
+     encode_json("QuotaMaxBytesPerBucket", user_info.bucket_quota.max_objects, formatter);
+     encode_json("QuotaMaxObjCountPerBucket", user_info.bucket_quota.max_size, formatter);
+     // send info about user's capacity utilization
      encode_json("TotalBytes", stats.size, formatter);
      encode_json("TotalBytesRounded", stats.size_rounded, formatter);
      encode_json("TotalEntries", stats.num_objects, formatter);
@@ -2135,6 +2143,15 @@ static void dump_bucket_metadata(struct req_state *s, rgw::sal::RGWBucket* bucke
 {
   dump_header(s, "X-RGW-Object-Count", static_cast<long long>(bucket->get_count()));
   dump_header(s, "X-RGW-Bytes-Used", static_cast<long long>(bucket->get_size()));
+  // only bucket's owner is allowed to get the quota settings of the account
+  if (bucket->is_owner(s->user)) {
+    auto user_info = s->user->get_info();
+    dump_header(s, "X-RGW-Quota-User-Size", static_cast<long long>(user_info.user_quota.max_size));
+    dump_header(s, "X-RGW-Quota-User-Objects", static_cast<long long>(user_info.user_quota.max_objects));
+    dump_header(s, "X-RGW-Quota-Max-Buckets", static_cast<long long>(user_info.max_buckets));
+    dump_header(s, "X-RGW-Quota-Bucket-Size", static_cast<long long>(user_info.bucket_quota.max_size));
+    dump_header(s, "X-RGW-Quota-Bucket-Objects", static_cast<long long>(user_info.bucket_quota.max_objects));
+  }
 }
 
 void RGWStatBucket_ObjStore_S3::send_response()
index 0dce6afa600fe41d8f6dc1b8b951bbfa284d7061..db3bb717014d699411cdb98969657b992e35235a 100644 (file)
@@ -176,7 +176,7 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_begin(bool has_buckets)
             global_stats,
             policies_stats,
             attrs,
-            user_quota,
+            s->user->get_info().user_quota,
             static_cast<RGWAccessControlPolicy_SWIFTAcct&>(*s->user_acl));
     dump_errno(s);
     dump_header(s, "Accept-Ranges", "bytes");
@@ -282,7 +282,7 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_end()
             global_stats,
             policies_stats,
             attrs,
-            user_quota,
+            s->user->get_info().user_quota,
             static_cast<RGWAccessControlPolicy_SWIFTAcct&>(*s->user_acl));
     dump_errno(s);
     end_header(s, nullptr, nullptr, s->formatter->get_len(), true);
@@ -556,7 +556,7 @@ void RGWStatAccount_ObjStore_SWIFT::send_response()
             global_stats,
             policies_stats,
             attrs,
-            user_quota,
+            s->user->get_info().user_quota,
             static_cast<RGWAccessControlPolicy_SWIFTAcct&>(*s->user_acl));
   }