From 6677658992af9735e70c521f9f46871d87a34d85 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 10 Apr 2022 09:23:59 +0800 Subject: [PATCH] common/ceph_json: dump bool using f->dump_bool() as per https://www.json.org/json-en.html, JSON encodes bool as "true" or "false", without the quotes. before this change, the quotes are always added when encoding boolean values. but this change is not backward compatible. encode_json()'s bool overload is used by rgw. it uses JSONObj defined in common/ceph_json.h to decode JSON-encoded structs. and it does not differentiate bool from str when decoding a boolean value despite that it could have check the "quoted" member variable of JSONObj for validating the type of value. so we should be fine. Fixes: https://tracker.ceph.com/issues/55189 Signed-off-by: Kefu Chai --- PendingReleaseNotes | 38 +++++++++++++++++++ doc/radosgw/pubsub-module.rst | 6 +-- src/common/ceph_json.cc | 8 +--- .../mgr/dashboard/services/rgw_client.py | 3 +- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/PendingReleaseNotes b/PendingReleaseNotes index 7f4381b34455c..19833faafcbf3 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -5,3 +5,41 @@ defaults to "/var/log/ceph/ops-log-$cluster-$name.log". * The SPDK backend for BlueStore is now able to connect to an NVMeoF target. Please note that this is not an officially supported feature. +* RGW's pubsub interface now returns boolean fields using bool. Before this change, + `/topics/` returns "stored_secret" and "persistent" using a string + of "true" or "false" with quotes around them. After this change, these fields + are returned without quotes so they can be decoded as boolean values in JSON. + The same applies to the `is_truncated` field returned by `/subscriptions/`. +* RGW's response of `Action=GetTopicAttributes&TopicArn=` REST API now + returns `HasStoredSecret` and `Persistent` as boolean in the JSON string + encoded in `Attributes/EndPoint`. +* All boolean fields previously rendered as string by `rgw-admin` command when + the JSON format is used are now rendered as boolean. If your scripts/tools + relies on this behavior, please update them accordingly. The impacted field names + are: + * absolute + * add + * admin + * appendable + * bucket_key_enabled + * delete_marker + * exists + * has_bucket_info + * high_precision_time + * index + * is_master + * is_prefix + * is_truncated + * linked + * log_meta + * log_op + * pending_removal + * read_only + * retain_head_object + * rule_exist + * start_with_full_sync + * sync_from_all + * syncstopped + * system + * truncated + * user_stats_sync diff --git a/doc/radosgw/pubsub-module.rst b/doc/radosgw/pubsub-module.rst index a7e3b3a6e4aec..47e44661097dc 100644 --- a/doc/radosgw/pubsub-module.rst +++ b/doc/radosgw/pubsub-module.rst @@ -280,8 +280,8 @@ Response will have the following format (JSON): "push_endpoint":"", "push_endpoint_args":"", "push_endpoint_topic":"", - "stored_secret":"", - "persistent":"" + "stored_secret":false, + "persistent":true, }, "arn":"" "opaqueData":"" @@ -519,7 +519,7 @@ The response will hold information on the current marker and whether there are m :: - {"next_marker":"","is_truncated":"",...} + {"next_marker":"","is_truncated":false,...} The actual content of the response is depended with how the subscription was created. diff --git a/src/common/ceph_json.cc b/src/common/ceph_json.cc index b5f8756718b0f..3270d2c49b07c 100644 --- a/src/common/ceph_json.cc +++ b/src/common/ceph_json.cc @@ -531,13 +531,7 @@ void encode_json(const char *name, const char *val, Formatter *f) void encode_json(const char *name, bool val, Formatter *f) { - string s; - if (val) - s = "true"; - else - s = "false"; - - f->dump_string(name, s); + f->dump_bool(name, val); } void encode_json(const char *name, int val, Formatter *f) diff --git a/src/pybind/mgr/dashboard/services/rgw_client.py b/src/pybind/mgr/dashboard/services/rgw_client.py index d7cff2fa0557e..14a4b7750ddd0 100644 --- a/src/pybind/mgr/dashboard/services/rgw_client.py +++ b/src/pybind/mgr/dashboard/services/rgw_client.py @@ -5,7 +5,6 @@ import json import logging import re import xml.etree.ElementTree as ET # noqa: N814 -from distutils.util import strtobool from subprocess import SubprocessError from mgr_util import build_url @@ -467,7 +466,7 @@ class RgwClient(RestClient): def _is_system_user(self, admin_path, userid, request=None) -> bool: # pylint: disable=unused-argument response = request() - return strtobool(response['data']['system']) + return response['data']['system'] def is_system_user(self) -> bool: return self._is_system_user(self.admin_path, self.userid) -- 2.39.5