1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 #include "rgw_bucket.h"
6 #include "rgw_rest_bucket.h"
8 #include "include/str_list.h"
10 #define dout_subsys ceph_subsys_rgw
12 class RGWOp_Bucket_Info : public RGWRESTOp {
15 RGWOp_Bucket_Info() {}
17 int check_caps(RGWUserCaps& caps) override {
18 return caps.check_cap("buckets", RGW_CAP_READ);
21 void execute() override;
23 const string name() override { return "get_bucket_info"; }
26 void RGWOp_Bucket_Info::execute()
28 RGWBucketAdminOpState op_state;
36 RESTArgs::get_string(s, "uid", uid_str, &uid_str);
37 rgw_user uid(uid_str);
39 RESTArgs::get_string(s, "bucket", bucket, &bucket);
40 RESTArgs::get_bool(s, "stats", false, &fetch_stats);
42 op_state.set_user_id(uid);
43 op_state.set_bucket_name(bucket);
44 op_state.set_fetch_stats(fetch_stats);
46 http_ret = RGWBucketAdminOp::info(store, op_state, flusher);
49 class RGWOp_Get_Policy : public RGWRESTOp {
54 int check_caps(RGWUserCaps& caps) override {
55 return caps.check_cap("buckets", RGW_CAP_READ);
58 void execute() override;
60 const string name() override { return "get_policy"; }
63 void RGWOp_Get_Policy::execute()
65 RGWBucketAdminOpState op_state;
70 RESTArgs::get_string(s, "bucket", bucket, &bucket);
71 RESTArgs::get_string(s, "object", object, &object);
73 op_state.set_bucket_name(bucket);
74 op_state.set_object(object);
76 http_ret = RGWBucketAdminOp::get_policy(store, op_state, flusher);
79 class RGWOp_Check_Bucket_Index : public RGWRESTOp {
82 RGWOp_Check_Bucket_Index() {}
84 int check_caps(RGWUserCaps& caps) override {
85 return caps.check_cap("buckets", RGW_CAP_WRITE);
88 void execute() override;
90 const string name() override { return "check_bucket_index"; }
93 void RGWOp_Check_Bucket_Index::execute()
100 RGWBucketAdminOpState op_state;
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);
106 op_state.set_bucket_name(bucket);
107 op_state.set_fix_index(fix_index);
108 op_state.set_check_objects(check_objects);
110 http_ret = RGWBucketAdminOp::check_index(store, op_state, flusher);
113 class RGWOp_Bucket_Link : public RGWRESTOp {
116 RGWOp_Bucket_Link() {}
118 int check_caps(RGWUserCaps& caps) override {
119 return caps.check_cap("buckets", RGW_CAP_WRITE);
122 void execute() override;
124 const string name() override { return "link_bucket"; }
127 void RGWOp_Bucket_Link::execute()
131 std::string bucket_id;
133 RGWBucketAdminOpState op_state;
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);
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);
144 http_ret = RGWBucketAdminOp::link(store, op_state);
147 class RGWOp_Bucket_Unlink : public RGWRESTOp {
150 RGWOp_Bucket_Unlink() {}
152 int check_caps(RGWUserCaps& caps) override {
153 return caps.check_cap("buckets", RGW_CAP_WRITE);
156 void execute() override;
158 const string name() override { return "unlink_bucket"; }
161 void RGWOp_Bucket_Unlink::execute()
166 RGWBucketAdminOpState op_state;
168 RESTArgs::get_string(s, "uid", uid_str, &uid_str);
169 rgw_user uid(uid_str);
171 RESTArgs::get_string(s, "bucket", bucket, &bucket);
173 op_state.set_user_id(uid);
174 op_state.set_bucket_name(bucket);
176 http_ret = RGWBucketAdminOp::unlink(store, op_state);
179 class RGWOp_Bucket_Remove : public RGWRESTOp {
182 RGWOp_Bucket_Remove() {}
184 int check_caps(RGWUserCaps& caps) override {
185 return caps.check_cap("buckets", RGW_CAP_WRITE);
188 void execute() override;
190 const string name() override { return "remove_bucket"; }
193 void RGWOp_Bucket_Remove::execute()
196 bool delete_children;
198 RGWBucketAdminOpState op_state;
200 RESTArgs::get_string(s, "bucket", bucket, &bucket);
201 RESTArgs::get_bool(s, "purge-objects", false, &delete_children);
203 op_state.set_bucket_name(bucket);
204 op_state.set_delete_children(delete_children);
206 http_ret = RGWBucketAdminOp::remove_bucket(store, op_state);
209 class RGWOp_Object_Remove: public RGWRESTOp {
212 RGWOp_Object_Remove() {}
214 int check_caps(RGWUserCaps& caps) override {
215 return caps.check_cap("buckets", RGW_CAP_WRITE);
218 void execute() override;
220 const string name() override { return "remove_object"; }
223 void RGWOp_Object_Remove::execute()
228 RGWBucketAdminOpState op_state;
230 RESTArgs::get_string(s, "bucket", bucket, &bucket);
231 RESTArgs::get_string(s, "object", object, &object);
233 op_state.set_bucket_name(bucket);
234 op_state.set_object(object);
236 http_ret = RGWBucketAdminOp::remove_object(store, op_state);
239 RGWOp *RGWHandler_Bucket::op_get()
242 if (s->info.args.sub_resource_exists("policy"))
243 return new RGWOp_Get_Policy;
245 if (s->info.args.sub_resource_exists("index"))
246 return new RGWOp_Check_Bucket_Index;
248 return new RGWOp_Bucket_Info;
251 RGWOp *RGWHandler_Bucket::op_put()
253 return new RGWOp_Bucket_Link;
256 RGWOp *RGWHandler_Bucket::op_post()
258 return new RGWOp_Bucket_Unlink;
261 RGWOp *RGWHandler_Bucket::op_delete()
263 if (s->info.args.sub_resource_exists("object"))
264 return new RGWOp_Object_Remove;
266 return new RGWOp_Bucket_Remove;