]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3907] Get rid of skips in yang. Skip was always true
authorAndrei Pavel <andrei@isc.org>
Fri, 20 Jun 2025 09:44:28 +0000 (12:44 +0300)
committerRazvan Becheriu <razvan@isc.org>
Fri, 20 Jun 2025 13:29:10 +0000 (13:29 +0000)
src/lib/yang/translator_control_socket.cc
src/lib/yang/translator_control_socket.h
src/lib/yang/translator_database.cc
src/lib/yang/translator_database.h

index d1576c8120a7264ffcc6288bdd4e00d43eb00ce9..bd135a216845e97e29b106302a8c14c4f1545e22 100644 (file)
@@ -153,7 +153,7 @@ TranslatorControlSocket::setControlSockets(string const& xpath,
             (model_ == KEA_DHCP_DDNS)) {
             setControlSocketsKea(xpath, elem);
         } else if (model_ == KEA_CTRL_AGENT) {
-            setControlSocketKea(xpath, elem, false);
+            setControlSocketKea(xpath, elem);
         } else {
           isc_throw(NotImplemented,
                     "setControlSocket not implemented for the model: "
@@ -174,7 +174,7 @@ TranslatorControlSocket::setControlSocket(string const& xpath,
             (model_ == KEA_DHCP6_SERVER) ||
             (model_ == KEA_DHCP_DDNS) ||
             (model_ == KEA_CTRL_AGENT)) {
-            setControlSocketKea(xpath, elem, true);
+            setControlSocketKea(xpath, elem);
         } else {
           isc_throw(NotImplemented,
                     "setControlSocket not implemented for the model: "
@@ -202,14 +202,12 @@ TranslatorControlSocket::setControlSocketsKea(string const& xpath,
         string type = control_socket->get("socket-type")->stringValue();
         ostringstream key;
         key << xpath << "[socket-type='" << type << "']";
-        setControlSocketKea(key.str(), control_socket, true);
+        setControlSocketKea(key.str(), control_socket);
     }
 }
 
 void
-TranslatorControlSocket::setControlSocketKea(string const& xpath,
-                                             ConstElementPtr elem,
-                                             bool skip) {
+TranslatorControlSocket::setControlSocketKea(string const& xpath, ConstElementPtr elem) {
     if (!elem) {
         deleteItem(xpath);
         return;
@@ -217,41 +215,34 @@ TranslatorControlSocket::setControlSocketKea(string const& xpath,
 
     checkAndSetLeaf(elem, xpath, "socket-name", LeafBaseType::String);
 
-    if (model_ == KEA_CTRL_AGENT) {
-        setMandatoryLeaf(elem, xpath, "socket-type", LeafBaseType::Enum);
-    } else {
-        checkAndSetLeaf(elem, xpath, "socket-address", LeafBaseType::String);
-        checkAndSetLeaf(elem, xpath, "socket-port", LeafBaseType::Uint32);
-        checkAndSetLeaf(elem, xpath, "trust-anchor", LeafBaseType::String);
-        checkAndSetLeaf(elem, xpath, "cert-file", LeafBaseType::String);
-        checkAndSetLeaf(elem, xpath, "key-file", LeafBaseType::String);
-        checkAndSetLeaf(elem, xpath, "cert-required", LeafBaseType::Bool);
-        ConstElementPtr authentication = elem->get("authentication");
-        if (authentication && !authentication->empty()) {
-            setMandatoryDivergingLeaf(authentication, xpath , "type", "auth-type", LeafBaseType::String);
-            checkAndSetLeaf(authentication, xpath + "/authentication", "realm", LeafBaseType::String);
-            checkAndSetLeaf(authentication, xpath + "/authentication", "directory", LeafBaseType::String);
-            ConstElementPtr clients = authentication->get("clients");
-            setControlSocketAuthenticationClients(xpath + "/authentication/clients", clients, skip);
-        }
-        ConstElementPtr http_headers = elem->get("http-headers");
-        if (http_headers && !http_headers->empty()) {
-            for (size_t i = 0; i < http_headers->size(); ++i) {
-                ElementPtr header = elem->getNonConst(i);
-                // setHeader
-            }
-        }
-        if (!skip) {
-            setMandatoryLeaf(elem, xpath, "socket-type", LeafBaseType::Enum);
+    checkAndSetLeaf(elem, xpath, "socket-address", LeafBaseType::String);
+    checkAndSetLeaf(elem, xpath, "socket-port", LeafBaseType::Uint32);
+    checkAndSetLeaf(elem, xpath, "trust-anchor", LeafBaseType::String);
+    checkAndSetLeaf(elem, xpath, "cert-file", LeafBaseType::String);
+    checkAndSetLeaf(elem, xpath, "key-file", LeafBaseType::String);
+    checkAndSetLeaf(elem, xpath, "cert-required", LeafBaseType::Bool);
+    ConstElementPtr authentication = elem->get("authentication");
+    if (authentication && !authentication->empty()) {
+        setMandatoryDivergingLeaf(authentication, xpath , "type", "auth-type", LeafBaseType::String);
+        checkAndSetLeaf(authentication, xpath + "/authentication", "realm", LeafBaseType::String);
+        checkAndSetLeaf(authentication, xpath + "/authentication", "directory", LeafBaseType::String);
+        ConstElementPtr clients = authentication->get("clients");
+        setControlSocketAuthenticationClients(xpath + "/authentication/clients", clients);
+    }
+    ConstElementPtr http_headers = elem->get("http-headers");
+    if (http_headers && !http_headers->empty()) {
+        for (size_t i = 0; i < http_headers->size(); ++i) {
+            ElementPtr header = elem->getNonConst(i);
+            // setHeader
         }
     }
+    setMandatoryLeaf(elem, xpath, "socket-type", LeafBaseType::Enum);
     checkAndSetUserContext(elem, xpath);
 }
 
 void
 TranslatorControlSocket::setControlSocketAuthenticationClients(string const& xpath,
-                                                               ConstElementPtr elem,
-                                                               bool skip) {
+                                                               ConstElementPtr elem) {
     if (!elem) {
         deleteItem(xpath);
         return;
@@ -282,21 +273,19 @@ TranslatorControlSocket::setControlSocketAuthenticationClients(string const& xpa
         key << xpath << "[user='" << user_str << "'][password=']" << password_str
                      << "'][user-file='" << user_file_str << "'][password-file='"
                      << password_file_str << "']";
-        setControlSocketAuthenticationClient(key.str(), client, skip);
+        setControlSocketAuthenticationClient(key.str(), client);
     }
 }
 
 void
 TranslatorControlSocket::setControlSocketAuthenticationClient(string const& xpath,
-                                                              ConstElementPtr /* elem */,
-                                                              bool /* skip */) {
+                                                              ConstElementPtr /* elem */) {
     setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
 }
 
 void
 TranslatorControlSocket::setControlSocketHttpHeaders(const std::string& xpath,
-                            isc::data::ConstElementPtr elem,
-                            bool skip) {
+                                                     isc::data::ConstElementPtr elem) {
     if (!elem) {
         deleteItem(xpath);
         return;
@@ -308,19 +297,16 @@ TranslatorControlSocket::setControlSocketHttpHeaders(const std::string& xpath,
             isc_throw(BadValue, "http header without name: " << header->str());
         }
         key << xpath << "[name='" << header->stringValue() << "']";
-        setControlSocketHttpHeader(key.str(), header, skip);
+        setControlSocketHttpHeader(key.str(), header);
     }
 }
 
 void
 TranslatorControlSocket::setControlSocketHttpHeader(const std::string& xpath,
-                                                    isc::data::ConstElementPtr elem,
-                                                    bool skip) {
+                                                    isc::data::ConstElementPtr elem) {
     checkAndSetLeaf(elem, xpath, "value", LeafBaseType::String);
     checkAndSetUserContext(elem, xpath);
-    if (!skip) {
-        setMandatoryLeaf(elem, xpath, "name", LeafBaseType::Enum);
-    }
+    setMandatoryLeaf(elem, xpath, "name", LeafBaseType::Enum);
 }
 
 }  // namespace yang
index b9cc12c3b1a977c0ea374d5c51beff8163d54efb..c1f58645b162557577785cb2e28a443f579b4925 100644 (file)
@@ -187,11 +187,8 @@ protected:
     ///
     /// @param xpath The xpath of the control socket.
     /// @param elem The JSON element.
-    /// @param skip The skip type field flag.
     /// @throw BadValue on control socket without socket type or name.
-    void setControlSocketKea(const std::string& xpath,
-                             isc::data::ConstElementPtr elem,
-                             bool skip);
+    void setControlSocketKea(const std::string& xpath, isc::data::ConstElementPtr elem);
 
     /// @brief setControlSocketAuthenticationClients for kea models.
     ///
@@ -201,11 +198,9 @@ protected:
     ///
     /// @param xpath The xpath of the control socket.
     /// @param elem The JSON element.
-    /// @param skip The skip type field flag.
     /// @throw BadValue on control socket without socket type or name.
     void setControlSocketAuthenticationClients(const std::string& xpath,
-                                               isc::data::ConstElementPtr elem,
-                                               bool skip);
+                                               isc::data::ConstElementPtr elem);
 
     /// @brief setControlSocketAuthenticationClient for kea models.
     ///
@@ -215,11 +210,9 @@ protected:
     ///
     /// @param xpath The xpath of the control socket.
     /// @param elem The JSON element.
-    /// @param skip The skip type field flag.
     /// @throw BadValue on control socket without socket type or name.
-    void setControlSocketAuthenticationClient(const std::string& xpath,
-                                              isc::data::ConstElementPtr elem,
-                                              bool skip);
+    void
+    setControlSocketAuthenticationClient(const std::string& xpath, isc::data::ConstElementPtr elem);
 
     /// @brief setControlSocketHttpHeaders for kea models.
     ///
@@ -229,11 +222,8 @@ protected:
     ///
     /// @param xpath The xpath of the control socket.
     /// @param elem The JSON element.
-    /// @param skip The skip type field flag.
     /// @throw BadValue on control socket without socket type or name.
-    void setControlSocketHttpHeaders(const std::string& xpath,
-                                     isc::data::ConstElementPtr elem,
-                                     bool skip);
+    void setControlSocketHttpHeaders(const std::string& xpath, isc::data::ConstElementPtr elem);
 
     /// @brief setControlSocketHttpHeader for kea models.
     ///
@@ -243,11 +233,8 @@ protected:
     ///
     /// @param xpath The xpath of the control socket.
     /// @param elem The JSON element.
-    /// @param skip The skip type field flag.
     /// @throw BadValue on control socket without socket type or name.
-    void setControlSocketHttpHeader(const std::string& xpath,
-                                    isc::data::ConstElementPtr elem,
-                                    bool skip);
+    void setControlSocketHttpHeader(const std::string& xpath, isc::data::ConstElementPtr elem);
 };  // TranslatorControlSocket
 
 }  // namespace yang
index 36b79a786c8146ad0bd6f20f988d8db2f4972939..cb5e67ba51b949ea34da5e15daed965901ed8e21 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2024 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2025 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -51,8 +51,6 @@ ElementPtr
 TranslatorDatabase::getDatabaseKea(DataNode const& data_node) {
     ElementPtr result = Element::createMap();
 
-    getMandatoryDivergingLeaf(result, data_node, "type", "database-type");
-
     checkAndGetLeaf(result, data_node, "cert-file");
     checkAndGetLeaf(result, data_node, "cipher-list");
     checkAndGetLeaf(result, data_node, "connect-timeout");
@@ -81,13 +79,11 @@ TranslatorDatabase::getDatabaseKea(DataNode const& data_node) {
 }
 
 void
-TranslatorDatabase::setDatabase(string const& xpath,
-                                ConstElementPtr elem,
-                                bool skip) {
+TranslatorDatabase::setDatabase(string const& xpath, ConstElementPtr elem) {
     try {
         if ((model_ == KEA_DHCP4_SERVER) ||
             (model_ == KEA_DHCP6_SERVER)) {
-            setDatabaseKea(xpath, elem, skip);
+            setDatabaseKea(xpath, elem);
         } else {
             isc_throw(NotImplemented,
                       "setDatabase not implemented for the model: " << model_);
@@ -100,13 +96,8 @@ TranslatorDatabase::setDatabase(string const& xpath,
 }
 
 void
-TranslatorDatabase::setDatabaseKea(string const& xpath,
-                                   ConstElementPtr elem,
-                                   bool skip) {
-    if (!elem) {
-        deleteItem(xpath);
-        return;
-    }
+TranslatorDatabase::setDatabaseKea(string const& xpath, ConstElementPtr elem) {
+    setItem(xpath, ElementPtr(), LeafBaseType::Unknown);
 
     checkAndSetLeaf(elem, xpath, "connect-timeout", LeafBaseType::Uint32);
     checkAndSetLeaf(elem, xpath, "cert-file", LeafBaseType::String);
@@ -131,10 +122,6 @@ TranslatorDatabase::setDatabaseKea(string const& xpath,
     checkAndSetLeaf(elem, xpath, "write-timeout", LeafBaseType::Uint32);
 
     checkAndSetUserContext(elem, xpath);
-
-    if (!skip) {
-        setMandatoryDivergingLeaf(elem, xpath, "type", "database-type", LeafBaseType::String);
-    }
 }
 
 TranslatorDatabases::TranslatorDatabases(Session session,
@@ -207,7 +194,7 @@ TranslatorDatabases::setDatabasesKea(string const& xpath,
         string type = database->get("type")->stringValue();
         ostringstream key;
         key << xpath << "[database-type='" << type << "']";
-        setDatabase(key.str(), database, true);
+        setDatabase(key.str(), database);
     }
 }
 
index e9648d18beff52a4ce25474a3908fee69e66b0ef..7866427428376de544b14714bc3391dc8fd6ebb7 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2024 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2025 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -141,10 +141,7 @@ public:
     ///
     /// @param xpath The xpath of the database access.
     /// @param elem The JSON element.
-    /// @param skip The skip type field flag.
-    void setDatabase(const std::string& xpath,
-                     isc::data::ConstElementPtr elem,
-                     bool skip = false);
+    void setDatabase(const std::string& xpath, isc::data::ConstElementPtr elem);
 
 protected:
     /// @brief getDatabase JSON for kea-dhcp[46]-server models.
@@ -160,11 +157,8 @@ protected:
     ///
     /// @param xpath The xpath of the database access.
     /// @param elem The JSON element.
-    /// @param skip The skip type field flag.
     /// @throw BadValue on database without type,
-    void setDatabaseKea(const std::string& xpath,
-                        isc::data::ConstElementPtr elem,
-                        bool skip);
+    void setDatabaseKea(const std::string& xpath, isc::data::ConstElementPtr elem);
 };  // TranslatorDatabase
 
 /// @brief A translator class for converting a database access list between