1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "rgw_op.h"
#include "rgw_bucket.h"
#include "rgw_rest_bucket.h"
#include "include/str_list.h"
#include "services/svc_sys_obj.h"
#define dout_subsys ceph_subsys_rgw
class RGWOp_Bucket_Info : public RGWRESTOp {
public:
RGWOp_Bucket_Info() {}
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_READ);
}
void execute() override;
const char* name() const override { return "get_bucket_info"; }
};
void RGWOp_Bucket_Info::execute()
{
RGWBucketAdminOpState op_state;
bool fetch_stats;
std::string bucket;
string uid_str;
RESTArgs::get_string(s, "uid", uid_str, &uid_str);
rgw_user uid(uid_str);
RESTArgs::get_string(s, "bucket", bucket, &bucket);
RESTArgs::get_bool(s, "stats", false, &fetch_stats);
op_state.set_user_id(uid);
op_state.set_bucket_name(bucket);
op_state.set_fetch_stats(fetch_stats);
http_ret = RGWBucketAdminOp::info(store, op_state, flusher);
}
class RGWOp_Get_Policy : public RGWRESTOp {
public:
RGWOp_Get_Policy() {}
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_READ);
}
void execute() override;
const char* name() const override { return "get_policy"; }
};
void RGWOp_Get_Policy::execute()
{
RGWBucketAdminOpState op_state;
std::string bucket;
std::string object;
RESTArgs::get_string(s, "bucket", bucket, &bucket);
RESTArgs::get_string(s, "object", object, &object);
op_state.set_bucket_name(bucket);
op_state.set_object(object);
http_ret = RGWBucketAdminOp::get_policy(store, op_state, flusher);
}
class RGWOp_Check_Bucket_Index : public RGWRESTOp {
public:
RGWOp_Check_Bucket_Index() {}
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_WRITE);
}
void execute() override;
const char* name() const override { return "check_bucket_index"; }
};
void RGWOp_Check_Bucket_Index::execute()
{
std::string bucket;
bool fix_index;
bool check_objects;
RGWBucketAdminOpState op_state;
RESTArgs::get_string(s, "bucket", bucket, &bucket);
RESTArgs::get_bool(s, "fix", false, &fix_index);
RESTArgs::get_bool(s, "check-objects", false, &check_objects);
op_state.set_bucket_name(bucket);
op_state.set_fix_index(fix_index);
op_state.set_check_objects(check_objects);
http_ret = RGWBucketAdminOp::check_index(store, op_state, flusher);
}
class RGWOp_Bucket_Link : public RGWRESTOp {
public:
RGWOp_Bucket_Link() {}
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_WRITE);
}
void execute() override;
const char* name() const override { return "link_bucket"; }
};
void RGWOp_Bucket_Link::execute()
{
std::string uid_str;
std::string bucket;
std::string bucket_id;
RGWBucketAdminOpState op_state;
RESTArgs::get_string(s, "uid", uid_str, &uid_str);
RESTArgs::get_string(s, "bucket", bucket, &bucket);
RESTArgs::get_string(s, "bucket-id", bucket_id, &bucket_id);
rgw_user uid(uid_str);
op_state.set_user_id(uid);
op_state.set_bucket_name(bucket);
op_state.set_bucket_id(bucket_id);
http_ret = RGWBucketAdminOp::link(store, op_state);
}
class RGWOp_Bucket_Unlink : public RGWRESTOp {
public:
RGWOp_Bucket_Unlink() {}
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_WRITE);
}
void execute() override;
const char* name() const override { return "unlink_bucket"; }
};
void RGWOp_Bucket_Unlink::execute()
{
std::string uid_str;
std::string bucket;
RGWBucketAdminOpState op_state;
RESTArgs::get_string(s, "uid", uid_str, &uid_str);
rgw_user uid(uid_str);
RESTArgs::get_string(s, "bucket", bucket, &bucket);
op_state.set_user_id(uid);
op_state.set_bucket_name(bucket);
http_ret = RGWBucketAdminOp::unlink(store, op_state);
}
class RGWOp_Bucket_Remove : public RGWRESTOp {
public:
RGWOp_Bucket_Remove() {}
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_WRITE);
}
void execute() override;
const char* name() const override { return "remove_bucket"; }
};
void RGWOp_Bucket_Remove::execute()
{
std::string bucket;
bool delete_children;
RGWBucketAdminOpState op_state;
RESTArgs::get_string(s, "bucket", bucket, &bucket);
RESTArgs::get_bool(s, "purge-objects", false, &delete_children);
op_state.set_bucket_name(bucket);
op_state.set_delete_children(delete_children);
http_ret = RGWBucketAdminOp::remove_bucket(store, op_state);
}
class RGWOp_Set_Bucket_Quota : public RGWRESTOp {
public:
RGWOp_Set_Bucket_Quota() {}
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_WRITE);
}
void execute() override;
const char* name() const override { return "set_bucket_quota"; }
};
#define QUOTA_INPUT_MAX_LEN 1024
void RGWOp_Set_Bucket_Quota::execute()
{
bool uid_arg_existed = false;
std::string uid_str;
RESTArgs::get_string(s, "uid", uid_str, &uid_str, &uid_arg_existed);
if (! uid_arg_existed) {
http_ret = -EINVAL;
return;
}
rgw_user uid(uid_str);
bool bucket_arg_existed = false;
std::string bucket;
RESTArgs::get_string(s, "bucket", bucket, &bucket, &bucket_arg_existed);
if (! bucket_arg_existed) {
http_ret = -EINVAL;
return;
}
bool use_http_params;
if (s->content_length > 0) {
use_http_params = false;
} else {
const char *encoding = s->info.env->get("HTTP_TRANSFER_ENCODING");
use_http_params = (!encoding || strcmp(encoding, "chunked") != 0);
}
RGWQuotaInfo quota;
if (!use_http_params) {
bool empty;
http_ret = rgw_rest_get_json_input(store->ctx(), s, quota, QUOTA_INPUT_MAX_LEN, &empty);
if (http_ret < 0) {
if (!empty)
return;
/* was probably chunked input, but no content provided, configure via http params */
use_http_params = true;
}
}
if (use_http_params) {
RGWBucketInfo bucket_info;
map<string, bufferlist> attrs;
auto obj_ctx = store->svc.sysobj->init_obj_ctx();
http_ret = store->get_bucket_info(obj_ctx, uid.tenant, bucket, bucket_info, NULL, &attrs);
if (http_ret < 0) {
return;
}
RGWQuotaInfo *old_quota = &bucket_info.quota;
int64_t old_max_size_kb = rgw_rounded_kb(old_quota->max_size);
int64_t max_size_kb;
RESTArgs::get_int64(s, "max-objects", old_quota->max_objects, "a.max_objects);
RESTArgs::get_int64(s, "max-size-kb", old_max_size_kb, &max_size_kb);
quota.max_size = max_size_kb * 1024;
RESTArgs::get_bool(s, "enabled", old_quota->enabled, "a.enabled);
}
RGWBucketAdminOpState op_state;
op_state.set_user_id(uid);
op_state.set_bucket_name(bucket);
op_state.set_quota(quota);
http_ret = RGWBucketAdminOp::set_quota(store, op_state);
}
class RGWOp_Object_Remove: public RGWRESTOp {
public:
RGWOp_Object_Remove() {}
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_WRITE);
}
void execute() override;
const char* name() const override { return "remove_object"; }
};
void RGWOp_Object_Remove::execute()
{
std::string bucket;
std::string object;
RGWBucketAdminOpState op_state;
RESTArgs::get_string(s, "bucket", bucket, &bucket);
RESTArgs::get_string(s, "object", object, &object);
op_state.set_bucket_name(bucket);
op_state.set_object(object);
http_ret = RGWBucketAdminOp::remove_object(store, op_state);
}
RGWOp *RGWHandler_Bucket::op_get()
{
if (s->info.args.sub_resource_exists("policy"))
return new RGWOp_Get_Policy;
if (s->info.args.sub_resource_exists("index"))
return new RGWOp_Check_Bucket_Index;
return new RGWOp_Bucket_Info;
}
RGWOp *RGWHandler_Bucket::op_put()
{
if (s->info.args.sub_resource_exists("quota"))
return new RGWOp_Set_Bucket_Quota;
return new RGWOp_Bucket_Link;
}
RGWOp *RGWHandler_Bucket::op_post()
{
return new RGWOp_Bucket_Unlink;
}
RGWOp *RGWHandler_Bucket::op_delete()
{
if (s->info.args.sub_resource_exists("object"))
return new RGWOp_Object_Remove;
return new RGWOp_Bucket_Remove;
}
|