]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_rest_usage.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / rgw / rgw_rest_usage.cc
CommitLineData
7c673cae 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
7c673cae
FG
3
4#include "rgw_op.h"
5#include "rgw_usage.h"
6#include "rgw_rest_usage.h"
20effc67 7#include "rgw_sal.h"
7c673cae
FG
8
9#include "include/str_list.h"
10
11#define dout_subsys ceph_subsys_rgw
12
20effc67
TL
13using namespace std;
14
7c673cae
FG
15class RGWOp_Usage_Get : public RGWRESTOp {
16
17public:
18 RGWOp_Usage_Get() {}
19
9f95a23c 20 int check_caps(const RGWUserCaps& caps) override {
7c673cae
FG
21 return caps.check_cap("usage", RGW_CAP_READ);
22 }
f67539c2 23 void execute(optional_yield y) override;
7c673cae 24
11fdf7f2 25 const char* name() const override { return "get_usage"; }
7c673cae
FG
26};
27
f67539c2 28void RGWOp_Usage_Get::execute(optional_yield y) {
7c673cae
FG
29 map<std::string, bool> categories;
30
31 string uid_str;
11fdf7f2 32 string bucket_name;
7c673cae
FG
33 uint64_t start, end;
34 bool show_entries;
35 bool show_summary;
36
37 RESTArgs::get_string(s, "uid", uid_str, &uid_str);
11fdf7f2 38 RESTArgs::get_string(s, "bucket", bucket_name, &bucket_name);
20effc67
TL
39 std::unique_ptr<rgw::sal::User> user = store->get_user(rgw_user(uid_str));
40 std::unique_ptr<rgw::sal::Bucket> bucket;
41
42 if (!bucket_name.empty()) {
43 store->get_bucket(nullptr, user.get(), std::string(), bucket_name, &bucket, null_yield);
44 }
7c673cae
FG
45
46 RESTArgs::get_epoch(s, "start", 0, &start);
47 RESTArgs::get_epoch(s, "end", (uint64_t)-1, &end);
48 RESTArgs::get_bool(s, "show-entries", true, &show_entries);
49 RESTArgs::get_bool(s, "show-summary", true, &show_summary);
50
51 string cat_str;
52 RESTArgs::get_string(s, "categories", cat_str, &cat_str);
53
54 if (!cat_str.empty()) {
55 list<string> cat_list;
56 list<string>::iterator iter;
57 get_str_list(cat_str, cat_list);
58 for (iter = cat_list.begin(); iter != cat_list.end(); ++iter) {
59 categories[*iter] = true;
60 }
61 }
62
20effc67 63 op_ret = RGWUsage::show(this, store, user.get(), bucket.get(), start, end, show_entries, show_summary, &categories, flusher);
7c673cae
FG
64}
65
66class RGWOp_Usage_Delete : public RGWRESTOp {
67
68public:
69 RGWOp_Usage_Delete() {}
70
9f95a23c 71 int check_caps(const RGWUserCaps& caps) override {
7c673cae
FG
72 return caps.check_cap("usage", RGW_CAP_WRITE);
73 }
f67539c2 74 void execute(optional_yield y) override;
7c673cae 75
11fdf7f2 76 const char* name() const override { return "trim_usage"; }
7c673cae
FG
77};
78
f67539c2 79void RGWOp_Usage_Delete::execute(optional_yield y) {
7c673cae 80 string uid_str;
11fdf7f2 81 string bucket_name;
7c673cae
FG
82 uint64_t start, end;
83
84 RESTArgs::get_string(s, "uid", uid_str, &uid_str);
11fdf7f2 85 RESTArgs::get_string(s, "bucket", bucket_name, &bucket_name);
20effc67
TL
86 std::unique_ptr<rgw::sal::User> user = store->get_user(rgw_user(uid_str));
87 std::unique_ptr<rgw::sal::Bucket> bucket;
88
89 if (!bucket_name.empty()) {
90 store->get_bucket(nullptr, user.get(), std::string(), bucket_name, &bucket, null_yield);
91 }
7c673cae
FG
92
93 RESTArgs::get_epoch(s, "start", 0, &start);
94 RESTArgs::get_epoch(s, "end", (uint64_t)-1, &end);
95
20effc67 96 if (rgw::sal::User::empty(user.get()) &&
11fdf7f2 97 !bucket_name.empty() &&
7c673cae
FG
98 !start &&
99 end == (uint64_t)-1) {
100 bool remove_all;
101 RESTArgs::get_bool(s, "remove-all", false, &remove_all);
102 if (!remove_all) {
f67539c2 103 op_ret = -EINVAL;
7c673cae
FG
104 return;
105 }
106 }
107
20effc67 108 op_ret = RGWUsage::trim(this, store, user.get(), bucket.get(), start, end);
7c673cae
FG
109}
110
111RGWOp *RGWHandler_Usage::op_get()
112{
113 return new RGWOp_Usage_Get;
114}
115
116RGWOp *RGWHandler_Usage::op_delete()
117{
118 return new RGWOp_Usage_Delete;
119}
120
121