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