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