]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add rest-usage handler
authorYehuda Sadeh <yehuda@inktank.com>
Fri, 21 Sep 2012 16:19:44 +0000 (09:19 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Mon, 8 Oct 2012 18:06:17 +0000 (11:06 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/Makefile.am
src/rgw/rgw_main.cc
src/rgw/rgw_rest.cc
src/rgw/rgw_rest_admin.h [new file with mode: 0644]
src/rgw/rgw_rest_s3.h
src/rgw/rgw_rest_usage.cc [new file with mode: 0644]
src/rgw/rgw_rest_usage.h [new file with mode: 0644]

index 0329a0fcf9d5f9ff214e670d14ca7675944bf54b..74e72d4a584af4335d6898d710121bc22190042e 100644 (file)
@@ -338,6 +338,7 @@ radosgw_SOURCES = \
         rgw/rgw_rest.cc \
         rgw/rgw_rest_swift.cc \
         rgw/rgw_rest_s3.cc \
+        rgw/rgw_rest_usage.cc \
         rgw/rgw_swift.cc \
        rgw/rgw_swift_auth.cc \
        rgw/rgw_main.cc
@@ -1716,6 +1717,8 @@ noinst_HEADERS = \
        rgw/rgw_rest.h\
        rgw/rgw_rest_swift.h\
        rgw/rgw_rest_s3.h\
+       rgw/rgw_rest_admin.h\
+       rgw/rgw_rest_usage.h\
        rgw/rgw_tools.h\
        rgw/rgw_usage.h\
        rgw/rgw_user.h\
index c253b1cc32ed1945a758c485524e144c005558db..26e371e0e6c640e62b3f796e7ab54eb43d676d89 100644 (file)
@@ -35,6 +35,8 @@
 #include "rgw_rest.h"
 #include "rgw_rest_s3.h"
 #include "rgw_rest_swift.h"
+#include "rgw_rest_admin.h"
+#include "rgw_rest_usage.h"
 #include "rgw_swift_auth.h"
 #include "rgw_swift.h"
 #include "rgw_log.h"
@@ -453,6 +455,10 @@ int main(int argc, const char **argv)
   rest.register_resource(g_conf->rgw_swift_url_prefix, new RGWRESTMgr_SWIFT);
   rest.register_resource(g_conf->rgw_swift_auth_entry, new RGWRESTMgr_SWIFT_Auth);
 
+  RGWRESTMgr_Admin *admin_resource = new RGWRESTMgr_Admin;
+  admin_resource->register_resource("/usage", new RGWRESTMgr_Usage);
+  rest.register_resource("/admin", admin_resource);
+
   RGWProcess process(g_ceph_context, g_conf->rgw_thread_pool_size, &rest);
   process.run();
 
index 4c4af68124499deb5c437ee9de260dbeb43cd7aa..fb2dec0458cd59dcc1746d90b9b1aa7c8ecf55ee 100644 (file)
@@ -678,9 +678,6 @@ int RGWHandler_ObjStore::read_permissions(RGWOp *op_obj)
 
 void RGWRESTMgr::register_resource(string resource, RGWRESTMgr *mgr)
 {
-  if (resource[resource.size() - 1] != '/')
-    resource.append("/");
-
   resource_mgrs[resource] = mgr;
   resources_by_size[resource.size()] = resource;
 }
@@ -694,14 +691,16 @@ void RGWRESTMgr::register_default_mgr(RGWRESTMgr *mgr)
 RGWRESTMgr *RGWRESTMgr::get_resource_mgr(struct req_state *s, const string& uri)
 {
   if (resources_by_size.empty())
-    return NULL;
+    return this;
 
   map<size_t, string>::reverse_iterator iter;
 
   for (iter = resources_by_size.rbegin(); iter != resources_by_size.rend(); ++iter) {
     string& resource = iter->second;
-    if (uri.compare(0, iter->first, resource) == 0) {
-      string suffix = resource.substr(resource.size() + 1);
+    if (uri.compare(0, iter->first, resource) == 0 &&
+       (resource.size() == iter->first ||
+        resource[iter->first] == '/')) {
+      string suffix = uri.substr(iter->first);
       return resource_mgrs[resource]->get_resource_mgr(s, suffix);
     }
   }
@@ -770,6 +769,10 @@ RGWHandler *RGWREST::get_handler(struct req_state *s, RGWClientIO *cio,
   }
 
   handler = m->get_handler(s);
+  if (!handler) {
+    *init_error = -ERR_METHOD_NOT_ALLOWED;
+    return NULL;
+  }
   *init_error = handler->init(s, cio);
   if (*init_error < 0)
     return NULL;
diff --git a/src/rgw/rgw_rest_admin.h b/src/rgw/rgw_rest_admin.h
new file mode 100644 (file)
index 0000000..25470f9
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef CEPH_RGW_REST_ADMIN_H
+#define CEPH_RGW_REST_ADMIN_H
+
+
+class RGWRESTMgr_Admin : public RGWRESTMgr {
+public:
+  RGWRESTMgr_Admin() {}
+  virtual ~RGWRESTMgr_Admin() {}
+};
+
+
+#endif
index 86d3352f310fd169c2ed7c27cdb8cf7ffe5ab544..11415cf132951816c7ef04134f3c8f2f9d63820f 100644 (file)
@@ -165,9 +165,9 @@ public:
 
 class RGWHandler_ObjStore_S3 : public RGWHandler_ObjStore {
   friend class RGWRESTMgr_S3;
-protected:
-  static int init_from_header(struct req_state *s);
 public:
+  static int init_from_header(struct req_state *s);
+
   RGWHandler_ObjStore_S3() : RGWHandler_ObjStore() {}
   virtual ~RGWHandler_ObjStore_S3() {}
 
diff --git a/src/rgw/rgw_rest_usage.cc b/src/rgw/rgw_rest_usage.cc
new file mode 100644 (file)
index 0000000..1057c5d
--- /dev/null
@@ -0,0 +1,32 @@
+#include "rgw_op.h"
+#include "rgw_usage.h"
+#include "rgw_rest_usage.h"
+
+class RGWOp_Usage : public RGWOp {
+
+public:
+  RGWOp_Usage() {}
+
+  int verify_permission() { return 0; }
+  void execute();
+
+  virtual const char *name() { return "get_usage"; }
+};
+
+void RGWOp_Usage::execute() {
+  map<std::string, bool> categories;
+  int ret = RGWUsage::show(rgwstore, s->user.user_id, 0, (uint64_t)-1, true, true, &categories, s->formatter);
+  if (ret)
+    set_req_state_err(s, ret);
+  dump_errno(s);
+  dump_start(s);
+
+  rgw_flush_formatter_and_reset(s, s->formatter);
+}
+
+RGWOp *RGWHandler_Usage::op_get()
+{
+  return new RGWOp_Usage;
+};
+
+
diff --git a/src/rgw/rgw_rest_usage.h b/src/rgw/rgw_rest_usage.h
new file mode 100644 (file)
index 0000000..779c781
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef CEPH_RGW_REST_USAGE_H
+#define CEPH_RGW_REST_USAGE_H
+
+#include "rgw_rest.h"
+#include "rgw_rest_s3.h"
+
+
+class RGWHandler_Usage : public RGWHandler_ObjStore_S3 {
+protected:
+  RGWOp *op_get();
+//  RGWOp *op_delete();
+public:
+  RGWHandler_Usage() {}
+  virtual ~RGWHandler_Usage() {}
+
+  int read_permissions(RGWOp*) {
+    return 0;
+  }
+  int authorize() {
+    return 0;
+  }
+};
+
+class RGWRESTMgr_Usage : public RGWRESTMgr {
+public:
+  RGWRESTMgr_Usage() {}
+  virtual ~RGWRESTMgr_Usage() {}
+
+  RGWHandler *get_handler(struct req_state *s) {
+    int ret = RGWHandler_ObjStore_S3::init_from_header(s);
+    if (ret < 0)
+      return NULL;
+    return new RGWHandler_Usage;
+  }
+};
+
+
+#endif