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