Skip to content

Commit 275a72c

Browse files
author
tempate
committed
Validate YAML tags on parsing
Signed-off-by: tempate <danieldiaz@eprosima.com> Uncrustify Signed-off-by: tempate <danieldiaz@eprosima.com> Rename validate_tags_ to validate_tags Signed-off-by: tempate <danieldiaz@eprosima.com> Validate new YAML options Signed-off-by: tempate <danieldiaz@eprosima.com> Make tag-sets static Signed-off-by: tempate <danieldiaz@eprosima.com>
1 parent bc15cd4 commit 275a72c

1 file changed

Lines changed: 65 additions & 18 deletions

File tree

ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <set>
16+
1517
#include <ddspipe_participants/configuration/DiscoveryServerParticipantConfiguration.hpp>
1618
#include <ddspipe_participants/configuration/EchoParticipantConfiguration.hpp>
1719
#include <ddspipe_participants/configuration/InitialPeersParticipantConfiguration.hpp>
@@ -23,6 +25,7 @@
2325
#include <ddspipe_yaml/Yaml.hpp>
2426
#include <ddspipe_yaml/YamlManager.hpp>
2527
#include <ddspipe_yaml/YamlReader.hpp>
28+
#include <ddspipe_yaml/YamlValidator.hpp>
2629

2730
#include <ddspipe_core/configuration/DdsPipeConfiguration.hpp>
2831
#include <ddspipe_core/configuration/MonitorConfiguration.hpp>
@@ -57,7 +60,7 @@ void YamlReader::fill(
5760
// Optional Topic QoS
5861
if (is_tag_present(yml, SPECS_QOS_TAG))
5962
{
60-
fill<core::types::TopicQoS>(object.topic_qos, get_value_in_tag(yml, SPECS_QOS_TAG), version);
63+
object.topic_qos = YamlReader::get<core::types::TopicQoS>(yml, SPECS_QOS_TAG, version);
6164
core::types::TopicQoS::default_topic_qos.set_value(object.topic_qos);
6265
}
6366

@@ -95,6 +98,34 @@ void YamlReader::fill(
9598
}
9699
}
97100

