]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/driver/rados/rgw_user.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / driver / rados / rgw_user.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #pragma once
5
6 #include <string>
7 #include <boost/algorithm/string.hpp>
8 #include "include/ceph_assert.h"
9
10 #include "include/types.h"
11 #include "rgw_common.h"
12 #include "rgw_tools.h"
13
14 #include "rgw_string.h"
15
16 #include "common/Formatter.h"
17 #include "rgw_formats.h"
18 #include "rgw_metadata.h"
19 #include "rgw_sal_fwd.h"
20
21 #define RGW_USER_ANON_ID "anonymous"
22
23 #define SECRET_KEY_LEN 40
24 #define PUBLIC_ID_LEN 20
25 #define RAND_SUBUSER_LEN 5
26
27 #define XMLNS_AWS_S3 "http://s3.amazonaws.com/doc/2006-03-01/"
28
29 class RGWUserCtl;
30 class RGWBucketCtl;
31 class RGWUserBuckets;
32
33 class RGWGetUserStats_CB;
34
35 /**
36 * A string wrapper that includes encode/decode functions
37 * for easily accessing a UID in all forms
38 */
39 struct RGWUID
40 {
41 rgw_user user_id;
42 void encode(bufferlist& bl) const {
43 std::string s;
44 user_id.to_str(s);
45 using ceph::encode;
46 encode(s, bl);
47 }
48 void decode(bufferlist::const_iterator& bl) {
49 std::string s;
50 using ceph::decode;
51 decode(s, bl);
52 user_id.from_str(s);
53 }
54 };
55 WRITE_CLASS_ENCODER(RGWUID)
56
57 /** Entry for bucket metadata collection */
58 struct bucket_meta_entry {
59 size_t size;
60 size_t size_rounded;
61 ceph::real_time creation_time;
62 uint64_t count;
63 };
64
65 extern int rgw_user_sync_all_stats(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver, rgw::sal::User* user, optional_yield y);
66 extern int rgw_user_get_all_buckets_stats(const DoutPrefixProvider *dpp,
67 rgw::sal::Driver* driver, rgw::sal::User* user,
68 std::map<std::string, bucket_meta_entry>& buckets_usage_map, optional_yield y);
69
70 /**
71 * Get the anonymous (ie, unauthenticated) user info.
72 */
73 extern void rgw_get_anon_user(RGWUserInfo& info);
74
75 extern void rgw_perm_to_str(uint32_t mask, char *buf, int len);
76 extern uint32_t rgw_str_to_perm(const char *str);
77
78 extern int rgw_validate_tenant_name(const std::string& t);
79
80 enum ObjectKeyType {
81 KEY_TYPE_SWIFT,
82 KEY_TYPE_S3,
83 KEY_TYPE_UNDEFINED
84 };
85
86 enum RGWKeyPoolOp {
87 GENERATE_KEY,
88 MODIFY_KEY
89 };
90
91 enum RGWUserId {
92 RGW_USER_ID,
93 RGW_SWIFT_USERNAME,
94 RGW_USER_EMAIL,
95 RGW_ACCESS_KEY,
96 };
97
98 /*
99 * An RGWUser class along with supporting classes created
100 * to support the creation of an RESTful administrative API
101 */
102 struct RGWUserAdminOpState {
103 // user attributes
104 std::unique_ptr<rgw::sal::User> user;
105 std::string user_email;
106 std::string display_name;
107 rgw_user new_user_id;
108 bool overwrite_new_user = false;
109 int32_t max_buckets{RGW_DEFAULT_MAX_BUCKETS};
110 __u8 suspended{0};
111 __u8 admin{0};
112 __u8 system{0};
113 __u8 exclusive{0};
114 __u8 fetch_stats{0};
115 __u8 sync_stats{0};
116 std::string caps;
117 RGWObjVersionTracker objv;
118 uint32_t op_mask{0};
119 std::map<int, std::string> temp_url_keys;
120
121 // subuser attributes
122 std::string subuser;
123 uint32_t perm_mask{RGW_PERM_NONE};
124
125 // key_attributes
126 std::string id; // access key
127 std::string key; // secret key
128 // access keys fetched for a user in the middle of an op
129 std::map<std::string, RGWAccessKey> op_access_keys;
130 int32_t key_type{-1};
131 bool access_key_exist = false;
132
133 std::set<std::string> mfa_ids;
134
135 // operation attributes
136 bool existing_user{false};
137 bool existing_key{false};
138 bool existing_subuser{false};
139 bool existing_email{false};
140 bool subuser_specified{false};
141 bool gen_secret{false};
142 bool gen_access{false};
143 bool gen_subuser{false};
144 bool id_specified{false};
145 bool key_specified{false};
146 bool type_specified{false};
147 bool key_type_setbycontext{false}; // key type set by user or subuser context
148 bool purge_data{false};
149 bool purge_keys{false};
150 bool display_name_specified{false};
151 bool user_email_specified{false};
152 bool max_buckets_specified{false};
153 bool perm_specified{false};
154 bool op_mask_specified{false};
155 bool caps_specified{false};
156 bool suspension_op{false};
157 bool admin_specified{false};
158 bool system_specified{false};
159 bool key_op{false};
160 bool temp_url_key_specified{false};
161 bool found_by_uid{false};
162 bool found_by_email{false};
163 bool found_by_key{false};
164 bool mfa_ids_specified{false};
165
166 // req parameters
167 bool populated{false};
168 bool initialized{false};
169 bool key_params_checked{false};
170 bool subuser_params_checked{false};
171 bool user_params_checked{false};
172
173 bool bucket_quota_specified{false};
174 bool user_quota_specified{false};
175 bool bucket_ratelimit_specified{false};
176 bool user_ratelimit_specified{false};
177
178 RGWQuota quota;
179 RGWRateLimitInfo user_ratelimit;
180 RGWRateLimitInfo bucket_ratelimit;
181
182 // req parameters for listing user
183 std::string marker{""};
184 uint32_t max_entries{1000};
185 rgw_placement_rule default_placement; // user default placement
186 bool default_placement_specified{false};
187
188 std::list<std::string> placement_tags; // user default placement_tags
189 bool placement_tags_specified{false};
190
191 void set_access_key(const std::string& access_key) {
192 if (access_key.empty())
193 return;
194
195 id = access_key;
196 id_specified = true;
197 gen_access = false;
198 key_op = true;
199 }
200
201 void set_secret_key(const std::string& secret_key) {
202 if (secret_key.empty())
203 return;
204
205 key = secret_key;
206 key_specified = true;
207 gen_secret = false;
208 key_op = true;
209 }
210
211 void set_user_id(const rgw_user& id);
212
213 void set_new_user_id(const rgw_user& id) {
214 if (id.empty())
215 return;
216
217 new_user_id = id;
218 }
219 void set_overwrite_new_user(bool b) {
220 overwrite_new_user = b;
221 }
222
223 void set_user_email(std::string& email) {
224 /* always lowercase email address */
225 boost::algorithm::to_lower(email);
226 user_email = email;
227 user_email_specified = true;
228 }
229
230 void set_display_name(const std::string& name) {
231 if (name.empty())
232 return;
233
234 display_name = name;
235 display_name_specified = true;
236 }
237
238 void set_subuser(std::string& _subuser);
239
240 void set_caps(const std::string& _caps) {
241 if (_caps.empty())
242 return;
243
244 caps = _caps;
245 caps_specified = true;
246 }
247
248 void set_perm(uint32_t perm) {
249 perm_mask = perm;
250 perm_specified = true;
251 }
252
253 void set_op_mask(uint32_t mask) {
254 op_mask = mask;
255 op_mask_specified = true;
256 }
257
258 void set_temp_url_key(const std::string& key, int index) {
259 temp_url_keys[index] = key;
260 temp_url_key_specified = true;
261 }
262
263 void set_key_type(int32_t type) {
264 key_type = type;
265 type_specified = true;
266 }
267
268 void set_access_key_exist() {
269 access_key_exist = true;
270 }
271
272 void set_suspension(__u8 is_suspended) {
273 suspended = is_suspended;
274 suspension_op = true;
275 }
276
277 void set_admin(__u8 is_admin) {
278 admin = is_admin;
279 admin_specified = true;
280 }
281
282 void set_system(__u8 is_system) {
283 system = is_system;
284 system_specified = true;
285 }
286
287 void set_exclusive(__u8 is_exclusive) {
288 exclusive = is_exclusive;
289 }
290
291 void set_fetch_stats(__u8 is_fetch_stats) {
292 fetch_stats = is_fetch_stats;
293 }
294
295 void set_sync_stats(__u8 is_sync_stats) {
296 sync_stats = is_sync_stats;
297 }
298
299 void set_user_info(RGWUserInfo& user_info);
300
301 void set_user_version_tracker(RGWObjVersionTracker& objv_tracker);
302
303 void set_max_buckets(int32_t mb) {
304 max_buckets = mb;
305 max_buckets_specified = true;
306 }
307
308 void set_gen_access() {
309 gen_access = true;
310 key_op = true;
311 }
312
313 void set_gen_secret() {
314 gen_secret = true;
315 key_op = true;
316 }
317
318 void set_generate_key() {
319 if (id.empty())
320 gen_access = true;
321 if (key.empty())
322 gen_secret = true;
323 key_op = true;
324 }
325
326 void clear_generate_key() {
327 gen_access = false;
328 gen_secret = false;
329 }
330
331 void set_purge_keys() {
332 purge_keys = true;
333 key_op = true;
334 }
335
336 void set_bucket_quota(RGWQuotaInfo& quotas) {
337 quota.bucket_quota = quotas;
338 bucket_quota_specified = true;
339 }
340
341 void set_user_quota(RGWQuotaInfo& quotas) {
342 quota.user_quota = quotas;
343 user_quota_specified = true;
344 }
345
346 void set_bucket_ratelimit(RGWRateLimitInfo& ratelimit) {
347 bucket_ratelimit = ratelimit;
348 bucket_ratelimit_specified = true;
349 }
350
351 void set_user_ratelimit(RGWRateLimitInfo& ratelimit) {
352 user_ratelimit = ratelimit;
353 user_ratelimit_specified = true;
354 }
355
356 void set_mfa_ids(const std::set<std::string>& ids) {
357 mfa_ids = ids;
358 mfa_ids_specified = true;
359 }
360
361 void set_default_placement(const rgw_placement_rule& _placement) {
362 default_placement = _placement;
363 default_placement_specified = true;
364 }
365
366 void set_placement_tags(const std::list<std::string>& _tags) {
367 placement_tags = _tags;
368 placement_tags_specified = true;
369 }
370
371 bool is_populated() { return populated; }
372 bool is_initialized() { return initialized; }
373 bool has_existing_user() { return existing_user; }
374 bool has_existing_key() { return existing_key; }
375 bool has_existing_subuser() { return existing_subuser; }
376 bool has_existing_email() { return existing_email; }
377 bool has_subuser() { return subuser_specified; }
378 bool has_key_op() { return key_op; }
379 bool has_caps_op() { return caps_specified; }
380 bool has_suspension_op() { return suspension_op; }
381 bool has_subuser_perm() { return perm_specified; }
382 bool has_op_mask() { return op_mask_specified; }
383 bool will_gen_access() { return gen_access; }
384 bool will_gen_secret() { return gen_secret; }
385 bool will_gen_subuser() { return gen_subuser; }
386 bool will_purge_keys() { return purge_keys; }
387 bool will_purge_data() { return purge_data; }
388 bool will_generate_subuser() { return gen_subuser; }
389 bool has_bucket_quota() { return bucket_quota_specified; }
390 bool has_user_quota() { return user_quota_specified; }
391 void set_populated() { populated = true; }
392 void clear_populated() { populated = false; }
393 void set_initialized() { initialized = true; }
394 void set_existing_user(bool flag) { existing_user = flag; }
395 void set_existing_key(bool flag) { existing_key = flag; }
396 void set_existing_subuser(bool flag) { existing_subuser = flag; }
397 void set_existing_email(bool flag) { existing_email = flag; }
398 void set_purge_data(bool flag) { purge_data = flag; }
399 void set_generate_subuser(bool flag) { gen_subuser = flag; }
400 __u8 get_suspension_status() { return suspended; }
401 int32_t get_key_type() {return key_type; }
402 bool get_access_key_exist() {return access_key_exist; }
403 uint32_t get_subuser_perm() { return perm_mask; }
404 int32_t get_max_buckets() { return max_buckets; }
405 uint32_t get_op_mask() { return op_mask; }
406 RGWQuotaInfo& get_bucket_quota() { return quota.bucket_quota; }
407 RGWQuotaInfo& get_user_quota() { return quota.user_quota; }
408 std::set<std::string>& get_mfa_ids() { return mfa_ids; }
409
410 rgw::sal::User* get_user() { return user.get(); }
411 const rgw_user& get_user_id();
412 std::string get_subuser() { return subuser; }
413 std::string get_access_key() { return id; }
414 std::string get_secret_key() { return key; }
415 std::string get_caps() { return caps; }
416 std::string get_user_email() { return user_email; }
417 std::string get_display_name() { return display_name; }
418 rgw_user& get_new_uid() { return new_user_id; }
419 bool get_overwrite_new_user() const { return overwrite_new_user; }
420 std::map<int, std::string>& get_temp_url_keys() { return temp_url_keys; }
421
422 RGWUserInfo& get_user_info();
423
424 std::map<std::string, RGWAccessKey>* get_swift_keys();
425 std::map<std::string, RGWAccessKey>* get_access_keys();
426 std::map<std::string, RGWSubUser>* get_subusers();
427
428 RGWUserCaps* get_caps_obj();
429
430 std::string build_default_swift_kid();
431
432 std::string generate_subuser();
433
434 RGWUserAdminOpState(rgw::sal::Driver* driver);
435 };
436
437 class RGWUser;
438
439 class RGWAccessKeyPool
440 {
441 RGWUser *user{nullptr};
442
443 std::map<std::string, int, ltstr_nocase> key_type_map;
444 rgw_user user_id;
445 rgw::sal::Driver* driver{nullptr};
446
447 std::map<std::string, RGWAccessKey> *swift_keys{nullptr};
448 std::map<std::string, RGWAccessKey> *access_keys{nullptr};
449
450 // we don't want to allow keys for the anonymous user or a null user
451 bool keys_allowed{false};
452
453 private:
454 int create_key(RGWUserAdminOpState& op_state, std::string *err_msg = NULL);
455 int generate_key(const DoutPrefixProvider *dpp,
456 RGWUserAdminOpState& op_state, optional_yield y,
457 std::string *err_msg = NULL);
458 int modify_key(RGWUserAdminOpState& op_state, std::string *err_msg = NULL);
459
460 int check_key_owner(RGWUserAdminOpState& op_state);
461 bool check_existing_key(RGWUserAdminOpState& op_state);
462 int check_op(RGWUserAdminOpState& op_state, std::string *err_msg = NULL);
463
464 /* API Contract Fulfilment */
465 int execute_add(const DoutPrefixProvider *dpp,
466 RGWUserAdminOpState& op_state, std::string *err_msg,
467 bool defer_save, optional_yield y);
468 int execute_remove(const DoutPrefixProvider *dpp,
469 RGWUserAdminOpState& op_state, std::string *err_msg,
470 bool defer_save, optional_yield y);
471 int remove_subuser_keys(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg,
472 bool defer_save, optional_yield y);
473
474 int add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, bool defer_save,
475 optional_yield y);
476 int remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg,
477 bool defer_save, optional_yield y);
478 public:
479 explicit RGWAccessKeyPool(RGWUser* usr);
480
481 int init(RGWUserAdminOpState& op_state);
482
483 /* API Contracted Methods */
484 int add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y,
485 std::string *err_msg = NULL);
486 int remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y,
487 std::string *err_msg = NULL);
488
489 friend class RGWUser;
490 friend class RGWSubUserPool;
491 };
492
493 class RGWSubUserPool
494 {
495 RGWUser *user{nullptr};
496
497 rgw_user user_id;
498 rgw::sal::Driver* driver{nullptr};
499 bool subusers_allowed{false};
500
501 std::map<std::string, RGWSubUser> *subuser_map{nullptr};
502
503 private:
504 int check_op(RGWUserAdminOpState& op_state, std::string *err_msg = NULL);
505
506 /* API Contract Fulfillment */
507 int execute_add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, bool defer_save, optional_yield y);
508 int execute_remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, bool defer_save, optional_yield y);
509 int execute_modify(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, bool defer_save, optional_yield y);
510
511 int add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, bool defer_save,
512 optional_yield y);
513 int remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, bool defer_save, optional_yield y);
514 int modify(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y, std::string *err_msg, bool defer_save);
515 public:
516 explicit RGWSubUserPool(RGWUser *user);
517
518 bool exists(std::string subuser);
519 int init(RGWUserAdminOpState& op_state);
520
521 /* API contracted methods */
522 int add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y,
523 std::string *err_msg = NULL);
524 int remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y, std::string *err_msg = NULL);
525 int modify(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y, std::string *err_msg = NULL);
526
527 friend class RGWUser;
528 };
529
530 class RGWUserCapPool
531 {
532 RGWUserCaps *caps{nullptr};
533 bool caps_allowed{false};
534 RGWUser *user{nullptr};
535
536 private:
537 int add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, bool defer_save,
538 optional_yield y);
539 int remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, bool defer_save,
540 optional_yield y);
541
542 public:
543 explicit RGWUserCapPool(RGWUser *user);
544
545 int init(RGWUserAdminOpState& op_state);
546
547 /* API contracted methods */
548 int add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y,
549 std::string *err_msg = NULL);
550 int remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y, std::string *err_msg = NULL);
551
552 friend class RGWUser;
553 };
554
555 class RGWUser
556 {
557
558 private:
559 RGWUserInfo old_info;
560 rgw::sal::Driver* driver{nullptr};
561
562 rgw_user user_id;
563 bool info_stored{false};
564
565 void set_populated() { info_stored = true; }
566 void clear_populated() { info_stored = false; }
567 bool is_populated() { return info_stored; }
568
569 int check_op(RGWUserAdminOpState& req, std::string *err_msg);
570 int update(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, optional_yield y);
571
572 void clear_members();
573 void init_default();
574
575 /* API Contract Fulfillment */
576 int execute_add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg,
577 optional_yield y);
578 int execute_remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state,
579 std::string *err_msg, optional_yield y);
580 int execute_modify(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, optional_yield y);
581 int execute_rename(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, std::string *err_msg, optional_yield y);
582
583 public:
584 RGWUser();
585
586 int init(const DoutPrefixProvider *dpp, rgw::sal::Driver* storage, RGWUserAdminOpState& op_state,
587 optional_yield y);
588
589 int init_storage(rgw::sal::Driver* storage);
590 int init(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y);
591 int init_members(RGWUserAdminOpState& op_state);
592
593 rgw::sal::Driver* get_driver() { return driver; }
594
595 /* API Contracted Members */
596 RGWUserCapPool caps;
597 RGWAccessKeyPool keys;
598 RGWSubUserPool subusers;
599
600 /* API Contracted Methods */
601 int add(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y, std::string *err_msg = NULL);
602
603 int remove(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y, std::string *err_msg = NULL);
604
605 int rename(RGWUserAdminOpState& op_state, optional_yield y, const DoutPrefixProvider *dpp, std::string *err_msg = NULL);
606
607 /* remove an already populated RGWUser */
608 int remove(std::string *err_msg = NULL);
609
610 int modify(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, optional_yield y, std::string *err_msg = NULL);
611
612 /* retrieve info from an existing user in the RGW system */
613 int info(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, RGWUserInfo& fetched_info, optional_yield y,
614 std::string *err_msg = NULL);
615
616 /* info from an already populated RGWUser */
617 int info (RGWUserInfo& fetched_info, std::string *err_msg = NULL);
618
619 /* list the existing users */
620 int list(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher);
621
622 friend class RGWAccessKeyPool;
623 friend class RGWSubUserPool;
624 friend class RGWUserCapPool;
625 };
626
627 /* Wrappers for admin API functionality */
628
629 class RGWUserAdminOp_User
630 {
631 public:
632 static int list(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver,
633 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher);
634
635 static int info(const DoutPrefixProvider *dpp,
636 rgw::sal::Driver* driver,
637 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
638 optional_yield y);
639
640 static int create(const DoutPrefixProvider *dpp,
641 rgw::sal::Driver* driver,
642 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
643 optional_yield y);
644
645 static int modify(const DoutPrefixProvider *dpp,
646 rgw::sal::Driver* driver,
647 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher, optional_yield y);
648
649 static int remove(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver,
650 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher, optional_yield y);
651 };
652
653 class RGWUserAdminOp_Subuser
654 {
655 public:
656 static int create(const DoutPrefixProvider *dpp,
657 rgw::sal::Driver* driver,
658 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
659 optional_yield y);
660
661 static int modify(const DoutPrefixProvider *dpp,
662 rgw::sal::Driver* driver,
663 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
664 optional_yield y);
665
666 static int remove(const DoutPrefixProvider *dpp,
667 rgw::sal::Driver* driver,
668 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
669 optional_yield y);
670 };
671
672 class RGWUserAdminOp_Key
673 {
674 public:
675 static int create(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver,
676 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
677 optional_yield y);
678
679 static int remove(const DoutPrefixProvider *dpp,
680 rgw::sal::Driver* driver,
681 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
682 optional_yield y);
683 };
684
685 class RGWUserAdminOp_Caps
686 {
687 public:
688 static int add(const DoutPrefixProvider *dpp,
689 rgw::sal::Driver* driver,
690 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
691 optional_yield y);
692
693 static int remove(const DoutPrefixProvider *dpp,
694 rgw::sal::Driver* driver,
695 RGWUserAdminOpState& op_state, RGWFormatterFlusher& flusher,
696 optional_yield y);
697 };
698
699 struct RGWUserCompleteInfo {
700 RGWUserInfo info;
701 std::map<std::string, bufferlist> attrs;
702 bool has_attrs{false};
703
704 void dump(Formatter * const f) const {
705 info.dump(f);
706 encode_json("attrs", attrs, f);
707 }
708
709 void decode_json(JSONObj *obj) {
710 decode_json_obj(info, obj);
711 has_attrs = JSONDecoder::decode_json("attrs", attrs, obj);
712 }
713 };
714
715 class RGWUserMetadataObject : public RGWMetadataObject {
716 RGWUserCompleteInfo uci;
717 public:
718 RGWUserMetadataObject() {}
719 RGWUserMetadataObject(const RGWUserCompleteInfo& _uci, const obj_version& v, real_time m)
720 : uci(_uci) {
721 objv = v;
722 mtime = m;
723 }
724
725 void dump(Formatter *f) const override {
726 uci.dump(f);
727 }
728
729 RGWUserCompleteInfo& get_uci() {
730 return uci;
731 }
732 };
733
734 class RGWUserMetadataHandler;
735
736 class RGWUserCtl
737 {
738 struct Svc {
739 RGWSI_Zone *zone{nullptr};
740 RGWSI_User *user{nullptr};
741 } svc;
742
743 struct Ctl {
744 RGWBucketCtl *bucket{nullptr};
745 } ctl;
746
747 RGWUserMetadataHandler *umhandler;
748 RGWSI_MetaBackend_Handler *be_handler{nullptr};
749
750 public:
751 RGWUserCtl(RGWSI_Zone *zone_svc,
752 RGWSI_User *user_svc,
753 RGWUserMetadataHandler *_umhandler);
754
755 void init(RGWBucketCtl *bucket_ctl) {
756 ctl.bucket = bucket_ctl;
757 }
758
759 RGWBucketCtl *get_bucket_ctl() {
760 return ctl.bucket;
761 }
762
763 struct GetParams {
764 RGWObjVersionTracker *objv_tracker{nullptr};
765 ceph::real_time *mtime{nullptr};
766 rgw_cache_entry_info *cache_info{nullptr};
767 std::map<std::string, bufferlist> *attrs{nullptr};
768
769 GetParams() {}
770
771 GetParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
772 objv_tracker = _objv_tracker;
773 return *this;
774 }
775
776 GetParams& set_mtime(ceph::real_time *_mtime) {
777 mtime = _mtime;
778 return *this;
779 }
780
781 GetParams& set_cache_info(rgw_cache_entry_info *_cache_info) {
782 cache_info = _cache_info;
783 return *this;
784 }
785
786 GetParams& set_attrs(std::map<std::string, bufferlist> *_attrs) {
787 attrs = _attrs;
788 return *this;
789 }
790 };
791
792 struct PutParams {
793 RGWUserInfo *old_info{nullptr};
794 RGWObjVersionTracker *objv_tracker{nullptr};
795 ceph::real_time mtime;
796 bool exclusive{false};
797 std::map<std::string, bufferlist> *attrs{nullptr};
798
799 PutParams() {}
800
801 PutParams& set_old_info(RGWUserInfo *_info) {
802 old_info = _info;
803 return *this;
804 }
805
806 PutParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
807 objv_tracker = _objv_tracker;
808 return *this;
809 }
810
811 PutParams& set_mtime(const ceph::real_time& _mtime) {
812 mtime = _mtime;
813 return *this;
814 }
815
816 PutParams& set_exclusive(bool _exclusive) {
817 exclusive = _exclusive;
818 return *this;
819 }
820
821 PutParams& set_attrs(std::map<std::string, bufferlist> *_attrs) {
822 attrs = _attrs;
823 return *this;
824 }
825 };
826
827 struct RemoveParams {
828 RGWObjVersionTracker *objv_tracker{nullptr};
829
830 RemoveParams() {}
831
832 RemoveParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
833 objv_tracker = _objv_tracker;
834 return *this;
835 }
836 };
837
838 int get_info_by_uid(const DoutPrefixProvider *dpp,
839 const rgw_user& uid, RGWUserInfo *info,
840 optional_yield y, const GetParams& params = {});
841 int get_info_by_email(const DoutPrefixProvider *dpp,
842 const std::string& email, RGWUserInfo *info,
843 optional_yield y, const GetParams& params = {});
844 int get_info_by_swift(const DoutPrefixProvider *dpp,
845 const std::string& swift_name, RGWUserInfo *info,
846 optional_yield y, const GetParams& params = {});
847 int get_info_by_access_key(const DoutPrefixProvider *dpp,
848 const std::string& access_key, RGWUserInfo *info,
849 optional_yield y, const GetParams& params = {});
850
851 int get_attrs_by_uid(const DoutPrefixProvider *dpp,
852 const rgw_user& user_id,
853 std::map<std::string, bufferlist> *attrs,
854 optional_yield y,
855 RGWObjVersionTracker *objv_tracker = nullptr);
856
857 int store_info(const DoutPrefixProvider *dpp,
858 const RGWUserInfo& info, optional_yield y,
859 const PutParams& params = {});
860 int remove_info(const DoutPrefixProvider *dpp,
861 const RGWUserInfo& info, optional_yield y,
862 const RemoveParams& params = {});
863
864 int list_buckets(const DoutPrefixProvider *dpp,
865 const rgw_user& user,
866 const std::string& marker,
867 const std::string& end_marker,
868 uint64_t max,
869 bool need_stats,
870 RGWUserBuckets *buckets,
871 bool *is_truncated,
872 optional_yield y,
873 uint64_t default_max = 1000);
874
875 int read_stats(const DoutPrefixProvider *dpp,
876 const rgw_user& user, RGWStorageStats *stats,
877 optional_yield y,
878 ceph::real_time *last_stats_sync = nullptr, /* last time a full stats sync completed */
879 ceph::real_time *last_stats_update = nullptr); /* last time a stats update was done */
880 };
881
882 class RGWUserMetaHandlerAllocator {
883 public:
884 static RGWMetadataHandler *alloc(RGWSI_User *user_svc);
885 };