From: Marcin Siodelski Date: Tue, 28 Nov 2023 10:48:53 +0000 (+0100) Subject: [#3106] Fixes in the HA config parser X-Git-Tag: Kea-2.5.5~127 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2baec4f3e1679d4a617f2b03bfea135dc52c4bd1;p=thirdparty%2Fkea.git [#3106] Fixes in the HA config parser - renamed two functions - removed redundant check - better exception text --- diff --git a/src/hooks/dhcp/high_availability/ha_config_parser.cc b/src/hooks/dhcp/high_availability/ha_config_parser.cc index 8619ca9f0b..7b8106e394 100644 --- a/src/hooks/dhcp/high_availability/ha_config_parser.cc +++ b/src/hooks/dhcp/high_availability/ha_config_parser.cc @@ -72,7 +72,7 @@ HAConfigParser::parse(const ConstElementPtr& config) { // This may cause different types of exceptions. We catch them here // and throw unified exception type. - parseAllInternal(config_storage, config); + parseAll(config_storage, config); validateRelationships(config_storage); logConfigStatus(config_storage); return (config_storage); @@ -86,8 +86,8 @@ HAConfigParser::parse(const ConstElementPtr& config) { } void -HAConfigParser::parseAllInternal(const HAConfigMapperPtr& config_storage, - const ConstElementPtr& config) { +HAConfigParser::parseAll(const HAConfigMapperPtr& config_storage, + const ConstElementPtr& config) { // Config must be provided. if (!config) { isc_throw(ConfigError, "HA configuration must not be null"); @@ -105,13 +105,13 @@ HAConfigParser::parseAllInternal(const HAConfigMapperPtr& config_storage, isc_throw(ConfigError, "a list of HA configurations must not be empty"); } for (auto config : config_vec) { - parseOneInternal(config_storage, config); + parseOne(config_storage, config); } } void -HAConfigParser::parseOneInternal(const HAConfigMapperPtr& config_storage, - const ElementPtr& config) { +HAConfigParser::parseOne(const HAConfigMapperPtr& config_storage, + const ElementPtr& config) { // Config must be provided. if (!config) { isc_throw(ConfigError, "HA configuration must not be null"); @@ -135,11 +135,6 @@ HAConfigParser::parseOneInternal(const HAConfigMapperPtr& config_storage, // Set general defaults. setDefaults(config, HA_CONFIG_DEFAULTS); - // HA configuration must be a map. - if (config->getType() != Element::map) { - isc_throw(ConfigError, "expected list of maps in the HA configuration"); - } - // It must contain peers section. if (!config->contains("peers")) { isc_throw(ConfigError, "'peers' parameter missing in HA configuration"); @@ -383,8 +378,9 @@ HAConfigParser::parseOneInternal(const HAConfigMapperPtr& config_storage, try { config_storage->map(peer_config.first, rel_config); - } catch (...) { - isc_throw(HAConfigValidationError, "server names must be unique for different relationships"); + } catch (const std::exception& ex) { + isc_throw(HAConfigValidationError, "server names must be unique for different relationships: " + << ex.what()); } } } diff --git a/src/hooks/dhcp/high_availability/ha_config_parser.h b/src/hooks/dhcp/high_availability/ha_config_parser.h index 8e56ea868e..ad99ae7e47 100644 --- a/src/hooks/dhcp/high_availability/ha_config_parser.h +++ b/src/hooks/dhcp/high_availability/ha_config_parser.h @@ -34,8 +34,8 @@ private: /// is going to be stored. /// /// @param config Specified configuration. - static void parseAllInternal(const HAConfigMapperPtr& config_storage, - const data::ConstElementPtr& config); + static void parseAll(const HAConfigMapperPtr& config_storage, + const data::ConstElementPtr& config); /// @brief Parses HA configuration for a single relationship. /// @@ -46,8 +46,8 @@ private: /// /// @param config specified configuration for a relationship. /// @throw ConfigError when parsing fails or configuration is invalid. - static void parseOneInternal(const HAConfigMapperPtr& config_storage, - const data::ElementPtr& config); + static void parseOne(const HAConfigMapperPtr& config_storage, + const data::ElementPtr& config); /// @brief Validates and returns a value of the parameter. ///