From: Andrei Pavel Date: Fri, 20 Jun 2025 09:44:28 +0000 (+0300) Subject: [#3907] Get rid of skips in yang. Skip was always true X-Git-Tag: Kea-3.0.0~10 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=2eed0ebf82fb40c3ebc7c1bb2776b2a1e2fa858a;p=thirdparty%2Fkea.git [#3907] Get rid of skips in yang. Skip was always true --- diff --git a/src/lib/yang/translator_control_socket.cc b/src/lib/yang/translator_control_socket.cc index d1576c8120..bd135a2168 100644 --- a/src/lib/yang/translator_control_socket.cc +++ b/src/lib/yang/translator_control_socket.cc @@ -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 diff --git a/src/lib/yang/translator_control_socket.h b/src/lib/yang/translator_control_socket.h index b9cc12c3b1..c1f58645b1 100644 --- a/src/lib/yang/translator_control_socket.h +++ b/src/lib/yang/translator_control_socket.h @@ -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 diff --git a/src/lib/yang/translator_database.cc b/src/lib/yang/translator_database.cc index 36b79a786c..cb5e67ba51 100644 --- a/src/lib/yang/translator_database.cc +++ b/src/lib/yang/translator_database.cc @@ -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); } } diff --git a/src/lib/yang/translator_database.h b/src/lib/yang/translator_database.h index e9648d18be..7866427428 100644 --- a/src/lib/yang/translator_database.h +++ b/src/lib/yang/translator_database.h @@ -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