]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_json_enc.cc
import ceph pacific 16.2.5
[ceph.git] / ceph / src / rgw / rgw_json_enc.cc
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 #include "rgw_common.h"
5 #include "rgw_zone.h"
6 #include "rgw_log.h"
7 #include "rgw_acl.h"
8 #include "rgw_acl_s3.h"
9 #include "rgw_cache.h"
10 #include "rgw_bucket.h"
11 #include "rgw_datalog.h"
12 #include "rgw_keystone.h"
13 #include "rgw_basic_types.h"
14 #include "rgw_op.h"
15 #include "rgw_data_sync.h"
16 #include "rgw_sync.h"
17 #include "rgw_orphan.h"
18 #include "rgw_bucket_sync.h"
19 #include "rgw_tools.h"
20
21 #include "common/ceph_json.h"
22 #include "common/Formatter.h"
23
24 #define dout_context g_ceph_context
25 #define dout_subsys ceph_subsys_rgw
26
27 void encode_json(const char *name, const obj_version& v, Formatter *f)
28 {
29 f->open_object_section(name);
30 f->dump_string("tag", v.tag);
31 f->dump_unsigned("ver", v.ver);
32 f->close_section();
33 }
34
35 void decode_json_obj(obj_version& v, JSONObj *obj)
36 {
37 JSONDecoder::decode_json("tag", v.tag, obj);
38 JSONDecoder::decode_json("ver", v.ver, obj);
39 }
40
41 void encode_json(const char *name, const RGWUserCaps& val, Formatter *f)
42 {
43 val.dump(f, name);
44 }
45
46
47 void encode_json(const char *name, const rgw_pool& pool, Formatter *f)
48 {
49 f->dump_string(name, pool.to_str());
50 }
51
52 void decode_json_obj(rgw_pool& pool, JSONObj *obj)
53 {
54 string s;
55 decode_json_obj(s, obj);
56 pool = rgw_pool(s);
57 }
58
59 void encode_json(const char *name, const rgw_placement_rule& r, Formatter *f)
60 {
61 encode_json(name, r.to_str(), f);
62 }
63
64 void decode_json_obj(rgw_placement_rule& v, JSONObj *obj)
65 {
66 string s;
67 decode_json_obj(s, obj);
68 v.from_str(s);
69 }
70
71 void RGWOLHInfo::dump(Formatter *f) const
72 {
73 encode_json("target", target, f);
74 }
75
76 void RGWOLHPendingInfo::dump(Formatter *f) const
77 {
78 utime_t ut(time);
79 encode_json("time", ut, f);
80 }
81
82 void RGWObjManifestPart::dump(Formatter *f) const
83 {
84 f->open_object_section("loc");
85 loc.dump(f);
86 f->close_section();
87 f->dump_unsigned("loc_ofs", loc_ofs);
88 f->dump_unsigned("size", size);
89 }
90
91 void RGWObjManifestRule::dump(Formatter *f) const
92 {
93 encode_json("start_part_num", start_part_num, f);
94 encode_json("start_ofs", start_ofs, f);
95 encode_json("part_size", part_size, f);
96 encode_json("stripe_max_size", stripe_max_size, f);
97 encode_json("override_prefix", override_prefix, f);
98 }
99
100 void rgw_bucket_placement::dump(Formatter *f) const
101 {
102 encode_json("bucket", bucket, f);
103 encode_json("placement_rule", placement_rule, f);
104 }
105
106 void rgw_obj_select::dump(Formatter *f) const
107 {
108 f->dump_string("placement_rule", placement_rule.to_str());
109 f->dump_object("obj", obj);
110 f->dump_object("raw_obj", raw_obj);
111 f->dump_bool("is_raw", is_raw);
112 }
113
114 void RGWObjManifest::obj_iterator::dump(Formatter *f) const
115 {
116 f->dump_unsigned("part_ofs", part_ofs);
117 f->dump_unsigned("stripe_ofs", stripe_ofs);
118 f->dump_unsigned("ofs", ofs);
119 f->dump_unsigned("stripe_size", stripe_size);
120 f->dump_int("cur_part_id", cur_part_id);
121 f->dump_int("cur_stripe", cur_stripe);
122 f->dump_string("cur_override_prefix", cur_override_prefix);
123 f->dump_object("location", location);
124 }
125
126 void RGWObjManifest::dump(Formatter *f) const
127 {
128 map<uint64_t, RGWObjManifestPart>::const_iterator iter = objs.begin();
129 f->open_array_section("objs");
130 for (; iter != objs.end(); ++iter) {
131 f->dump_unsigned("ofs", iter->first);
132 f->open_object_section("part");
133 iter->second.dump(f);
134 f->close_section();
135 }
136 f->close_section();
137 f->dump_unsigned("obj_size", obj_size);
138 ::encode_json("explicit_objs", explicit_objs, f);
139 ::encode_json("head_size", head_size, f);
140 ::encode_json("max_head_size", max_head_size, f);
141 ::encode_json("prefix", prefix, f);
142 ::encode_json("rules", rules, f);
143 ::encode_json("tail_instance", tail_instance, f);
144 ::encode_json("tail_placement", tail_placement, f);
145
146 // nullptr being passed into iterators since there
147 // is no cct and we aren't doing anything with these
148 // iterators that would write do the log
149 f->dump_object("begin_iter", obj_begin(nullptr));
150 f->dump_object("end_iter", obj_end(nullptr));
151 }
152
153 void rgw_log_entry::dump(Formatter *f) const
154 {
155 f->dump_string("object_owner", object_owner.to_str());
156 f->dump_string("bucket_owner", bucket_owner.to_str());
157 f->dump_string("bucket", bucket);
158 f->dump_stream("time") << time;
159 f->dump_string("remote_addr", remote_addr);
160 f->dump_string("user", user);
161 stringstream s;
162 s << obj;
163 f->dump_string("obj", s.str());
164 f->dump_string("op", op);
165 f->dump_string("uri", uri);
166 f->dump_string("http_status", http_status);
167 f->dump_string("error_code", error_code);
168 f->dump_unsigned("bytes_sent", bytes_sent);
169 f->dump_unsigned("bytes_received", bytes_received);
170 f->dump_unsigned("obj_size", obj_size);
171 f->dump_stream("total_time") << total_time;
172 f->dump_string("user_agent", user_agent);
173 f->dump_string("referrer", referrer);
174 f->dump_string("bucket_id", bucket_id);
175 f->dump_string("trans_id", trans_id);
176 }
177
178 void ACLPermission::dump(Formatter *f) const
179 {
180 f->dump_int("flags", flags);
181 }
182
183 void ACLGranteeType::dump(Formatter *f) const
184 {
185 f->dump_unsigned("type", type);
186 }
187
188 void ACLGrant::dump(Formatter *f) const
189 {
190 f->open_object_section("type");
191 type.dump(f);
192 f->close_section();
193
194 f->dump_string("id", id.to_str());
195 f->dump_string("email", email);
196
197 f->open_object_section("permission");
198 permission.dump(f);
199 f->close_section();
200
201 f->dump_string("name", name);
202 f->dump_int("group", (int)group);
203 f->dump_string("url_spec", url_spec);
204 }
205
206 void RGWAccessControlList::dump(Formatter *f) const
207 {
208 map<string, int>::const_iterator acl_user_iter = acl_user_map.begin();
209 f->open_array_section("acl_user_map");
210 for (; acl_user_iter != acl_user_map.end(); ++acl_user_iter) {
211 f->open_object_section("entry");
212 f->dump_string("user", acl_user_iter->first);
213 f->dump_int("acl", acl_user_iter->second);
214 f->close_section();
215 }
216 f->close_section();
217
218 map<uint32_t, int>::const_iterator acl_group_iter = acl_group_map.begin();
219 f->open_array_section("acl_group_map");
220 for (; acl_group_iter != acl_group_map.end(); ++acl_group_iter) {
221 f->open_object_section("entry");
222 f->dump_unsigned("group", acl_group_iter->first);
223 f->dump_int("acl", acl_group_iter->second);
224 f->close_section();
225 }
226 f->close_section();
227
228 multimap<string, ACLGrant>::const_iterator giter = grant_map.begin();
229 f->open_array_section("grant_map");
230 for (; giter != grant_map.end(); ++giter) {
231 f->open_object_section("entry");
232 f->dump_string("id", giter->first);
233 f->open_object_section("grant");
234 giter->second.dump(f);
235 f->close_section();
236 f->close_section();
237 }
238 f->close_section();
239 }
240
241 void ACLOwner::dump(Formatter *f) const
242 {
243 encode_json("id", id.to_str(), f);
244 encode_json("display_name", display_name, f);
245 }
246
247 void ACLOwner::decode_json(JSONObj *obj) {
248 string id_str;
249 JSONDecoder::decode_json("id", id_str, obj);
250 id.from_str(id_str);
251 JSONDecoder::decode_json("display_name", display_name, obj);
252 }
253
254 void RGWAccessControlPolicy::dump(Formatter *f) const
255 {
256 encode_json("acl", acl, f);
257 encode_json("owner", owner, f);
258 }
259
260 void ObjectMetaInfo::dump(Formatter *f) const
261 {
262 encode_json("size", size, f);
263 encode_json("mtime", utime_t(mtime), f);
264 }
265
266 void ObjectCacheInfo::dump(Formatter *f) const
267 {
268 encode_json("status", status, f);
269 encode_json("flags", flags, f);
270 encode_json("data", data, f);
271 encode_json_map("xattrs", "name", "value", "length", xattrs, f);
272 encode_json_map("rm_xattrs", "name", "value", "length", rm_xattrs, f);
273 encode_json("meta", meta, f);
274
275 }
276
277 void RGWCacheNotifyInfo::dump(Formatter *f) const
278 {
279 encode_json("op", op, f);
280 encode_json("obj", obj, f);
281 encode_json("obj_info", obj_info, f);
282 encode_json("ofs", ofs, f);
283 encode_json("ns", ns, f);
284 }
285
286 void RGWAccessKey::dump(Formatter *f) const
287 {
288 encode_json("access_key", id, f);
289 encode_json("secret_key", key, f);
290 encode_json("subuser", subuser, f);
291 }
292
293 void RGWAccessKey::dump_plain(Formatter *f) const
294 {
295 encode_json("access_key", id, f);
296 encode_json("secret_key", key, f);
297 }
298
299 void encode_json_plain(const char *name, const RGWAccessKey& val, Formatter *f)
300 {
301 f->open_object_section(name);
302 val.dump_plain(f);
303 f->close_section();
304 }
305
306 void RGWAccessKey::dump(Formatter *f, const string& user, bool swift) const
307 {
308 string u = user;
309 if (!subuser.empty()) {
310 u.append(":");
311 u.append(subuser);
312 }
313 encode_json("user", u, f);
314 if (!swift) {
315 encode_json("access_key", id, f);
316 }
317 encode_json("secret_key", key, f);
318 }
319
320 void RGWAccessKey::decode_json(JSONObj *obj) {
321 JSONDecoder::decode_json("access_key", id, obj, true);
322 JSONDecoder::decode_json("secret_key", key, obj, true);
323 if (!JSONDecoder::decode_json("subuser", subuser, obj)) {
324 string user;
325 JSONDecoder::decode_json("user", user, obj);
326 int pos = user.find(':');
327 if (pos >= 0) {
328 subuser = user.substr(pos + 1);
329 }
330 }
331 }
332
333 void RGWAccessKey::decode_json(JSONObj *obj, bool swift) {
334 if (!swift) {
335 decode_json(obj);
336 return;
337 }
338
339 if (!JSONDecoder::decode_json("subuser", subuser, obj)) {
340 JSONDecoder::decode_json("user", id, obj, true);
341 int pos = id.find(':');
342 if (pos >= 0) {
343 subuser = id.substr(pos + 1);
344 }
345 }
346 JSONDecoder::decode_json("secret_key", key, obj, true);
347 }
348
349 struct rgw_flags_desc {
350 uint32_t mask;
351 const char *str;
352 };
353
354 static struct rgw_flags_desc rgw_perms[] = {
355 { RGW_PERM_FULL_CONTROL, "full-control" },
356 { RGW_PERM_READ | RGW_PERM_WRITE, "read-write" },
357 { RGW_PERM_READ, "read" },
358 { RGW_PERM_WRITE, "write" },
359 { RGW_PERM_READ_ACP, "read-acp" },
360 { RGW_PERM_WRITE_ACP, "write-acp" },
361 { 0, NULL }
362 };
363
364 template <class T>
365 static void mask_to_str(T *mask_list, uint32_t mask, char *buf, int len)
366 {
367 const char *sep = "";
368 int pos = 0;
369 if (!mask) {
370 snprintf(buf, len, "<none>");
371 return;
372 }
373 while (mask) {
374 uint32_t orig_mask = mask;
375 for (int i = 0; mask_list[i].mask; i++) {
376 T *desc = &mask_list[i];
377 if ((mask & desc->mask) == desc->mask) {
378 pos += snprintf(buf + pos, len - pos, "%s%s", sep, desc->str);
379 if (pos == len)
380 return;
381 sep = ", ";
382 mask &= ~desc->mask;
383 if (!mask)
384 return;
385 }
386 }
387 if (mask == orig_mask) // no change
388 break;
389 }
390 }
391
392 static void perm_to_str(uint32_t mask, char *buf, int len)
393 {
394 return mask_to_str(rgw_perms, mask, buf, len);
395 }
396
397 static struct rgw_flags_desc op_type_flags[] = {
398 { RGW_OP_TYPE_READ, "read" },
399 { RGW_OP_TYPE_WRITE, "write" },
400 { RGW_OP_TYPE_DELETE, "delete" },
401 { 0, NULL }
402 };
403
404 extern void op_type_to_str(uint32_t mask, char *buf, int len)
405 {
406 return mask_to_str(op_type_flags, mask, buf, len);
407 }
408
409 void RGWSubUser::dump(Formatter *f) const
410 {
411 encode_json("id", name, f);
412 char buf[256];
413 perm_to_str(perm_mask, buf, sizeof(buf));
414 encode_json("permissions", (const char *)buf, f);
415 }
416
417 void RGWSubUser::dump(Formatter *f, const string& user) const
418 {
419 string s = user;
420 s.append(":");
421 s.append(name);
422 encode_json("id", s, f);
423 char buf[256];
424 perm_to_str(perm_mask, buf, sizeof(buf));
425 encode_json("permissions", (const char *)buf, f);
426 }
427
428 static uint32_t str_to_perm(const string& s)
429 {
430 if (s.compare("read") == 0)
431 return RGW_PERM_READ;
432 else if (s.compare("write") == 0)
433 return RGW_PERM_WRITE;
434 else if (s.compare("read-write") == 0)
435 return RGW_PERM_READ | RGW_PERM_WRITE;
436 else if (s.compare("full-control") == 0)
437 return RGW_PERM_FULL_CONTROL;
438 return 0;
439 }
440
441 void RGWSubUser::decode_json(JSONObj *obj)
442 {
443 string uid;
444 JSONDecoder::decode_json("id", uid, obj);
445 int pos = uid.find(':');
446 if (pos >= 0)
447 name = uid.substr(pos + 1);
448 string perm_str;
449 JSONDecoder::decode_json("permissions", perm_str, obj);
450 perm_mask = str_to_perm(perm_str);
451 }
452
453 static void user_info_dump_subuser(const char *name, const RGWSubUser& subuser, Formatter *f, void *parent)
454 {
455 RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
456 subuser.dump(f, info->user_id.to_str());
457 }
458
459 static void user_info_dump_key(const char *name, const RGWAccessKey& key, Formatter *f, void *parent)
460 {
461 RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
462 key.dump(f, info->user_id.to_str(), false);
463 }
464
465 static void user_info_dump_swift_key(const char *name, const RGWAccessKey& key, Formatter *f, void *parent)
466 {
467 RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
468 key.dump(f, info->user_id.to_str(), true);
469 }
470
471 void RGWUserInfo::dump(Formatter *f) const
472 {
473
474 encode_json("user_id", user_id.to_str(), f);
475 encode_json("display_name", display_name, f);
476 encode_json("email", user_email, f);
477 encode_json("suspended", (int)suspended, f);
478 encode_json("max_buckets", (int)max_buckets, f);
479
480 encode_json_map("subusers", NULL, "subuser", NULL, user_info_dump_subuser,(void *)this, subusers, f);
481 encode_json_map("keys", NULL, "key", NULL, user_info_dump_key,(void *)this, access_keys, f);
482 encode_json_map("swift_keys", NULL, "key", NULL, user_info_dump_swift_key,(void *)this, swift_keys, f);
483
484 encode_json("caps", caps, f);
485
486 char buf[256];
487 op_type_to_str(op_mask, buf, sizeof(buf));
488 encode_json("op_mask", (const char *)buf, f);
489
490 if (system) { /* no need to show it for every user */
491 encode_json("system", (bool)system, f);
492 }
493 if (admin) {
494 encode_json("admin", (bool)admin, f);
495 }
496 encode_json("default_placement", default_placement.name, f);
497 encode_json("default_storage_class", default_placement.storage_class, f);
498 encode_json("placement_tags", placement_tags, f);
499 encode_json("bucket_quota", bucket_quota, f);
500 encode_json("user_quota", user_quota, f);
501 encode_json("temp_url_keys", temp_url_keys, f);
502
503 string user_source_type;
504 switch ((RGWIdentityType)type) {
505 case TYPE_RGW:
506 user_source_type = "rgw";
507 break;
508 case TYPE_KEYSTONE:
509 user_source_type = "keystone";
510 break;
511 case TYPE_LDAP:
512 user_source_type = "ldap";
513 break;
514 case TYPE_NONE:
515 user_source_type = "none";
516 break;
517 default:
518 user_source_type = "none";
519 break;
520 }
521 encode_json("type", user_source_type, f);
522 encode_json("mfa_ids", mfa_ids, f);
523 }
524
525
526 static void decode_access_keys(map<string, RGWAccessKey>& m, JSONObj *o)
527 {
528 RGWAccessKey k;
529 k.decode_json(o);
530 m[k.id] = k;
531 }
532
533 static void decode_swift_keys(map<string, RGWAccessKey>& m, JSONObj *o)
534 {
535 RGWAccessKey k;
536 k.decode_json(o, true);
537 m[k.id] = k;
538 }
539
540 static void decode_subusers(map<string, RGWSubUser>& m, JSONObj *o)
541 {
542 RGWSubUser u;
543 u.decode_json(o);
544 m[u.name] = u;
545 }
546
547 void RGWUserInfo::decode_json(JSONObj *obj)
548 {
549 string uid;
550
551 JSONDecoder::decode_json("user_id", uid, obj, true);
552 user_id.from_str(uid);
553
554 JSONDecoder::decode_json("display_name", display_name, obj);
555 JSONDecoder::decode_json("email", user_email, obj);
556 bool susp = false;
557 JSONDecoder::decode_json("suspended", susp, obj);
558 suspended = (__u8)susp;
559 JSONDecoder::decode_json("max_buckets", max_buckets, obj);
560
561 JSONDecoder::decode_json("keys", access_keys, decode_access_keys, obj);
562 JSONDecoder::decode_json("swift_keys", swift_keys, decode_swift_keys, obj);
563 JSONDecoder::decode_json("subusers", subusers, decode_subusers, obj);
564
565 JSONDecoder::decode_json("caps", caps, obj);
566
567 string mask_str;
568 JSONDecoder::decode_json("op_mask", mask_str, obj);
569 rgw_parse_op_type_list(mask_str, &op_mask);
570
571 bool sys = false;
572 JSONDecoder::decode_json("system", sys, obj);
573 system = (__u8)sys;
574 bool ad = false;
575 JSONDecoder::decode_json("admin", ad, obj);
576 admin = (__u8)ad;
577 JSONDecoder::decode_json("default_placement", default_placement.name, obj);
578 JSONDecoder::decode_json("default_storage_class", default_placement.storage_class, obj);
579 JSONDecoder::decode_json("placement_tags", placement_tags, obj);
580 JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
581 JSONDecoder::decode_json("user_quota", user_quota, obj);
582 JSONDecoder::decode_json("temp_url_keys", temp_url_keys, obj);
583
584 string user_source_type;
585 JSONDecoder::decode_json("type", user_source_type, obj);
586 if (user_source_type == "rgw") {
587 type = TYPE_RGW;
588 } else if (user_source_type == "keystone") {
589 type = TYPE_KEYSTONE;
590 } else if (user_source_type == "ldap") {
591 type = TYPE_LDAP;
592 } else if (user_source_type == "none") {
593 type = TYPE_NONE;
594 }
595 JSONDecoder::decode_json("mfa_ids", mfa_ids, obj);
596 }
597
598 void RGWQuotaInfo::dump(Formatter *f) const
599 {
600 f->dump_bool("enabled", enabled);
601 f->dump_bool("check_on_raw", check_on_raw);
602
603 f->dump_int("max_size", max_size);
604 f->dump_int("max_size_kb", rgw_rounded_kb(max_size));
605 f->dump_int("max_objects", max_objects);
606 }
607
608 void RGWQuotaInfo::decode_json(JSONObj *obj)
609 {
610 if (false == JSONDecoder::decode_json("max_size", max_size, obj)) {
611 /* We're parsing an older version of the struct. */
612 int64_t max_size_kb = 0;
613
614 JSONDecoder::decode_json("max_size_kb", max_size_kb, obj);
615 max_size = max_size_kb * 1024;
616 }
617 JSONDecoder::decode_json("max_objects", max_objects, obj);
618
619 JSONDecoder::decode_json("check_on_raw", check_on_raw, obj);
620 JSONDecoder::decode_json("enabled", enabled, obj);
621 }
622
623 void rgw_data_placement_target::dump(Formatter *f) const
624 {
625 encode_json("data_pool", data_pool, f);
626 encode_json("data_extra_pool", data_extra_pool, f);
627 encode_json("index_pool", index_pool, f);
628 }
629
630 void rgw_data_placement_target::decode_json(JSONObj *obj) {
631 JSONDecoder::decode_json("data_pool", data_pool, obj);
632 JSONDecoder::decode_json("data_extra_pool", data_extra_pool, obj);
633 JSONDecoder::decode_json("index_pool", index_pool, obj);
634 }
635
636 void rgw_bucket::dump(Formatter *f) const
637 {
638 encode_json("name", name, f);
639 encode_json("marker", marker, f);
640 encode_json("bucket_id", bucket_id, f);
641 encode_json("tenant", tenant, f);
642 encode_json("explicit_placement", explicit_placement, f);
643 }
644
645 void rgw_bucket::decode_json(JSONObj *obj) {
646 JSONDecoder::decode_json("name", name, obj);
647 JSONDecoder::decode_json("marker", marker, obj);
648 JSONDecoder::decode_json("bucket_id", bucket_id, obj);
649 JSONDecoder::decode_json("tenant", tenant, obj);
650 JSONDecoder::decode_json("explicit_placement", explicit_placement, obj);
651 if (explicit_placement.data_pool.empty()) {
652 /* decoding old format */
653 JSONDecoder::decode_json("pool", explicit_placement.data_pool, obj);
654 JSONDecoder::decode_json("data_extra_pool", explicit_placement.data_extra_pool, obj);
655 JSONDecoder::decode_json("index_pool", explicit_placement.index_pool, obj);
656 }
657 }
658
659 void RGWBucketEntryPoint::dump(Formatter *f) const
660 {
661 encode_json("bucket", bucket, f);
662 encode_json("owner", owner, f);
663 utime_t ut(creation_time);
664 encode_json("creation_time", ut, f);
665 encode_json("linked", linked, f);
666 encode_json("has_bucket_info", has_bucket_info, f);
667 if (has_bucket_info) {
668 encode_json("old_bucket_info", old_bucket_info, f);
669 }
670 }
671
672 void RGWBucketEntryPoint::decode_json(JSONObj *obj) {
673 JSONDecoder::decode_json("bucket", bucket, obj);
674 JSONDecoder::decode_json("owner", owner, obj);
675 utime_t ut;
676 JSONDecoder::decode_json("creation_time", ut, obj);
677 creation_time = ut.to_real_time();
678 JSONDecoder::decode_json("linked", linked, obj);
679 JSONDecoder::decode_json("has_bucket_info", has_bucket_info, obj);
680 if (has_bucket_info) {
681 JSONDecoder::decode_json("old_bucket_info", old_bucket_info, obj);
682 }
683 }
684
685 void RGWStorageStats::dump(Formatter *f) const
686 {
687 encode_json("size", size, f);
688 encode_json("size_actual", size_rounded, f);
689 encode_json("size_utilized", size_utilized, f);
690 encode_json("size_kb", rgw_rounded_kb(size), f);
691 encode_json("size_kb_actual", rgw_rounded_kb(size_rounded), f);
692 encode_json("size_kb_utilized", rgw_rounded_kb(size_utilized), f);
693 encode_json("num_objects", num_objects, f);
694 }
695
696 void RGWRedirectInfo::dump(Formatter *f) const
697 {
698 encode_json("protocol", protocol, f);
699 encode_json("hostname", hostname, f);
700 encode_json("http_redirect_code", (int)http_redirect_code, f);
701 }
702
703 void RGWRedirectInfo::decode_json(JSONObj *obj) {
704 JSONDecoder::decode_json("protocol", protocol, obj);
705 JSONDecoder::decode_json("hostname", hostname, obj);
706 int code;
707 JSONDecoder::decode_json("http_redirect_code", code, obj);
708 http_redirect_code = code;
709 }
710
711 void RGWBWRedirectInfo::dump(Formatter *f) const
712 {
713 encode_json("redirect", redirect, f);
714 encode_json("replace_key_prefix_with", replace_key_prefix_with, f);
715 encode_json("replace_key_with", replace_key_with, f);
716 }
717
718 void RGWBWRedirectInfo::decode_json(JSONObj *obj) {
719 JSONDecoder::decode_json("redirect", redirect, obj);
720 JSONDecoder::decode_json("replace_key_prefix_with", replace_key_prefix_with, obj);
721 JSONDecoder::decode_json("replace_key_with", replace_key_with, obj);
722 }
723
724 void RGWBWRoutingRuleCondition::dump(Formatter *f) const
725 {
726 encode_json("key_prefix_equals", key_prefix_equals, f);
727 encode_json("http_error_code_returned_equals", (int)http_error_code_returned_equals, f);
728 }
729
730 void RGWBWRoutingRuleCondition::decode_json(JSONObj *obj) {
731 JSONDecoder::decode_json("key_prefix_equals", key_prefix_equals, obj);
732 int code;
733 JSONDecoder::decode_json("http_error_code_returned_equals", code, obj);
734 http_error_code_returned_equals = code;
735 }
736
737 void RGWBWRoutingRule::dump(Formatter *f) const
738 {
739 encode_json("condition", condition, f);
740 encode_json("redirect_info", redirect_info, f);
741 }
742
743 void RGWBWRoutingRule::decode_json(JSONObj *obj) {
744 JSONDecoder::decode_json("condition", condition, obj);
745 JSONDecoder::decode_json("redirect_info", redirect_info, obj);
746 }
747
748 void RGWBWRoutingRules::dump(Formatter *f) const
749 {
750 encode_json("rules", rules, f);
751 }
752
753 void RGWBWRoutingRules::decode_json(JSONObj *obj) {
754 JSONDecoder::decode_json("rules", rules, obj);
755 }
756
757 void RGWBucketWebsiteConf::dump(Formatter *f) const
758 {
759 if (!redirect_all.hostname.empty()) {
760 encode_json("redirect_all", redirect_all, f);
761 } else {
762 encode_json("index_doc_suffix", index_doc_suffix, f);
763 encode_json("error_doc", error_doc, f);
764 encode_json("routing_rules", routing_rules, f);
765 }
766 }
767
768 void RGWBucketWebsiteConf::decode_json(JSONObj *obj) {
769 JSONDecoder::decode_json("redirect_all", redirect_all, obj);
770 JSONDecoder::decode_json("index_doc_suffix", index_doc_suffix, obj);
771 JSONDecoder::decode_json("error_doc", error_doc, obj);
772 JSONDecoder::decode_json("routing_rules", routing_rules, obj);
773 }
774
775 void RGWBucketInfo::dump(Formatter *f) const
776 {
777 encode_json("bucket", bucket, f);
778 utime_t ut(creation_time);
779 encode_json("creation_time", ut, f);
780 encode_json("owner", owner.to_str(), f);
781 encode_json("flags", flags, f);
782 encode_json("zonegroup", zonegroup, f);
783 encode_json("placement_rule", placement_rule, f);
784 encode_json("has_instance_obj", has_instance_obj, f);
785 encode_json("quota", quota, f);
786 encode_json("num_shards", layout.current_index.layout.normal.num_shards, f);
787 encode_json("bi_shard_hash_type", (uint32_t)layout.current_index.layout.normal.hash_type, f);
788 encode_json("requester_pays", requester_pays, f);
789 encode_json("has_website", has_website, f);
790 if (has_website) {
791 encode_json("website_conf", website_conf, f);
792 }
793 encode_json("swift_versioning", swift_versioning, f);
794 encode_json("swift_ver_location", swift_ver_location, f);
795 encode_json("index_type", (uint32_t)layout.current_index.layout.type, f);
796 encode_json("mdsearch_config", mdsearch_config, f);
797 encode_json("reshard_status", (int)reshard_status, f);
798 encode_json("new_bucket_instance_id", new_bucket_instance_id, f);
799 if (!empty_sync_policy()) {
800 encode_json("sync_policy", *sync_policy, f);
801 }
802 }
803
804 void RGWBucketInfo::decode_json(JSONObj *obj) {
805 JSONDecoder::decode_json("bucket", bucket, obj);
806 utime_t ut;
807 JSONDecoder::decode_json("creation_time", ut, obj);
808 creation_time = ut.to_real_time();
809 JSONDecoder::decode_json("owner", owner, obj);
810 JSONDecoder::decode_json("flags", flags, obj);
811 JSONDecoder::decode_json("zonegroup", zonegroup, obj);
812 /* backward compatability with region */
813 if (zonegroup.empty()) {
814 JSONDecoder::decode_json("region", zonegroup, obj);
815 }
816 string pr;
817 JSONDecoder::decode_json("placement_rule", pr, obj);
818 placement_rule.from_str(pr);
819 JSONDecoder::decode_json("has_instance_obj", has_instance_obj, obj);
820 JSONDecoder::decode_json("quota", quota, obj);
821 JSONDecoder::decode_json("num_shards", layout.current_index.layout.normal.num_shards, obj);
822 uint32_t hash_type;
823 JSONDecoder::decode_json("bi_shard_hash_type", hash_type, obj);
824 layout.current_index.layout.normal.hash_type = static_cast<rgw::BucketHashType>(hash_type);
825 JSONDecoder::decode_json("requester_pays", requester_pays, obj);
826 JSONDecoder::decode_json("has_website", has_website, obj);
827 if (has_website) {
828 JSONDecoder::decode_json("website_conf", website_conf, obj);
829 }
830 JSONDecoder::decode_json("swift_versioning", swift_versioning, obj);
831 JSONDecoder::decode_json("swift_ver_location", swift_ver_location, obj);
832 uint32_t it;
833 JSONDecoder::decode_json("index_type", it, obj);
834 layout.current_index.layout.type = (rgw::BucketIndexType)it;
835 JSONDecoder::decode_json("mdsearch_config", mdsearch_config, obj);
836 int rs;
837 JSONDecoder::decode_json("reshard_status", rs, obj);
838 reshard_status = (cls_rgw_reshard_status)rs;
839
840 rgw_sync_policy_info sp;
841 JSONDecoder::decode_json("sync_policy", sp, obj);
842 if (!sp.empty()) {
843 set_sync_policy(std::move(sp));
844 }
845 }
846
847 void rgw_sync_directional_rule::dump(Formatter *f) const
848 {
849 encode_json("source_zone", source_zone, f);
850 encode_json("dest_zone", dest_zone, f);
851 }
852
853 void rgw_sync_directional_rule::decode_json(JSONObj *obj)
854 {
855 JSONDecoder::decode_json("source_zone", source_zone, obj);
856 JSONDecoder::decode_json("dest_zone", dest_zone, obj);
857 }
858
859 void rgw_sync_symmetric_group::dump(Formatter *f) const
860 {
861 encode_json("id", id, f);
862 encode_json("zones", zones, f);
863 }
864
865 void rgw_sync_symmetric_group::decode_json(JSONObj *obj)
866 {
867 JSONDecoder::decode_json("id", id, obj);
868 JSONDecoder::decode_json("zones", zones, obj);
869 }
870
871 void rgw_sync_bucket_entity::dump(Formatter *f) const
872 {
873 encode_json("zone", zone, f);
874 encode_json("bucket", bucket_key(), f);
875 }
876
877 void rgw_sync_bucket_entity::decode_json(JSONObj *obj)
878 {
879 JSONDecoder::decode_json("zone", zone, obj);
880 string s;
881 if (JSONDecoder::decode_json("bucket", s, obj)) {
882 rgw_bucket b;
883 int ret = rgw_bucket_parse_bucket_key(nullptr, s, &b, nullptr);
884 if (ret >= 0) {
885 bucket = b;
886 } else {
887 bucket.reset();
888 }
889 }
890 }
891
892 void rgw_sync_pipe_filter_tag::dump(Formatter *f) const
893 {
894 encode_json("key", key, f);
895 encode_json("value", value, f);
896 }
897
898 void rgw_sync_pipe_filter_tag::decode_json(JSONObj *obj)
899 {
900 JSONDecoder::decode_json("key", key, obj);
901 JSONDecoder::decode_json("value", value, obj);
902 }
903
904 void rgw_sync_pipe_filter::dump(Formatter *f) const
905 {
906 encode_json("prefix", prefix, f);
907 encode_json("tags", tags, f);
908 }
909
910 void rgw_sync_pipe_filter::decode_json(JSONObj *obj)
911 {
912 JSONDecoder::decode_json("prefix", prefix, obj);
913 JSONDecoder::decode_json("tags", tags, obj);
914 }
915
916 void rgw_sync_pipe_acl_translation::dump(Formatter *f) const
917 {
918 encode_json("owner", owner, f);
919 }
920
921 void rgw_sync_pipe_acl_translation::decode_json(JSONObj *obj)
922 {
923 JSONDecoder::decode_json("owner", owner, obj);
924 }
925
926 void rgw_sync_pipe_source_params::dump(Formatter *f) const
927 {
928 encode_json("filter", filter, f);
929 }
930
931 void rgw_sync_pipe_source_params::decode_json(JSONObj *obj)
932 {
933 JSONDecoder::decode_json("filter", filter, obj);
934 }
935
936 void rgw_sync_pipe_dest_params::dump(Formatter *f) const
937 {
938 encode_json("acl_translation", acl_translation, f);
939 encode_json("storage_class", storage_class, f);
940 }
941
942 void rgw_sync_pipe_dest_params::decode_json(JSONObj *obj)
943 {
944 JSONDecoder::decode_json("acl_translation", acl_translation, obj);
945 JSONDecoder::decode_json("storage_class", storage_class, obj);
946 }
947
948 void rgw_sync_pipe_params::dump(Formatter *f) const
949 {
950 encode_json("source", source, f);
951 encode_json("dest", dest, f);
952 encode_json("priority", priority, f);
953 string s;
954 switch (mode) {
955 case MODE_SYSTEM:
956 s = "system";
957 break;
958 default:
959 s = "user";
960 }
961 encode_json("mode", s, f);
962 encode_json("user", user, f);
963 }
964
965 void rgw_sync_pipe_params::decode_json(JSONObj *obj)
966 {
967 JSONDecoder::decode_json("source", source, obj);
968 JSONDecoder::decode_json("dest", dest, obj);
969 JSONDecoder::decode_json("priority", priority, obj);
970 string s;
971 JSONDecoder::decode_json("mode", s, obj);
972 if (s == "system") {
973 mode = MODE_SYSTEM;
974 } else {
975 mode = MODE_USER;
976 }
977 JSONDecoder::decode_json("user", user, obj);
978 }
979
980
981 void rgw_sync_bucket_entities::dump(Formatter *f) const
982 {
983 encode_json("bucket", rgw_sync_bucket_entities::bucket_key(bucket), f);
984 if (zones) {
985 encode_json("zones", zones, f);
986 } else if (all_zones) {
987 set<string> z = { "*" };
988 encode_json("zones", z, f);
989 }
990 }
991
992 void rgw_sync_bucket_entities::decode_json(JSONObj *obj)
993 {
994 string s;
995 JSONDecoder::decode_json("bucket", s, obj);
996 if (s == "*") {
997 bucket.reset();
998 } else {
999 rgw_bucket b;
1000 int ret = rgw_bucket_parse_bucket_key(nullptr, s, &b, nullptr);
1001 if (ret < 0) {
1002 bucket.reset();
1003 } else {
1004 if (b.tenant == "*") {
1005 b.tenant.clear();
1006 }
1007 if (b.name == "*") {
1008 b.name.clear();
1009 }
1010 if (b.bucket_id == "*") {
1011 b.bucket_id.clear();
1012 }
1013 bucket = b;
1014 }
1015 }
1016 JSONDecoder::decode_json("zones", zones, obj);
1017 if (zones && zones->size() == 1) {
1018 auto iter = zones->begin();
1019 if (*iter == "*") {
1020 zones.reset();
1021 all_zones = true;
1022 }
1023 }
1024 }
1025
1026 void rgw_sync_bucket_pipe::dump(Formatter *f) const
1027 {
1028 encode_json("id", id, f);
1029 encode_json("source", source, f);
1030 encode_json("dest", dest, f);
1031 encode_json("params", params, f);
1032 }
1033
1034 void rgw_sync_bucket_pipe::decode_json(JSONObj *obj)
1035 {
1036 JSONDecoder::decode_json("id", id, obj);
1037 JSONDecoder::decode_json("source", source, obj);
1038 JSONDecoder::decode_json("dest", dest, obj);
1039 JSONDecoder::decode_json("params", params, obj);
1040 }
1041
1042 void rgw_sync_bucket_pipes::dump(Formatter *f) const
1043 {
1044 encode_json("id", id, f);
1045 encode_json("source", source, f);
1046 encode_json("dest", dest, f);
1047 encode_json("params", params, f);
1048 }
1049
1050 void rgw_sync_bucket_pipes::decode_json(JSONObj *obj)
1051 {
1052 JSONDecoder::decode_json("id", id, obj);
1053 JSONDecoder::decode_json("source", source, obj);
1054 JSONDecoder::decode_json("dest", dest, obj);
1055 JSONDecoder::decode_json("params", params, obj);
1056 }
1057
1058 void rgw_sync_data_flow_group::dump(Formatter *f) const
1059 {
1060 if (!symmetrical.empty()) {
1061 encode_json("symmetrical", symmetrical, f);
1062 }
1063
1064 if (!directional.empty()) {
1065 encode_json("directional", directional, f);
1066 }
1067 }
1068
1069 void rgw_sync_data_flow_group::decode_json(JSONObj *obj)
1070 {
1071 JSONDecoder::decode_json("symmetrical", symmetrical, obj);
1072 JSONDecoder::decode_json("directional", directional, obj);
1073 }
1074
1075 void rgw_sync_policy_group::dump(Formatter *f) const
1076 {
1077 encode_json("id", id, f);
1078 encode_json("data_flow", data_flow, f);
1079 encode_json("pipes", pipes, f);
1080 string s;
1081 switch (status) {
1082 case rgw_sync_policy_group::Status::FORBIDDEN:
1083 s = "forbidden";
1084 break;
1085 case rgw_sync_policy_group::Status::ALLOWED:
1086 s = "allowed";
1087 break;
1088 case rgw_sync_policy_group::Status::ENABLED:
1089 s = "enabled";
1090 break;
1091 default:
1092 s = "unknown";
1093 }
1094 encode_json("status", s, f);
1095 }
1096
1097 void rgw_sync_policy_group::decode_json(JSONObj *obj)
1098 {
1099 JSONDecoder::decode_json("id", id, obj);
1100 JSONDecoder::decode_json("data_flow", data_flow, obj);
1101 JSONDecoder::decode_json("pipes", pipes, obj);
1102 string s;
1103 JSONDecoder::decode_json("status", s, obj);
1104 set_status(s);
1105 }
1106
1107 void rgw_sync_policy_info::dump(Formatter *f) const
1108 {
1109 Formatter::ArraySection section(*f, "groups");
1110 for (auto& group : groups ) {
1111 encode_json("group", group.second, f);
1112 }
1113 }
1114
1115 void rgw_sync_policy_info::decode_json(JSONObj *obj)
1116 {
1117 vector<rgw_sync_policy_group> groups_vec;
1118
1119 JSONDecoder::decode_json("groups", groups_vec, obj);
1120
1121 for (auto& group : groups_vec) {
1122 groups.emplace(std::make_pair(group.id, std::move(group)));
1123 }
1124 }
1125
1126 void rgw_obj_key::dump(Formatter *f) const
1127 {
1128 encode_json("name", name, f);
1129 encode_json("instance", instance, f);
1130 encode_json("ns", ns, f);
1131 }
1132
1133 void rgw_obj_key::decode_json(JSONObj *obj)
1134 {
1135 JSONDecoder::decode_json("name", name, obj);
1136 JSONDecoder::decode_json("instance", instance, obj);
1137 JSONDecoder::decode_json("ns", ns, obj);
1138 }
1139
1140 void RGWBucketEnt::dump(Formatter *f) const
1141 {
1142 encode_json("bucket", bucket, f);
1143 encode_json("size", size, f);
1144 encode_json("size_rounded", size_rounded, f);
1145 utime_t ut(creation_time);
1146 encode_json("mtime", ut, f); /* mtime / creation time discrepency needed for backward compatibility */
1147 encode_json("count", count, f);
1148 encode_json("placement_rule", placement_rule.to_str(), f);
1149 }
1150
1151 void RGWUploadPartInfo::dump(Formatter *f) const
1152 {
1153 encode_json("num", num, f);
1154 encode_json("size", size, f);
1155 encode_json("etag", etag, f);
1156 utime_t ut(modified);
1157 encode_json("modified", ut, f);
1158 }
1159
1160 void rgw_raw_obj::dump(Formatter *f) const
1161 {
1162 encode_json("pool", pool, f);
1163 encode_json("oid", oid, f);
1164 encode_json("loc", loc, f);
1165 }
1166
1167 void rgw_raw_obj::decode_json(JSONObj *obj) {
1168 JSONDecoder::decode_json("pool", pool, obj);
1169 JSONDecoder::decode_json("oid", oid, obj);
1170 JSONDecoder::decode_json("loc", loc, obj);
1171 }
1172
1173 void rgw_obj::dump(Formatter *f) const
1174 {
1175 encode_json("bucket", bucket, f);
1176 encode_json("key", key, f);
1177 }
1178
1179 void RGWDefaultSystemMetaObjInfo::dump(Formatter *f) const {
1180 encode_json("default_id", default_id, f);
1181 }
1182
1183 void RGWDefaultSystemMetaObjInfo::decode_json(JSONObj *obj) {
1184 JSONDecoder::decode_json("default_id", default_id, obj);
1185 }
1186
1187 void RGWNameToId::dump(Formatter *f) const {
1188 encode_json("obj_id", obj_id, f);
1189 }
1190
1191 void RGWNameToId::decode_json(JSONObj *obj) {
1192 JSONDecoder::decode_json("obj_id", obj_id, obj);
1193 }
1194
1195 void RGWSystemMetaObj::dump(Formatter *f) const
1196 {
1197 encode_json("id", id , f);
1198 encode_json("name", name , f);
1199 }
1200
1201 void RGWSystemMetaObj::decode_json(JSONObj *obj)
1202 {
1203 JSONDecoder::decode_json("id", id, obj);
1204 JSONDecoder::decode_json("name", name, obj);
1205 }
1206
1207 void RGWPeriodLatestEpochInfo::dump(Formatter *f) const {
1208 encode_json("latest_epoch", epoch, f);
1209 }
1210
1211 void RGWPeriodLatestEpochInfo::decode_json(JSONObj *obj) {
1212 JSONDecoder::decode_json("latest_epoch", epoch, obj);
1213 }
1214
1215 void RGWPeriod::dump(Formatter *f) const
1216 {
1217 encode_json("id", id, f);
1218 encode_json("epoch", epoch , f);
1219 encode_json("predecessor_uuid", predecessor_uuid, f);
1220 encode_json("sync_status", sync_status, f);
1221 encode_json("period_map", period_map, f);
1222 encode_json("master_zonegroup", master_zonegroup, f);
1223 encode_json("master_zone", master_zone, f);
1224 encode_json("period_config", period_config, f);
1225 encode_json("realm_id", realm_id, f);
1226 encode_json("realm_name", realm_name, f);
1227 encode_json("realm_epoch", realm_epoch, f);
1228 }
1229
1230 void RGWPeriod::decode_json(JSONObj *obj)
1231 {
1232 JSONDecoder::decode_json("id", id, obj);
1233 JSONDecoder::decode_json("epoch", epoch, obj);
1234 JSONDecoder::decode_json("predecessor_uuid", predecessor_uuid, obj);
1235 JSONDecoder::decode_json("sync_status", sync_status, obj);
1236 JSONDecoder::decode_json("period_map", period_map, obj);
1237 JSONDecoder::decode_json("master_zonegroup", master_zonegroup, obj);
1238 JSONDecoder::decode_json("master_zone", master_zone, obj);
1239 JSONDecoder::decode_json("period_config", period_config, obj);
1240 JSONDecoder::decode_json("realm_id", realm_id, obj);
1241 JSONDecoder::decode_json("realm_name", realm_name, obj);
1242 JSONDecoder::decode_json("realm_epoch", realm_epoch, obj);
1243 }
1244
1245 void RGWZoneParams::dump(Formatter *f) const
1246 {
1247 RGWSystemMetaObj::dump(f);
1248 encode_json("domain_root", domain_root, f);
1249 encode_json("control_pool", control_pool, f);
1250 encode_json("gc_pool", gc_pool, f);
1251 encode_json("lc_pool", lc_pool, f);
1252 encode_json("log_pool", log_pool, f);
1253 encode_json("intent_log_pool", intent_log_pool, f);
1254 encode_json("usage_log_pool", usage_log_pool, f);
1255 encode_json("roles_pool", roles_pool, f);
1256 encode_json("reshard_pool", reshard_pool, f);
1257 encode_json("user_keys_pool", user_keys_pool, f);
1258 encode_json("user_email_pool", user_email_pool, f);
1259 encode_json("user_swift_pool", user_swift_pool, f);
1260 encode_json("user_uid_pool", user_uid_pool, f);
1261 encode_json("otp_pool", otp_pool, f);
1262 encode_json_plain("system_key", system_key, f);
1263 encode_json("placement_pools", placement_pools, f);
1264 encode_json("tier_config", tier_config, f);
1265 encode_json("realm_id", realm_id, f);
1266 encode_json("notif_pool", notif_pool, f);
1267 }
1268
1269 void RGWZoneStorageClass::dump(Formatter *f) const
1270 {
1271 if (data_pool) {
1272 encode_json("data_pool", data_pool.get(), f);
1273 }
1274 if (compression_type) {
1275 encode_json("compression_type", compression_type.get(), f);
1276 }
1277 }
1278
1279 void RGWZoneStorageClass::decode_json(JSONObj *obj)
1280 {
1281 JSONDecoder::decode_json("data_pool", data_pool, obj);
1282 JSONDecoder::decode_json("compression_type", compression_type, obj);
1283 }
1284
1285 void RGWZoneStorageClasses::dump(Formatter *f) const
1286 {
1287 for (auto& i : m) {
1288 encode_json(i.first.c_str(), i.second, f);
1289 }
1290 }
1291
1292 void RGWZoneStorageClasses::decode_json(JSONObj *obj)
1293 {
1294 JSONFormattable f;
1295 decode_json_obj(f, obj);
1296
1297 for (auto& field : f.object()) {
1298 JSONObj *field_obj = obj->find_obj(field.first);
1299 assert(field_obj);
1300
1301 decode_json_obj(m[field.first], field_obj);
1302 }
1303 standard_class = &m[RGW_STORAGE_CLASS_STANDARD];
1304 }
1305
1306 void RGWZonePlacementInfo::dump(Formatter *f) const
1307 {
1308 encode_json("index_pool", index_pool, f);
1309 encode_json("storage_classes", storage_classes, f);
1310 encode_json("data_extra_pool", data_extra_pool, f);
1311 encode_json("index_type", (uint32_t)index_type, f);
1312
1313 /* no real need for backward compatibility of compression_type and data_pool in here,
1314 * rather not clutter the output */
1315 }
1316
1317 void RGWZonePlacementInfo::decode_json(JSONObj *obj)
1318 {
1319 JSONDecoder::decode_json("index_pool", index_pool, obj);
1320 JSONDecoder::decode_json("storage_classes", storage_classes, obj);
1321 JSONDecoder::decode_json("data_extra_pool", data_extra_pool, obj);
1322 uint32_t it;
1323 JSONDecoder::decode_json("index_type", it, obj);
1324 index_type = (rgw::BucketIndexType)it;
1325
1326 /* backward compatibility, these are now defined in storage_classes */
1327 string standard_compression_type;
1328 string *pcompression = nullptr;
1329 if (JSONDecoder::decode_json("compression", standard_compression_type, obj)) {
1330 pcompression = &standard_compression_type;
1331 }
1332 rgw_pool standard_data_pool;
1333 rgw_pool *ppool = nullptr;
1334 if (JSONDecoder::decode_json("data_pool", standard_data_pool, obj)) {
1335 ppool = &standard_data_pool;
1336 }
1337 if (ppool || pcompression) {
1338 storage_classes.set_storage_class(RGW_STORAGE_CLASS_STANDARD, ppool, pcompression);
1339 }
1340 }
1341
1342 void RGWZoneParams::decode_json(JSONObj *obj)
1343 {
1344 RGWSystemMetaObj::decode_json(obj);
1345 JSONDecoder::decode_json("domain_root", domain_root, obj);
1346 JSONDecoder::decode_json("control_pool", control_pool, obj);
1347 JSONDecoder::decode_json("gc_pool", gc_pool, obj);
1348 JSONDecoder::decode_json("lc_pool", lc_pool, obj);
1349 JSONDecoder::decode_json("log_pool", log_pool, obj);
1350 JSONDecoder::decode_json("intent_log_pool", intent_log_pool, obj);
1351 JSONDecoder::decode_json("roles_pool", roles_pool, obj);
1352 JSONDecoder::decode_json("reshard_pool", reshard_pool, obj);
1353 JSONDecoder::decode_json("usage_log_pool", usage_log_pool, obj);
1354 JSONDecoder::decode_json("user_keys_pool", user_keys_pool, obj);
1355 JSONDecoder::decode_json("user_email_pool", user_email_pool, obj);
1356 JSONDecoder::decode_json("user_swift_pool", user_swift_pool, obj);
1357 JSONDecoder::decode_json("user_uid_pool", user_uid_pool, obj);
1358 JSONDecoder::decode_json("otp_pool", otp_pool, obj);
1359 JSONDecoder::decode_json("system_key", system_key, obj);
1360 JSONDecoder::decode_json("placement_pools", placement_pools, obj);
1361 JSONDecoder::decode_json("tier_config", tier_config, obj);
1362 JSONDecoder::decode_json("realm_id", realm_id, obj);
1363 JSONDecoder::decode_json("notif_pool", notif_pool, obj);
1364
1365 }
1366
1367 void RGWZone::dump(Formatter *f) const
1368 {
1369 encode_json("id", id, f);
1370 encode_json("name", name, f);
1371 encode_json("endpoints", endpoints, f);
1372 encode_json("log_meta", log_meta, f);
1373 encode_json("log_data", log_data, f);
1374 encode_json("bucket_index_max_shards", bucket_index_max_shards, f);
1375 encode_json("read_only", read_only, f);
1376 encode_json("tier_type", tier_type, f);
1377 encode_json("sync_from_all", sync_from_all, f);
1378 encode_json("sync_from", sync_from, f);
1379 encode_json("redirect_zone", redirect_zone, f);
1380 }
1381
1382 void RGWZone::decode_json(JSONObj *obj)
1383 {
1384 JSONDecoder::decode_json("id", id, obj);
1385 JSONDecoder::decode_json("name", name, obj);
1386 if (id.empty()) {
1387 id = name;
1388 }
1389 JSONDecoder::decode_json("endpoints", endpoints, obj);
1390 JSONDecoder::decode_json("log_meta", log_meta, obj);
1391 JSONDecoder::decode_json("log_data", log_data, obj);
1392 JSONDecoder::decode_json("bucket_index_max_shards", bucket_index_max_shards, obj);
1393 JSONDecoder::decode_json("read_only", read_only, obj);
1394 JSONDecoder::decode_json("tier_type", tier_type, obj);
1395 JSONDecoder::decode_json("sync_from_all", sync_from_all, true, obj);
1396 JSONDecoder::decode_json("sync_from", sync_from, obj);
1397 JSONDecoder::decode_json("redirect_zone", redirect_zone, obj);
1398 }
1399
1400 void RGWZoneGroupPlacementTarget::dump(Formatter *f) const
1401 {
1402 encode_json("name", name, f);
1403 encode_json("tags", tags, f);
1404 encode_json("storage_classes", storage_classes, f);
1405 }
1406
1407 void RGWZoneGroupPlacementTarget::decode_json(JSONObj *obj)
1408 {
1409 JSONDecoder::decode_json("name", name, obj);
1410 JSONDecoder::decode_json("tags", tags, obj);
1411 JSONDecoder::decode_json("storage_classes", storage_classes, obj);
1412 if (storage_classes.empty()) {
1413 storage_classes.insert(RGW_STORAGE_CLASS_STANDARD);
1414 }
1415 }
1416
1417 void RGWZoneGroup::dump(Formatter *f) const
1418 {
1419 RGWSystemMetaObj::dump(f);
1420 encode_json("api_name", api_name, f);
1421 encode_json("is_master", is_master, f);
1422 encode_json("endpoints", endpoints, f);
1423 encode_json("hostnames", hostnames, f);
1424 encode_json("hostnames_s3website", hostnames_s3website, f);
1425 encode_json("master_zone", master_zone, f);
1426 encode_json_map("zones", zones, f); /* more friendly representation */
1427 encode_json_map("placement_targets", placement_targets, f); /* more friendly representation */
1428 encode_json("default_placement", default_placement, f);
1429 encode_json("realm_id", realm_id, f);
1430 encode_json("sync_policy", sync_policy, f);
1431 }
1432
1433 static void decode_zones(map<rgw_zone_id, RGWZone>& zones, JSONObj *o)
1434 {
1435 RGWZone z;
1436 z.decode_json(o);
1437 zones[z.id] = z;
1438 }
1439
1440 static void decode_placement_targets(map<string, RGWZoneGroupPlacementTarget>& targets, JSONObj *o)
1441 {
1442 RGWZoneGroupPlacementTarget t;
1443 t.decode_json(o);
1444 targets[t.name] = t;
1445 }
1446
1447
1448 void RGWZoneGroup::decode_json(JSONObj *obj)
1449 {
1450 RGWSystemMetaObj::decode_json(obj);
1451 if (id.empty()) {
1452 derr << "old format " << dendl;
1453 JSONDecoder::decode_json("name", name, obj);
1454 id = name;
1455 }
1456 JSONDecoder::decode_json("api_name", api_name, obj);
1457 JSONDecoder::decode_json("is_master", is_master, obj);
1458 JSONDecoder::decode_json("endpoints", endpoints, obj);
1459 JSONDecoder::decode_json("hostnames", hostnames, obj);
1460 JSONDecoder::decode_json("hostnames_s3website", hostnames_s3website, obj);
1461 JSONDecoder::decode_json("master_zone", master_zone, obj);
1462 JSONDecoder::decode_json("zones", zones, decode_zones, obj);
1463 JSONDecoder::decode_json("placement_targets", placement_targets, decode_placement_targets, obj);
1464 JSONDecoder::decode_json("default_placement", default_placement.name, obj);
1465 JSONDecoder::decode_json("default_storage_class", default_placement.storage_class, obj);
1466 JSONDecoder::decode_json("realm_id", realm_id, obj);
1467 JSONDecoder::decode_json("sync_policy", sync_policy, obj);
1468 }
1469
1470
1471 void RGWPeriodMap::dump(Formatter *f) const
1472 {
1473 encode_json("id", id, f);
1474 encode_json_map("zonegroups", zonegroups, f);
1475 encode_json("short_zone_ids", short_zone_ids, f);
1476 }
1477
1478 static void decode_zonegroups(map<string, RGWZoneGroup>& zonegroups, JSONObj *o)
1479 {
1480 RGWZoneGroup zg;
1481 zg.decode_json(o);
1482 zonegroups[zg.get_id()] = zg;
1483 }
1484
1485 void RGWPeriodMap::decode_json(JSONObj *obj)
1486 {
1487 JSONDecoder::decode_json("id", id, obj);
1488 JSONDecoder::decode_json("zonegroups", zonegroups, decode_zonegroups, obj);
1489 /* backward compatability with region */
1490 if (zonegroups.empty()) {
1491 JSONDecoder::decode_json("regions", zonegroups, obj);
1492 }
1493 /* backward compatability with region */
1494 if (master_zonegroup.empty()) {
1495 JSONDecoder::decode_json("master_region", master_zonegroup, obj);
1496 }
1497 JSONDecoder::decode_json("short_zone_ids", short_zone_ids, obj);
1498 }
1499
1500
1501 void RGWPeriodConfig::dump(Formatter *f) const
1502 {
1503 encode_json("bucket_quota", bucket_quota, f);
1504 encode_json("user_quota", user_quota, f);
1505 }
1506
1507 void RGWPeriodConfig::decode_json(JSONObj *obj)
1508 {
1509 JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
1510 JSONDecoder::decode_json("user_quota", user_quota, obj);
1511 }
1512
1513 void RGWRegionMap::dump(Formatter *f) const
1514 {
1515 encode_json("regions", regions, f);
1516 encode_json("master_region", master_region, f);
1517 encode_json("bucket_quota", bucket_quota, f);
1518 encode_json("user_quota", user_quota, f);
1519 }
1520
1521 void RGWRegionMap::decode_json(JSONObj *obj)
1522 {
1523 JSONDecoder::decode_json("regions", regions, obj);
1524 JSONDecoder::decode_json("master_region", master_region, obj);
1525 JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
1526 JSONDecoder::decode_json("user_quota", user_quota, obj);
1527 }
1528
1529 void RGWZoneGroupMap::dump(Formatter *f) const
1530 {
1531 encode_json("zonegroups", zonegroups, f);
1532 encode_json("master_zonegroup", master_zonegroup, f);
1533 encode_json("bucket_quota", bucket_quota, f);
1534 encode_json("user_quota", user_quota, f);
1535 }
1536
1537 void RGWZoneGroupMap::decode_json(JSONObj *obj)
1538 {
1539 JSONDecoder::decode_json("zonegroups", zonegroups, obj);
1540 /* backward compatability with region */
1541 if (zonegroups.empty()) {
1542 JSONDecoder::decode_json("regions", zonegroups, obj);
1543 }
1544 JSONDecoder::decode_json("master_zonegroup", master_zonegroup, obj);
1545 /* backward compatability with region */
1546 if (master_zonegroup.empty()) {
1547 JSONDecoder::decode_json("master_region", master_zonegroup, obj);
1548 }
1549
1550 JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
1551 JSONDecoder::decode_json("user_quota", user_quota, obj);
1552 }
1553
1554 void RGWMetadataLogInfo::dump(Formatter *f) const
1555 {
1556 encode_json("marker", marker, f);
1557 utime_t ut(last_update);
1558 encode_json("last_update", ut, f);
1559 }
1560
1561 void RGWMetadataLogInfo::decode_json(JSONObj *obj)
1562 {
1563 JSONDecoder::decode_json("marker", marker, obj);
1564 utime_t ut;
1565 JSONDecoder::decode_json("last_update", ut, obj);
1566 last_update = ut.to_real_time();
1567 }
1568
1569 void RGWDataChangesLogInfo::dump(Formatter *f) const
1570 {
1571 encode_json("marker", marker, f);
1572 utime_t ut(last_update);
1573 encode_json("last_update", ut, f);
1574 }
1575
1576 void RGWDataChangesLogInfo::decode_json(JSONObj *obj)
1577 {
1578 JSONDecoder::decode_json("marker", marker, obj);
1579 utime_t ut;
1580 JSONDecoder::decode_json("last_update", ut, obj);
1581 last_update = ut.to_real_time();
1582 }
1583
1584
1585 void RGWRealm::dump(Formatter *f) const
1586 {
1587 RGWSystemMetaObj::dump(f);
1588 encode_json("current_period", current_period, f);
1589 encode_json("epoch", epoch, f);
1590 }
1591
1592
1593 void RGWRealm::decode_json(JSONObj *obj)
1594 {
1595 RGWSystemMetaObj::decode_json(obj);
1596 JSONDecoder::decode_json("current_period", current_period, obj);
1597 JSONDecoder::decode_json("epoch", epoch, obj);
1598 }
1599
1600 void rgw::keystone::TokenEnvelope::Token::decode_json(JSONObj *obj)
1601 {
1602 string expires_iso8601;
1603 struct tm t;
1604
1605 JSONDecoder::decode_json("id", id, obj, true);
1606 JSONDecoder::decode_json("tenant", tenant_v2, obj, true);
1607 JSONDecoder::decode_json("expires", expires_iso8601, obj, true);
1608
1609 if (parse_iso8601(expires_iso8601.c_str(), &t)) {
1610 expires = internal_timegm(&t);
1611 } else {
1612 expires = 0;
1613 throw JSONDecoder::err("Failed to parse ISO8601 expiration date from Keystone response.");
1614 }
1615 }
1616
1617 void rgw::keystone::TokenEnvelope::Role::decode_json(JSONObj *obj)
1618 {
1619 JSONDecoder::decode_json("id", id, obj);
1620 JSONDecoder::decode_json("name", name, obj, true);
1621 }
1622
1623 void rgw::keystone::TokenEnvelope::Domain::decode_json(JSONObj *obj)
1624 {
1625 JSONDecoder::decode_json("id", id, obj, true);
1626 JSONDecoder::decode_json("name", name, obj, true);
1627 }
1628
1629 void rgw::keystone::TokenEnvelope::Project::decode_json(JSONObj *obj)
1630 {
1631 JSONDecoder::decode_json("id", id, obj, true);
1632 JSONDecoder::decode_json("name", name, obj, true);
1633 JSONDecoder::decode_json("domain", domain, obj);
1634 }
1635
1636 void rgw::keystone::TokenEnvelope::User::decode_json(JSONObj *obj)
1637 {
1638 JSONDecoder::decode_json("id", id, obj, true);
1639 JSONDecoder::decode_json("name", name, obj, true);
1640 JSONDecoder::decode_json("domain", domain, obj);
1641 JSONDecoder::decode_json("roles", roles_v2, obj);
1642 }
1643
1644 void rgw::keystone::TokenEnvelope::decode_v3(JSONObj* const root_obj)
1645 {
1646 std::string expires_iso8601;
1647
1648 JSONDecoder::decode_json("user", user, root_obj, true);
1649 JSONDecoder::decode_json("expires_at", expires_iso8601, root_obj, true);
1650 JSONDecoder::decode_json("roles", roles, root_obj, true);
1651 JSONDecoder::decode_json("project", project, root_obj, true);
1652
1653 struct tm t;
1654 if (parse_iso8601(expires_iso8601.c_str(), &t)) {
1655 token.expires = internal_timegm(&t);
1656 } else {
1657 token.expires = 0;
1658 throw JSONDecoder::err("Failed to parse ISO8601 expiration date"
1659 "from Keystone response.");
1660 }
1661 }
1662
1663 void rgw::keystone::TokenEnvelope::decode_v2(JSONObj* const root_obj)
1664 {
1665 JSONDecoder::decode_json("user", user, root_obj, true);
1666 JSONDecoder::decode_json("token", token, root_obj, true);
1667
1668 roles = user.roles_v2;
1669 project = token.tenant_v2;
1670 }
1671
1672 void rgw_slo_entry::decode_json(JSONObj *obj)
1673 {
1674 JSONDecoder::decode_json("path", path, obj);
1675 JSONDecoder::decode_json("etag", etag, obj);
1676 JSONDecoder::decode_json("size_bytes", size_bytes, obj);
1677 };
1678
1679 void rgw_meta_sync_info::decode_json(JSONObj *obj)
1680 {
1681 string s;
1682 JSONDecoder::decode_json("status", s, obj);
1683 if (s == "init") {
1684 state = StateInit;
1685 } else if (s == "building-full-sync-maps") {
1686 state = StateBuildingFullSyncMaps;
1687 } else if (s == "sync") {
1688 state = StateSync;
1689 }
1690 JSONDecoder::decode_json("num_shards", num_shards, obj);
1691 JSONDecoder::decode_json("period", period, obj);
1692 JSONDecoder::decode_json("realm_epoch", realm_epoch, obj);
1693 }
1694
1695 void rgw_meta_sync_info::dump(Formatter *f) const
1696 {
1697 string s;
1698 switch ((SyncState)state) {
1699 case StateInit:
1700 s = "init";
1701 break;
1702 case StateBuildingFullSyncMaps:
1703 s = "building-full-sync-maps";
1704 break;
1705 case StateSync:
1706 s = "sync";
1707 break;
1708 default:
1709 s = "unknown";
1710 break;
1711 }
1712 encode_json("status", s, f);
1713 encode_json("num_shards", num_shards, f);
1714 encode_json("period", period, f);
1715 encode_json("realm_epoch", realm_epoch, f);
1716 }
1717
1718 void rgw_meta_sync_marker::decode_json(JSONObj *obj)
1719 {
1720 int s;
1721 JSONDecoder::decode_json("state", s, obj);
1722 state = s;
1723 JSONDecoder::decode_json("marker", marker, obj);
1724 JSONDecoder::decode_json("next_step_marker", next_step_marker, obj);
1725 JSONDecoder::decode_json("total_entries", total_entries, obj);
1726 JSONDecoder::decode_json("pos", pos, obj);
1727 utime_t ut;
1728 JSONDecoder::decode_json("timestamp", ut, obj);
1729 timestamp = ut.to_real_time();
1730 JSONDecoder::decode_json("realm_epoch", realm_epoch, obj);
1731 }
1732
1733 void rgw_meta_sync_marker::dump(Formatter *f) const
1734 {
1735 encode_json("state", (int)state, f);
1736 encode_json("marker", marker, f);
1737 encode_json("next_step_marker", next_step_marker, f);
1738 encode_json("total_entries", total_entries, f);
1739 encode_json("pos", pos, f);
1740 encode_json("timestamp", utime_t(timestamp), f);
1741 encode_json("realm_epoch", realm_epoch, f);
1742 }
1743
1744 void rgw_meta_sync_status::decode_json(JSONObj *obj)
1745 {
1746 JSONDecoder::decode_json("info", sync_info, obj);
1747 JSONDecoder::decode_json("markers", sync_markers, obj);
1748 }
1749
1750 void rgw_meta_sync_status::dump(Formatter *f) const {
1751 encode_json("info", sync_info, f);
1752 encode_json("markers", sync_markers, f);
1753 }
1754
1755 void rgw_sync_error_info::dump(Formatter *f) const {
1756 encode_json("source_zone", source_zone, f);
1757 encode_json("error_code", error_code, f);
1758 encode_json("message", message, f);
1759 }
1760
1761 void rgw_bucket_shard_full_sync_marker::decode_json(JSONObj *obj)
1762 {
1763 JSONDecoder::decode_json("position", position, obj);
1764 JSONDecoder::decode_json("count", count, obj);
1765 }
1766
1767 void rgw_bucket_shard_full_sync_marker::dump(Formatter *f) const
1768 {
1769 encode_json("position", position, f);
1770 encode_json("count", count, f);
1771 }
1772
1773 void rgw_bucket_shard_inc_sync_marker::decode_json(JSONObj *obj)
1774 {
1775 JSONDecoder::decode_json("position", position, obj);
1776 JSONDecoder::decode_json("timestamp", timestamp, obj);
1777 }
1778
1779 void rgw_bucket_shard_inc_sync_marker::dump(Formatter *f) const
1780 {
1781 encode_json("position", position, f);
1782 encode_json("timestamp", timestamp, f);
1783 }
1784
1785 void rgw_bucket_shard_sync_info::decode_json(JSONObj *obj)
1786 {
1787 std::string s;
1788 JSONDecoder::decode_json("status", s, obj);
1789 if (s == "full-sync") {
1790 state = StateFullSync;
1791 } else if (s == "incremental-sync") {
1792 state = StateIncrementalSync;
1793 } else if (s == "stopped") {
1794 state = StateStopped;
1795 } else {
1796 state = StateInit;
1797 }
1798 JSONDecoder::decode_json("full_marker", full_marker, obj);
1799 JSONDecoder::decode_json("inc_marker", inc_marker, obj);
1800 }
1801
1802 void rgw_bucket_shard_sync_info::dump(Formatter *f) const
1803 {
1804 const char *s{nullptr};
1805 switch ((SyncState)state) {
1806 case StateInit:
1807 s = "init";
1808 break;
1809 case StateFullSync:
1810 s = "full-sync";
1811 break;
1812 case StateIncrementalSync:
1813 s = "incremental-sync";
1814 break;
1815 case StateStopped:
1816 s = "stopped";
1817 break;
1818 default:
1819 s = "unknown";
1820 break;
1821 }
1822 encode_json("status", s, f);
1823 encode_json("full_marker", full_marker, f);
1824 encode_json("inc_marker", inc_marker, f);
1825 }
1826
1827 /* This utility function shouldn't conflict with the overload of std::to_string
1828 * provided by string_ref since Boost 1.54 as it's defined outside of the std
1829 * namespace. I hope we'll remove it soon - just after merging the Matt's PR
1830 * for bundled Boost. It would allow us to forget that CentOS 7 has Boost 1.53. */
1831 static inline std::string to_string(const std::string_view& s)
1832 {
1833 return std::string(s.data(), s.length());
1834 }
1835
1836 void rgw::keystone::AdminTokenRequestVer2::dump(Formatter* const f) const
1837 {
1838 f->open_object_section("token_request");
1839 f->open_object_section("auth");
1840 f->open_object_section("passwordCredentials");
1841 encode_json("username", ::to_string(conf.get_admin_user()), f);
1842 encode_json("password", ::to_string(conf.get_admin_password()), f);
1843 f->close_section();
1844 encode_json("tenantName", ::to_string(conf.get_admin_tenant()), f);
1845 f->close_section();
1846 f->close_section();
1847 }
1848
1849 void rgw::keystone::AdminTokenRequestVer3::dump(Formatter* const f) const
1850 {
1851 f->open_object_section("token_request");
1852 f->open_object_section("auth");
1853 f->open_object_section("identity");
1854 f->open_array_section("methods");
1855 f->dump_string("", "password");
1856 f->close_section();
1857 f->open_object_section("password");
1858 f->open_object_section("user");
1859 f->open_object_section("domain");
1860 encode_json("name", ::to_string(conf.get_admin_domain()), f);
1861 f->close_section();
1862 encode_json("name", ::to_string(conf.get_admin_user()), f);
1863 encode_json("password", ::to_string(conf.get_admin_password()), f);
1864 f->close_section();
1865 f->close_section();
1866 f->close_section();
1867 f->open_object_section("scope");
1868 f->open_object_section("project");
1869 if (! conf.get_admin_project().empty()) {
1870 encode_json("name", ::to_string(conf.get_admin_project()), f);
1871 } else {
1872 encode_json("name", ::to_string(conf.get_admin_tenant()), f);
1873 }
1874 f->open_object_section("domain");
1875 encode_json("name", ::to_string(conf.get_admin_domain()), f);
1876 f->close_section();
1877 f->close_section();
1878 f->close_section();
1879 f->close_section();
1880 f->close_section();
1881 }
1882
1883
1884 void rgw::keystone::BarbicanTokenRequestVer2::dump(Formatter* const f) const
1885 {
1886 f->open_object_section("token_request");
1887 f->open_object_section("auth");
1888 f->open_object_section("passwordCredentials");
1889 encode_json("username", cct->_conf->rgw_keystone_barbican_user, f);
1890 encode_json("password", cct->_conf->rgw_keystone_barbican_password, f);
1891 f->close_section();
1892 encode_json("tenantName", cct->_conf->rgw_keystone_barbican_tenant, f);
1893 f->close_section();
1894 f->close_section();
1895 }
1896
1897 void rgw::keystone::BarbicanTokenRequestVer3::dump(Formatter* const f) const
1898 {
1899 f->open_object_section("token_request");
1900 f->open_object_section("auth");
1901 f->open_object_section("identity");
1902 f->open_array_section("methods");
1903 f->dump_string("", "password");
1904 f->close_section();
1905 f->open_object_section("password");
1906 f->open_object_section("user");
1907 f->open_object_section("domain");
1908 encode_json("name", cct->_conf->rgw_keystone_barbican_domain, f);
1909 f->close_section();
1910 encode_json("name", cct->_conf->rgw_keystone_barbican_user, f);
1911 encode_json("password", cct->_conf->rgw_keystone_barbican_password, f);
1912 f->close_section();
1913 f->close_section();
1914 f->close_section();
1915 f->open_object_section("scope");
1916 f->open_object_section("project");
1917 if (!cct->_conf->rgw_keystone_barbican_project.empty()) {
1918 encode_json("name", cct->_conf->rgw_keystone_barbican_project, f);
1919 } else {
1920 encode_json("name", cct->_conf->rgw_keystone_barbican_tenant, f);
1921 }
1922 f->open_object_section("domain");
1923 encode_json("name", cct->_conf->rgw_keystone_barbican_domain, f);
1924 f->close_section();
1925 f->close_section();
1926 f->close_section();
1927 f->close_section();
1928 f->close_section();
1929 }
1930
1931 void RGWOrphanSearchStage::dump(Formatter *f) const
1932 {
1933 f->open_object_section("orphan_search_stage");
1934 string s;
1935 switch(stage){
1936 case ORPHAN_SEARCH_STAGE_INIT:
1937 s = "init";
1938 break;
1939 case ORPHAN_SEARCH_STAGE_LSPOOL:
1940 s = "lspool";
1941 break;
1942 case ORPHAN_SEARCH_STAGE_LSBUCKETS:
1943 s = "lsbuckets";
1944 break;
1945 case ORPHAN_SEARCH_STAGE_ITERATE_BI:
1946 s = "iterate_bucket_index";
1947 break;
1948 case ORPHAN_SEARCH_STAGE_COMPARE:
1949 s = "comparing";
1950 break;
1951 default:
1952 s = "unknown";
1953 }
1954 f->dump_string("search_stage", s);
1955 f->dump_int("shard",shard);
1956 f->dump_string("marker",marker);
1957 f->close_section();
1958 }
1959
1960 void RGWOrphanSearchInfo::dump(Formatter *f) const
1961 {
1962 f->open_object_section("orphan_search_info");
1963 f->dump_string("job_name", job_name);
1964 encode_json("pool", pool, f);
1965 f->dump_int("num_shards", num_shards);
1966 encode_json("start_time", start_time, f);
1967 f->close_section();
1968 }
1969
1970 void RGWOrphanSearchState::dump(Formatter *f) const
1971 {
1972 f->open_object_section("orphan_search_state");
1973 encode_json("info", info, f);
1974 encode_json("stage", stage, f);
1975 f->close_section();
1976 }
1977
1978 void RGWObjTags::dump(Formatter *f) const
1979 {
1980 f->open_object_section("tagset");
1981 for (auto& tag: tag_map){
1982 f->dump_string(tag.first.c_str(), tag.second);
1983 }
1984 f->close_section();
1985 }
1986
1987 void lc_op::dump(Formatter *f) const
1988 {
1989 f->dump_bool("status", status);
1990 f->dump_bool("dm_expiration", dm_expiration);
1991
1992 f->dump_int("expiration", expiration);
1993 f->dump_int("noncur_expiration", noncur_expiration);
1994 f->dump_int("mp_expiration", mp_expiration);
1995 if (expiration_date) {
1996 utime_t ut(*expiration_date);
1997 f->dump_stream("expiration_date") << ut;
1998 }
1999 if (obj_tags) {
2000 f->dump_object("obj_tags", *obj_tags);
2001 }
2002 f->open_object_section("transitions");
2003 for(auto& [storage_class, transition] : transitions) {
2004 f->dump_object(storage_class, transition);
2005 }
2006 f->close_section();
2007
2008 f->open_object_section("noncur_transitions");
2009 for (auto& [storage_class, transition] : noncur_transitions) {
2010 f->dump_object(storage_class, transition);
2011 }
2012 f->close_section();
2013 }
2014
2015 void LCFilter::dump(Formatter *f) const
2016 {
2017 f->dump_string("prefix", prefix);
2018 f->dump_object("obj_tags", obj_tags);
2019 }
2020
2021 void LCExpiration::dump(Formatter *f) const
2022 {
2023 f->dump_string("days", days);
2024 f->dump_string("date", date);
2025 }
2026
2027 void LCRule::dump(Formatter *f) const
2028 {
2029 f->dump_string("id", id);
2030 f->dump_string("prefix", prefix);
2031 f->dump_string("status", status);
2032 f->dump_object("expiration", expiration);
2033 f->dump_object("noncur_expiration", noncur_expiration);
2034 f->dump_object("mp_expiration", mp_expiration);
2035 f->dump_object("filter", filter);
2036 f->open_object_section("transitions");
2037 for (auto& [storage_class, transition] : transitions) {
2038 f->dump_object(storage_class, transition);
2039 }
2040 f->close_section();
2041
2042 f->open_object_section("noncur_transitions");
2043 for (auto& [storage_class, transition] : noncur_transitions) {
2044 f->dump_object(storage_class, transition);
2045 }
2046 f->close_section();
2047 f->dump_bool("dm_expiration", dm_expiration);
2048 }
2049
2050 void RGWLifecycleConfiguration::dump(Formatter *f) const
2051 {
2052 f->open_object_section("prefix_map");
2053 for (auto& prefix : prefix_map) {
2054 f->dump_object(prefix.first.c_str(), prefix.second);
2055 }
2056 f->close_section();
2057
2058 f->open_array_section("rule_map");
2059 for (auto& rule : rule_map) {
2060 f->open_object_section("entry");
2061 f->dump_string("id", rule.first);
2062 f->open_object_section("rule");
2063 rule.second.dump(f);
2064 f->close_section();
2065 f->close_section();
2066 }
2067 f->close_section();
2068 }
2069
2070 void compression_block::dump(Formatter *f) const
2071 {
2072 f->dump_unsigned("old_ofs", old_ofs);
2073 f->dump_unsigned("new_ofs", new_ofs);
2074 f->dump_unsigned("len", len);
2075 }
2076
2077 void RGWCompressionInfo::dump(Formatter *f) const
2078 {
2079 f->dump_string("compression_type", compression_type);
2080 f->dump_unsigned("orig_size", orig_size);
2081 if (compressor_message) {
2082 f->dump_int("compressor_message", *compressor_message);
2083 }
2084 ::encode_json("blocks", blocks, f);
2085 }
2086
2087 void objexp_hint_entry::dump(Formatter *f) const
2088 {
2089 f->open_object_section("objexp_hint_entry");
2090 encode_json("tenant", tenant, f);
2091 encode_json("bucket_name", bucket_name, f);
2092 encode_json("bucket_id", bucket_id, f);
2093 encode_json("rgw_obj_key", obj_key, f);
2094 utime_t ut(exp_time);
2095 encode_json("exp_time", ut, f);
2096 f->close_section();
2097 }
2098
2099 void rgw_user::dump(Formatter *f) const
2100 {
2101 ::encode_json("user", *this, f);
2102 }