]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: new restful api for retrieving user quota info
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 15 Jan 2014 19:36:47 +0000 (11:36 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 24 Jan 2014 23:07:36 +0000 (15:07 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_common.cc
src/rgw/rgw_rest_user.cc

index 2e69d532cd151e56655626c39f4297b49575d467..d5e172cd693c0836068127ba6cdc7f0d3282b3eb 100644 (file)
@@ -542,6 +542,7 @@ int XMLArgs::parse()
           (name.compare("caps") == 0) ||
           (name.compare("index") == 0) ||
           (name.compare("policy") == 0) ||
+          (name.compare("quota") == 0) ||
           (name.compare("object") == 0)) {
 
         if (!admin_subresource_added) {
index 3d08e403229555e017202f2a852844cd20f455fc..759997fa69bef3a998f36c9585f0362fda9f4ad4 100644 (file)
@@ -1,3 +1,5 @@
+#include "common/ceph_json.h"
+
 #include "rgw_op.h"
 #include "rgw_user.h"
 #include "rgw_rest_user.h"
@@ -609,8 +611,89 @@ void RGWOp_Caps_Remove::execute()
   http_ret = RGWUserAdminOp_Caps::remove(store, op_state, flusher);
 }
 
+struct UserQuotas {
+  RGWQuotaInfo bucket_quota;
+  RGWQuotaInfo user_quota;
+
+  UserQuotas(RGWUserInfo& info) {
+    bucket_quota = info.bucket_quota;
+    user_quota = info.user_quota;
+  }
+  void dump(Formatter *f) const {
+    encode_json("bucket_quota", bucket_quota, f);
+    encode_json("user_quota", user_quota, f);
+  }
+  void decode_json(JSONObj *obj) {
+    JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
+    JSONDecoder::decode_json("user_quota", user_quota, obj);
+  }
+};
+
+class RGWOp_Quota_Info : public RGWRESTOp {
+
+public:
+  RGWOp_Quota_Info() {}
+
+  int check_caps(RGWUserCaps& caps) {
+    return caps.check_cap("users", RGW_CAP_READ);
+  }
+
+  void execute();
+
+  virtual const string name() { return "get_quota_info"; }
+};
+
+
+void RGWOp_Quota_Info::execute()
+{
+  RGWUserAdminOpState op_state;
+
+  std::string uid;
+  std::string quota_type;
+
+  RESTArgs::get_string(s, "uid", uid, &uid);
+  RESTArgs::get_string(s, "quota-type", quota_type, &quota_type);
+
+  bool show_all = quota_type.empty();
+  bool show_bucket = show_all || (quota_type == "bucket");
+  bool show_user = show_all || (quota_type == "user");
+
+  if (!(show_all || show_bucket || show_user)) {
+    http_ret = -EINVAL;
+    return;
+  }
+
+
+  op_state.set_user_id(uid);
+
+  RGWUser user;
+  http_ret = user.init(store, op_state);
+  if (http_ret < 0)
+    return;
+
+  RGWUserInfo info;
+  string err_msg;
+  http_ret = user.info(info, &err_msg);
+  if (http_ret < 0)
+    return;
+
+  if (show_all) {
+    UserQuotas quotas(info);
+    encode_json("quota", quotas, s->formatter);
+  } else if (show_user) {
+    encode_json("user_quota", info.user_quota, s->formatter);
+  } else {
+    encode_json("bucket_quota", info.bucket_quota, s->formatter);
+  }
+
+  flusher.flush();
+}
+
 RGWOp *RGWHandler_User::op_get()
 {
+  if (s->info.args.sub_resource_exists("quota"))
+    return new RGWOp_Quota_Info;
+
   return new RGWOp_User_Info;
 };
 
@@ -625,6 +708,9 @@ RGWOp *RGWHandler_User::op_put()
   if (s->info.args.sub_resource_exists("caps"))
     return new RGWOp_Caps_Add;
 
+  if (s->info.args.sub_resource_exists("quota"))
+    return new RGWOp_Quota_Set;
+
   return new RGWOp_User_Create;
 };