]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3106] Fixes in the HA config parser
authorMarcin Siodelski <marcin@isc.org>
Tue, 28 Nov 2023 10:48:53 +0000 (11:48 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 29 Nov 2023 19:58:55 +0000 (20:58 +0100)
- renamed two functions
- removed redundant check
- better exception text

src/hooks/dhcp/high_availability/ha_config_parser.cc
src/hooks/dhcp/high_availability/ha_config_parser.h

index 8619ca9f0bfb7d2c5083d7c97847d7d905b3bd7a..7b8106e3944c5f7072819a2e7dfaf118d711e6fa 100644 (file)
@@ -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());
         }
     }
 }
index 8e56ea868e63997d0e7545b1d4d5719c1daa8afb..ad99ae7e4755db452b0799bff3cfbafb3ab58a43 100644 (file)
@@ -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.
     ///