101+
template <>
102+
bool YamlValidator::validate<ddsrouter::core::SpecsConfiguration>(
103+
const Yaml& yml,
104+
const YamlReaderVersion& /* version */)
105+
{
106+
static const std::set<TagType> tags{
107+
NUMBER_THREADS_TAG,
108+
REMOVE_UNUSED_ENTITIES_TAG,
109+
SPECS_QOS_TAG,
110+
DISCOVERY_TRIGGER_TAG,
111+
LOG_CONFIGURATION_TAG,
112+
MONITOR_TAG};
113+
114+
return YamlValidator::validate_tags(yml, tags);
115+
}
116+
117+
template <>
118+
ddsrouter::core::SpecsConfiguration YamlReader::get<ddsrouter::core::SpecsConfiguration>(
119+
const Yaml& yml,
120+
const YamlReaderVersion version)
121+
{
122+
YamlValidator::validate<ddsrouter::core::SpecsConfiguration>(yml, version);
123+
124+
ddsrouter::core::SpecsConfiguration object;
125+
fill<ddsrouter::core::SpecsConfiguration>(object, yml, version);
126+
return object;
127+
}
128+
98129
template <>
99130
ddsrouter::core::types::ParticipantKind YamlReader::get(
100131
const Yaml& yml,
@@ -190,21 +221,14 @@ void YamlReader::fill(
190221
// Get optional routes
191222
if (YamlReader::is_tag_present(yml, ROUTES_TAG))
192223
{
193-
YamlReader::fill<core::RoutesConfiguration>(
194-
object.routes,
195-
YamlReader::get_value_in_tag(yml, ROUTES_TAG),
196-
version);
224+
object.routes = YamlReader::get<core::RoutesConfiguration>(yml, ROUTES_TAG, version);
197225
}
198226

199227
/////
200228
// Get optional topic routes
201229
if (YamlReader::is_tag_present(yml, TOPIC_ROUTES_TAG))
202230
{
203-
// get list, and parse each element as above
204-
YamlReader::fill<core::TopicRoutesConfiguration>(
205-
object.topic_routes,
206-
YamlReader::get_value_in_tag(yml, TOPIC_ROUTES_TAG),
207-
version);
231+
object.topic_routes = YamlReader::get<core::TopicRoutesConfiguration>(yml, TOPIC_ROUTES_TAG, version);
208232
}
209233

210234
/////
@@ -221,6 +245,9 @@ core::DdsPipeConfiguration YamlReader::get<core::DdsPipeConfiguration>(
221245
const Yaml& yml,
222246
const YamlReaderVersion version)
223247
{
248+
// The DdsPipeConfiguration's fields don't correspond to a YAML section and, therefore, can't be validated.
249+
// Instead, they are validated in the methods above (most of them in the DdsRouterConfiguration).
250+
224251
core::DdsPipeConfiguration object;
225252
fill<core::DdsPipeConfiguration>(object, yml, version);
226253
return object;
@@ -250,6 +277,7 @@ void YamlReader::fill(
250277
{
251278
ddsrouter::core::types::ParticipantKind kind =
252279
YamlReader::get<ddsrouter::core::types::ParticipantKind>(conf, PARTICIPANT_KIND_TAG, version);
280+
253281
object.participants_configurations.insert(
254282
{
255283
kind,
@@ -262,10 +290,9 @@ void YamlReader::fill(
262290
// Get optional specs configuration
263291
if (YamlReader::is_tag_present(yml, SPECS_TAG))
264292
{
265-
YamlReader::fill<ddsrouter::core::SpecsConfiguration>(
266-
object.advanced_options,
267-
YamlReader::get_value_in_tag(yml, SPECS_TAG),
268-
version);
293+
object.advanced_options = get<ddsrouter::core::SpecsConfiguration>(YamlReader::get_value_in_tag(yml,
294+
SPECS_TAG),
295+
version);
269296
}
270297

271298
// DDS Pipe Configuration
@@ -286,18 +313,38 @@ void YamlReader::fill(
286313
// Get optional xml configuration
287314
if (YamlReader::is_tag_present(yml, XML_TAG))
288315
{
289-
YamlReader::fill<participants::XmlHandlerConfiguration>(
290-
object.xml_configuration,
291-
YamlReader::get_value_in_tag(yml, XML_TAG),
292-
version);
316+
object.xml_configuration = YamlReader::get<participants::XmlHandlerConfiguration>(yml, XML_TAG, version);
293317
}
294318
}
295319

320+
template <>
321+
DDSPIPE_YAML_DllAPI
322+
bool YamlValidator::validate<ddsrouter::core::DdsRouterConfiguration>(
323+
const Yaml& yml,
324+
const YamlReaderVersion& /* version */)
325+
{
326+
static const std::set<TagType> tags{
327+
VERSION_TAG,
328+
COLLECTION_PARTICIPANTS_TAG,
329+
XML_TAG,
330+
ALLOWLIST_TAG,
331+
BLOCKLIST_TAG,
332+
BUILTIN_TAG,
333+
ROUTES_TAG,
334+
TOPIC_ROUTES_TAG,
335+
TOPICS_TAG,
336+
SPECS_TAG};
337+
338+
return YamlValidator::validate_tags(yml, tags);
339+
}
340+
296341
template <>
297342
ddsrouter::core::DdsRouterConfiguration YamlReader::get<ddsrouter::core::DdsRouterConfiguration>(
298343
const Yaml& yml,
299344
const YamlReaderVersion version)
300345
{
346+
YamlValidator::validate<ddsrouter::core::DdsRouterConfiguration>(yml, version);
347+
301348
ddsrouter::core::DdsRouterConfiguration object;
302349
fill<ddsrouter::core::DdsRouterConfiguration>(object, yml, version);
303350
return object;

0 commit comments

Comments
 (0)