]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_rest_usage.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
6 #include "rgw_rest_usage.h"
8 #include "include/str_list.h"
10 #define dout_subsys ceph_subsys_rgw
12 class RGWOp_Usage_Get
: public RGWRESTOp
{
17 int check_caps(const RGWUserCaps
& caps
) override
{
18 return caps
.check_cap("usage", RGW_CAP_READ
);
20 void execute() override
;
22 const char* name() const override
{ return "get_usage"; }
25 void RGWOp_Usage_Get::execute() {
26 map
<std::string
, bool> categories
;
34 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
35 RESTArgs::get_string(s
, "bucket", bucket_name
, &bucket_name
);
36 rgw_user
uid(uid_str
);
38 RESTArgs::get_epoch(s
, "start", 0, &start
);
39 RESTArgs::get_epoch(s
, "end", (uint64_t)-1, &end
);
40 RESTArgs::get_bool(s
, "show-entries", true, &show_entries
);
41 RESTArgs::get_bool(s
, "show-summary", true, &show_summary
);
44 RESTArgs::get_string(s
, "categories", cat_str
, &cat_str
);
46 if (!cat_str
.empty()) {
47 list
<string
> cat_list
;
48 list
<string
>::iterator iter
;
49 get_str_list(cat_str
, cat_list
);
50 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
51 categories
[*iter
] = true;
55 http_ret
= RGWUsage::show(store
->getRados(), uid
, bucket_name
, start
, end
, show_entries
, show_summary
, &categories
, flusher
);
58 class RGWOp_Usage_Delete
: public RGWRESTOp
{
61 RGWOp_Usage_Delete() {}
63 int check_caps(const RGWUserCaps
& caps
) override
{
64 return caps
.check_cap("usage", RGW_CAP_WRITE
);
66 void execute() override
;
68 const char* name() const override
{ return "trim_usage"; }
71 void RGWOp_Usage_Delete::execute() {
76 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
77 RESTArgs::get_string(s
, "bucket", bucket_name
, &bucket_name
);
78 rgw_user
uid(uid_str
);
80 RESTArgs::get_epoch(s
, "start", 0, &start
);
81 RESTArgs::get_epoch(s
, "end", (uint64_t)-1, &end
);
84 !bucket_name
.empty() &&
86 end
== (uint64_t)-1) {
88 RESTArgs::get_bool(s
, "remove-all", false, &remove_all
);
95 http_ret
= RGWUsage::trim(store
->getRados(), uid
, bucket_name
, start
, end
);
98 RGWOp
*RGWHandler_Usage::op_get()
100 return new RGWOp_Usage_Get
;
103 RGWOp
*RGWHandler_Usage::op_delete()
105 return new RGWOp_Usage_Delete
;