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