]>
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"
7 #include "rgw_sal_rados.h"
9 #include "include/str_list.h"
11 #define dout_subsys ceph_subsys_rgw
13 class RGWOp_Usage_Get
: public RGWRESTOp
{
18 int check_caps(const RGWUserCaps
& caps
) override
{
19 return caps
.check_cap("usage", RGW_CAP_READ
);
21 void execute(optional_yield y
) override
;
23 const char* name() const override
{ return "get_usage"; }
26 void RGWOp_Usage_Get::execute(optional_yield y
) {
27 map
<std::string
, bool> categories
;
35 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
36 RESTArgs::get_string(s
, "bucket", bucket_name
, &bucket_name
);
37 rgw_user
uid(uid_str
);
39 RESTArgs::get_epoch(s
, "start", 0, &start
);
40 RESTArgs::get_epoch(s
, "end", (uint64_t)-1, &end
);
41 RESTArgs::get_bool(s
, "show-entries", true, &show_entries
);
42 RESTArgs::get_bool(s
, "show-summary", true, &show_summary
);
45 RESTArgs::get_string(s
, "categories", cat_str
, &cat_str
);
47 if (!cat_str
.empty()) {
48 list
<string
> cat_list
;
49 list
<string
>::iterator iter
;
50 get_str_list(cat_str
, cat_list
);
51 for (iter
= cat_list
.begin(); iter
!= cat_list
.end(); ++iter
) {
52 categories
[*iter
] = true;
56 op_ret
= RGWUsage::show(this, store
->getRados(), uid
, bucket_name
, start
, end
, show_entries
, show_summary
, &categories
, flusher
);
59 class RGWOp_Usage_Delete
: public RGWRESTOp
{
62 RGWOp_Usage_Delete() {}
64 int check_caps(const RGWUserCaps
& caps
) override
{
65 return caps
.check_cap("usage", RGW_CAP_WRITE
);
67 void execute(optional_yield y
) override
;
69 const char* name() const override
{ return "trim_usage"; }
72 void RGWOp_Usage_Delete::execute(optional_yield y
) {
77 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
78 RESTArgs::get_string(s
, "bucket", bucket_name
, &bucket_name
);
79 rgw_user
uid(uid_str
);
81 RESTArgs::get_epoch(s
, "start", 0, &start
);
82 RESTArgs::get_epoch(s
, "end", (uint64_t)-1, &end
);
85 !bucket_name
.empty() &&
87 end
== (uint64_t)-1) {
89 RESTArgs::get_bool(s
, "remove-all", false, &remove_all
);
96 op_ret
= RGWUsage::trim(this, store
->getRados(), uid
, bucket_name
, start
, end
);
99 RGWOp
*RGWHandler_Usage::op_get()
101 return new RGWOp_Usage_Get
;
104 RGWOp
*RGWHandler_Usage::op_delete()
106 return new RGWOp_Usage_Delete
;