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
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\
#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"
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();
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;
}
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);
}
}
}
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;
--- /dev/null
+#ifndef CEPH_RGW_REST_ADMIN_H
+#define CEPH_RGW_REST_ADMIN_H
+
+
+class RGWRESTMgr_Admin : public RGWRESTMgr {
+public:
+ RGWRESTMgr_Admin() {}
+ virtual ~RGWRESTMgr_Admin() {}
+};
+
+
+#endif
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() {}
--- /dev/null
+#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;
+};
+
+
--- /dev/null
+#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