From: Sage Weil Date: Sat, 5 Jun 2021 15:23:35 +0000 (-0400) Subject: common/cmdparse: fix CephBool validation for tell commands X-Git-Tag: v17.1.0~1726^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6bd4df3573f645163d0f2d4212da9ae265389dd7;p=ceph.git common/cmdparse: fix CephBool validation for tell commands The tell/asok validation uses a different validation path; make it work for CephBool arguments. Signed-off-by: Sage Weil --- diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index 7052b235fb99..9d28a5c57dbf 100644 --- a/src/common/cmdparse.cc +++ b/src/common/cmdparse.cc @@ -569,6 +569,30 @@ bool validate_str_arg(std::string_view value, } } +bool validate_bool(CephContext *cct, + const cmdmap_t& cmdmap, + const arg_desc_t& desc, + const std::string_view name, + const std::string_view type, + std::ostream& os) +{ + bool v; + try { + if (!cmd_getval(cmdmap, string(name), v)) { + if (auto req = desc.find("req"); + req != end(desc) && req->second == "false") { + return true; + } else { + os << "missing required parameter: '" << name << "'"; + return false; + } + } + return true; + } catch (const bad_cmd_get& e) { + return false; + } +} + template(cct, cmdmap, arg_desc, name, type, os); + } else if (type == "CephBool") { + return !validate_bool(cct, cmdmap, arg_desc, + name, type, os); } else { return !validate_arg(cct, cmdmap, arg_desc, name, type, os);