]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_rest_bucket.cc
update sources to v12.2.3
[ceph.git] / ceph / src / rgw / rgw_rest_bucket.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "rgw_op.h"
5 #include "rgw_bucket.h"
6 #include "rgw_rest_bucket.h"
7
8 #include "include/str_list.h"
9
10 #define dout_subsys ceph_subsys_rgw
11
12 class RGWOp_Bucket_Info : public RGWRESTOp {
13
14 public:
15 RGWOp_Bucket_Info() {}
16
17 int check_caps(RGWUserCaps& caps) override {
18 return caps.check_cap("buckets", RGW_CAP_READ);
19 }
20
21 void execute() override;
22
23 const string name() override { return "get_bucket_info"; }
24 };
25
26 void RGWOp_Bucket_Info::execute()
27 {
28 RGWBucketAdminOpState op_state;
29
30 bool fetch_stats;
31
32 std::string bucket;
33
34 string uid_str;
35
36 RESTArgs::get_string(s, "uid", uid_str, &uid_str);
37 rgw_user uid(uid_str);
38
39 RESTArgs::get_string(s, "bucket", bucket, &bucket);
40 RESTArgs::get_bool(s, "stats", false, &fetch_stats);
41
42 op_state.set_user_id(uid);
43 op_state.set_bucket_name(bucket);
44 op_state.set_fetch_stats(fetch_stats);
45
46 http_ret = RGWBucketAdminOp::info(store, op_state, flusher);
47 }
48
49 class RGWOp_Get_Policy : public RGWRESTOp {
50
51 public:
52 RGWOp_Get_Policy() {}
53
54 int check_caps(RGWUserCaps& caps) override {
55 return caps.check_cap("buckets", RGW_CAP_READ);
56 }
57
58 void execute() override;
59
60 const string name() override { return "get_policy"; }
61 };
62
63 void RGWOp_Get_Policy::execute()
64 {
65 RGWBucketAdminOpState op_state;
66
67 std::string bucket;
68 std::string object;
69
70 RESTArgs::get_string(s, "bucket", bucket, &bucket);
71 RESTArgs::get_string(s, "object", object, &object);
72
73 op_state.set_bucket_name(bucket);
74 op_state.set_object(object);
75
76 http_ret = RGWBucketAdminOp::get_policy(store, op_state, flusher);
77 }
78
79 class RGWOp_Check_Bucket_Index : public RGWRESTOp {
80
81 public:
82 RGWOp_Check_Bucket_Index() {}
83
84 int check_caps(RGWUserCaps& caps) override {
85 return caps.check_cap("buckets", RGW_CAP_WRITE);
86 }
87
88 void execute() override;
89
90 const string name() override { return "check_bucket_index"; }
91 };
92
93 void RGWOp_Check_Bucket_Index::execute()
94 {
95 std::string bucket;
96
97 bool fix_index;
98 bool check_objects;
99
100 RGWBucketAdminOpState op_state;
101
102 RESTArgs::get_string(s, "bucket", bucket, &bucket);
103 RESTArgs::get_bool(s, "fix", false, &fix_index);
104 RESTArgs::get_bool(s, "check-objects", false, &check_objects);
105
106 op_state.set_bucket_name(bucket);
107 op_state.set_fix_index(fix_index);
108 op_state.set_check_objects(check_objects);
109
110 http_ret = RGWBucketAdminOp::check_index(store, op_state, flusher);
111 }
112
113 class RGWOp_Bucket_Link : public RGWRESTOp {
114
115 public:
116 RGWOp_Bucket_Link() {}
117
118 int check_caps(RGWUserCaps& caps) override {
119 return caps.check_cap("buckets", RGW_CAP_WRITE);
120 }
121
122 void execute() override;
123
124 const string name() override { return "link_bucket"; }
125 };
126
127 void RGWOp_Bucket_Link::execute()
128 {
129 std::string uid_str;
130 std::string bucket;
131 std::string bucket_id;
132
133 RGWBucketAdminOpState op_state;
134
135 RESTArgs::get_string(s, "uid", uid_str, &uid_str);
136 RESTArgs::get_string(s, "bucket", bucket, &bucket);
137 RESTArgs::get_string(s, "bucket-id", bucket_id, &bucket_id);
138
139 rgw_user uid(uid_str);
140 op_state.set_user_id(uid);
141 op_state.set_bucket_name(bucket);
142 op_state.set_bucket_id(bucket_id);
143
144 http_ret = RGWBucketAdminOp::link(store, op_state);
145 }
146
147 class RGWOp_Bucket_Unlink : public RGWRESTOp {
148
149 public:
150 RGWOp_Bucket_Unlink() {}
151
152 int check_caps(RGWUserCaps& caps) override {
153 return caps.check_cap("buckets", RGW_CAP_WRITE);
154 }
155
156 void execute() override;
157
158 const string name() override { return "unlink_bucket"; }
159 };
160
161 void RGWOp_Bucket_Unlink::execute()
162 {
163 std::string uid_str;
164 std::string bucket;
165
166 RGWBucketAdminOpState op_state;
167
168 RESTArgs::get_string(s, "uid", uid_str, &uid_str);
169 rgw_user uid(uid_str);
170
171 RESTArgs::get_string(s, "bucket", bucket, &bucket);
172
173 op_state.set_user_id(uid);
174 op_state.set_bucket_name(bucket);
175
176 http_ret = RGWBucketAdminOp::unlink(store, op_state);
177 }
178
179 class RGWOp_Bucket_Remove : public RGWRESTOp {
180
181 public:
182 RGWOp_Bucket_Remove() {}
183
184 int check_caps(RGWUserCaps& caps) override {
185 return caps.check_cap("buckets", RGW_CAP_WRITE);
186 }
187
188 void execute() override;
189
190 const string name() override { return "remove_bucket"; }
191 };
192
193 void RGWOp_Bucket_Remove::execute()
194 {
195 std::string bucket;
196 bool delete_children;
197
198 RGWBucketAdminOpState op_state;
199
200 RESTArgs::get_string(s, "bucket", bucket, &bucket);
201 RESTArgs::get_bool(s, "purge-objects", false, &delete_children);
202
203 op_state.set_bucket_name(bucket);
204 op_state.set_delete_children(delete_children);
205
206 http_ret = RGWBucketAdminOp::remove_bucket(store, op_state);
207 }
208
209 class RGWOp_Object_Remove: public RGWRESTOp {
210
211 public:
212 RGWOp_Object_Remove() {}
213
214 int check_caps(RGWUserCaps& caps) override {
215 return caps.check_cap("buckets", RGW_CAP_WRITE);
216 }
217
218 void execute() override;
219
220 const string name() override { return "remove_object"; }
221 };
222
223 void RGWOp_Object_Remove::execute()
224 {
225 std::string bucket;
226 std::string object;
227
228 RGWBucketAdminOpState op_state;
229
230 RESTArgs::get_string(s, "bucket", bucket, &bucket);
231 RESTArgs::get_string(s, "object", object, &object);
232
233 op_state.set_bucket_name(bucket);
234 op_state.set_object(object);
235
236 http_ret = RGWBucketAdminOp::remove_object(store, op_state);
237 }
238
239 RGWOp *RGWHandler_Bucket::op_get()
240 {
241
242 if (s->info.args.sub_resource_exists("policy"))
243 return new RGWOp_Get_Policy;
244
245 if (s->info.args.sub_resource_exists("index"))
246 return new RGWOp_Check_Bucket_Index;
247
248 return new RGWOp_Bucket_Info;
249 }
250
251 RGWOp *RGWHandler_Bucket::op_put()
252 {
253 return new RGWOp_Bucket_Link;
254 }
255
256 RGWOp *RGWHandler_Bucket::op_post()
257 {
258 return new RGWOp_Bucket_Unlink;
259 }
260
261 RGWOp *RGWHandler_Bucket::op_delete()
262 {
263 if (s->info.args.sub_resource_exists("object"))
264 return new RGWOp_Object_Remove;
265
266 return new RGWOp_Bucket_Remove;
267 }
268