]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_rest_usage.cc
import 15.2.0 Octopus source
[ceph.git] / 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
3
4 #include "rgw_op.h"
5 #include "rgw_usage.h"
6 #include "rgw_rest_usage.h"
7
8 #include "include/str_list.h"
9
10 #define dout_subsys ceph_subsys_rgw
11
12 class RGWOp_Usage_Get : public RGWRESTOp {
13
14 public:
15 RGWOp_Usage_Get() {}
16
17 int check_caps(const RGWUserCaps& caps) override {
18 return caps.check_cap("usage", RGW_CAP_READ);
19 }
20 void execute() override;
21
22 const char* name() const override { return "get_usage"; }
23 };
24
25 void RGWOp_Usage_Get::execute() {
26 map<std::string, bool> categories;
27
28 string uid_str;
29 string bucket_name;
30 uint64_t start, end;
31 bool show_entries;
32 bool show_summary;
33
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);
37
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);
42
43 string cat_str;
44 RESTArgs::get_string(s, "categories", cat_str, &cat_str);
45
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;
52 }
53 }
54
55 http_ret = RGWUsage::show(store->getRados(), uid, bucket_name, start, end, show_entries, show_summary, &categories, flusher);
56 }
57
58 class RGWOp_Usage_Delete : public RGWRESTOp {
59
60 public:
61 RGWOp_Usage_Delete() {}
62
63 int check_caps(const RGWUserCaps& caps) override {
64 return caps.check_cap("usage", RGW_CAP_WRITE);
65 }
66 void execute() override;
67
68 const char* name() const override { return "trim_usage"; }
69 };
70
71 void RGWOp_Usage_Delete::execute() {
72 string uid_str;
73 string bucket_name;
74 uint64_t start, end;
75
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);
79
80 RESTArgs::get_epoch(s, "start", 0, &start);
81 RESTArgs::get_epoch(s, "end", (uint64_t)-1, &end);
82
83 if (uid.empty() &&
84 !bucket_name.empty() &&
85 !start &&
86 end == (uint64_t)-1) {
87 bool remove_all;
88 RESTArgs::get_bool(s, "remove-all", false, &remove_all);
89 if (!remove_all) {
90 http_ret = -EINVAL;
91 return;
92 }
93 }
94
95 http_ret = RGWUsage::trim(store->getRados(), uid, bucket_name, start, end);
96 }
97
98 RGWOp *RGWHandler_Usage::op_get()
99 {
100 return new RGWOp_Usage_Get;
101 }
102
103 RGWOp *RGWHandler_Usage::op_delete()
104 {
105 return new RGWOp_Usage_Delete;
106 }
107
108