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