@@ -25,7 +25,7 @@ namespace {
2525std::string ToLower (const std::string& str) {
2626 std::string result = str;
2727 std::transform (result.begin (), result.end (), result.begin (),
28- [](unsigned char c ) { return std::tolower (c ); });
28+ [](unsigned char ch_value ) { return std::tolower (ch_value ); });
2929 return result;
3030}
3131
@@ -38,15 +38,17 @@ std::string ToLower(const std::string& str) {
3838std::string JsonValueToString (const nlohmann::json& value) {
3939 if (value.is_string ()) {
4040 return " \" " + value.get <std::string>() + " \" " ;
41- } else if (value.is_boolean ()) {
41+ }
42+ if (value.is_boolean ()) {
4243 return value.get <bool >() ? " true" : " false" ;
43- } else if (value.is_number ()) {
44+ }
45+ if (value.is_number ()) {
4446 return value.dump ();
45- } else if (value.is_null ()) {
47+ }
48+ if (value.is_null ()) {
4649 return " null" ;
47- } else {
48- return value.dump ();
4950 }
51+ return value.dump ();
5052}
5153
5254/* *
@@ -286,17 +288,25 @@ std::optional<nlohmann::json> NavigateJsonPath(const nlohmann::json& json, const
286288 */
287289void MaskSensitiveFieldsRecursive (nlohmann::json& json, const std::string& path) {
288290 if (json.is_object ()) {
289- for (auto it = json.begin (); it != json.end (); ++it) {
290- std::string child_path = path.empty () ? it.key () : path + " ." + it.key ();
291+ for (const auto & [key, child] : json.items ()) {
292+ std::string child_path;
293+ if (path.empty ()) {
294+ child_path = key;
295+ } else {
296+ child_path.reserve (path.size () + 1 + key.size ());
297+ child_path.assign (path);
298+ child_path.push_back (' .' );
299+ child_path.append (key);
300+ }
291301 if (IsSensitiveField (child_path)) {
292- it. value () = " ***" ;
293- } else if (it. value (). is_object () || it. value () .is_array ()) {
294- MaskSensitiveFieldsRecursive (it. value () , child_path);
302+ json[key] = " ***" ;
303+ } else if (child. is_object () || child .is_array ()) {
304+ MaskSensitiveFieldsRecursive (json[key] , child_path);
295305 }
296306 }
297307 } else if (json.is_array ()) {
298- for (size_t i = 0 ; i < json. size (); ++i ) {
299- MaskSensitiveFieldsRecursive (json[i] , path);
308+ for (auto & child : json) {
309+ MaskSensitiveFieldsRecursive (child , path);
300310 }
301311 }
302312}
@@ -313,12 +323,12 @@ std::string JsonToYaml(const nlohmann::json& json, int indent = 0) {
313323 std::string indent_str (indent * 2 , ' ' );
314324
315325 if (json.is_object ()) {
316- for (auto it = json. begin (); it != json.end (); ++it ) {
317- oss << indent_str << it. key () << " :" ;
318- if (it. value (). is_object () || it. value () .is_array ()) {
319- oss << " \n " << JsonToYaml (it. value () , indent + 1 );
326+ for (const auto & [key, child] : json.items () ) {
327+ oss << indent_str << key << " :" ;
328+ if (child. is_object () || child .is_array ()) {
329+ oss << " \n " << JsonToYaml (child , indent + 1 );
320330 } else {
321- oss << " " << JsonValueToString (it. value () ) << " \n " ;
331+ oss << " " << JsonValueToString (child ) << " \n " ;
322332 }
323333 }
324334 } else if (json.is_array ()) {
@@ -327,21 +337,21 @@ std::string JsonToYaml(const nlohmann::json& json, int indent = 0) {
327337 if (item.is_object ()) {
328338 // First property on same line, rest indented
329339 bool first = true ;
330- for (auto it = item. begin (); it != item.end (); ++it ) {
340+ for (const auto & [key, value] : item.items () ) {
331341 if (first) {
332- oss << " " << it. key () << " :" ;
333- if (it. value () .is_object () || it. value () .is_array ()) {
334- oss << " \n " << JsonToYaml (it. value () , indent + 2 );
342+ oss << " " << key << " :" ;
343+ if (value.is_object () || value.is_array ()) {
344+ oss << " \n " << JsonToYaml (value, indent + 2 );
335345 } else {
336- oss << " " << JsonValueToString (it. value () ) << " \n " ;
346+ oss << " " << JsonValueToString (value) << " \n " ;
337347 }
338348 first = false ;
339349 } else {
340- oss << std::string ((indent + 1 ) * 2 , ' ' ) << it. key () << " :" ;
341- if (it. value () .is_object () || it. value () .is_array ()) {
342- oss << " \n " << JsonToYaml (it. value () , indent + 2 );
350+ oss << std::string ((indent + 1 ) * 2 , ' ' ) << key << " :" ;
351+ if (value.is_object () || value.is_array ()) {
352+ oss << " \n " << JsonToYaml (value, indent + 2 );
343353 } else {
344- oss << " " << JsonValueToString (it. value () ) << " \n " ;
354+ oss << " " << JsonValueToString (value) << " \n " ;
345355 }
346356 }
347357 }
@@ -395,19 +405,19 @@ std::map<std::string, std::string> ConfigSchemaExplorer::ListPaths(const std::st
395405 // List properties
396406 if (current.contains (" properties" )) {
397407 const auto & properties = current[" properties" ];
398- for (auto it = properties. begin (); it != properties.end (); ++it ) {
408+ for (const auto & [key, property] : properties.items () ) {
399409 std::string description;
400- if (it. value () .contains (" description" )) {
401- description = it. value () [" description" ].get <std::string>();
410+ if (property .contains (" description" )) {
411+ description = property [" description" ].get <std::string>();
402412 }
403- result[it. key () ] = description;
413+ result[key] = description;
404414 }
405415 }
406416
407417 return result;
408418}
409419
410- std::string ConfigSchemaExplorer::FormatHelp (const ConfigHelpInfo& info) const {
420+ std::string ConfigSchemaExplorer::FormatHelp (const ConfigHelpInfo& info) {
411421 std::ostringstream oss;
412422
413423 oss << info.path << " \n\n " ;
@@ -477,7 +487,7 @@ std::string ConfigSchemaExplorer::FormatHelp(const ConfigHelpInfo& info) const {
477487}
478488
479489std::string ConfigSchemaExplorer::FormatPathList (const std::map<std::string, std::string>& paths,
480- const std::string& parent_path) const {
490+ const std::string& parent_path) {
481491 std::ostringstream oss;
482492
483493 if (parent_path.empty ()) {
@@ -538,8 +548,7 @@ std::optional<nlohmann::json> ConfigSchemaExplorer::FindSchemaNode(const std::st
538548 return current;
539549}
540550
541- ConfigHelpInfo ConfigSchemaExplorer::ExtractHelpInfo (const std::string& path,
542- const nlohmann::json& node) const {
551+ ConfigHelpInfo ConfigSchemaExplorer::ExtractHelpInfo (const std::string& path, const nlohmann::json& node) {
543552 ConfigHelpInfo info;
544553 info.path = path;
545554
@@ -552,7 +561,9 @@ ConfigHelpInfo ConfigSchemaExplorer::ExtractHelpInfo(const std::string& path,
552561 std::ostringstream oss;
553562 bool first = true ;
554563 for (const auto & type : node[" type" ]) {
555- if (!first) oss << " | " ;
564+ if (!first) {
565+ oss << " | " ;
566+ }
556567 oss << type.get <std::string>();
557568 first = false ;
558569 }
@@ -621,9 +632,8 @@ std::vector<std::string> ConfigSchemaExplorer::SplitPath(const std::string& path
621632
622633bool IsSensitiveField (const std::string& path) {
623634 std::string lower_path = ToLower (path);
624- return lower_path.find (" password" ) != std::string::npos ||
625- lower_path.find (" secret" ) != std::string::npos || lower_path.find (" key" ) != std::string::npos ||
626- lower_path.find (" token" ) != std::string::npos;
635+ return lower_path.find (" password" ) != std::string::npos || lower_path.find (" secret" ) != std::string::npos ||
636+ lower_path.find (" key" ) != std::string::npos || lower_path.find (" token" ) != std::string::npos;
627637}
628638
629639std::string MaskSensitiveValue (const std::string& path, const std::string& value) {
0 commit comments