Skip to content

Commit

Permalink
Validate YAML tags on parsing
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate committed Apr 11, 2024
1 parent db40e71 commit 94c3ff1
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ class DDSRECORDER_YAML_DllAPI RecorderConfiguration
const Yaml& yml,
const ddspipe::yaml::YamlReaderVersion& version);

void load_output_configuration_(
const Yaml& yml,
const ddspipe::yaml::YamlReaderVersion& version);

void load_controller_configuration_(
const Yaml& yml,
const ddspipe::yaml::YamlReaderVersion& version);
Expand Down
9 changes: 9 additions & 0 deletions ddsrecorder_yaml/src/cpp/recorder/YamlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <mcap/mcap.hpp>

#include <ddspipe_yaml/YamlReader.hpp>
#include <ddspipe_yaml/YamlValidator.hpp>

#include <ddsrecorder_yaml/recorder/yaml_configuration_tags.hpp>

Expand All @@ -30,6 +31,14 @@ YamlReader::get<mcap::McapWriterOptions>(
const Yaml& yml,
const YamlReaderVersion version)
{
const std::set<TagType> tags = {
RECORDER_COMPRESSION_SETTINGS_ALGORITHM_TAG,
RECORDER_COMPRESSION_SETTINGS_LEVEL_TAG,
RECORDER_COMPRESSION_SETTINGS_FORCE_TAG,
};

YamlValidator::validate_tags(yml, tags);

mcap::McapWriterOptions mcap_writer_options{"ros2"};

// Parse optional compression algorithm
Expand Down
97 changes: 94 additions & 3 deletions ddsrecorder_yaml/src/cpp/recorder/YamlReaderConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ddspipe_yaml/yaml_configuration_tags.hpp>
#include <ddspipe_yaml/Yaml.hpp>
#include <ddspipe_yaml/YamlManager.hpp>
#include <ddspipe_yaml/YamlValidator.hpp>

#include <ddsrecorder_yaml/recorder/yaml_configuration_tags.hpp>
#include <ddsrecorder_yaml/recorder/YamlReaderConfiguration.hpp>
Expand Down Expand Up @@ -122,6 +123,14 @@ void RecorderConfiguration::load_ddsrecorder_configuration_(
recorder_configuration->app_metadata = "";
recorder_configuration->is_repeater = false;

const std::set<TagType> tags{
RECORDER_RECORDER_TAG,
SPECS_TAG,
RECORDER_DDS_TAG,
RECORDER_REMOTE_CONTROLLER_TAG};

YamlValidator::validate_tags(yml, tags);

/////
// Get optional Recorder configuration options
if (YamlReader::is_tag_present(yml, RECORDER_RECORDER_TAG))
Expand All @@ -136,7 +145,6 @@ void RecorderConfiguration::load_ddsrecorder_configuration_(

/////
// Get optional specs configuration
// WARNING: Parse builtin topics (dds tag) AFTER specs, as some topic-specific default values are set there
if (YamlReader::is_tag_present(yml, SPECS_TAG))
{
auto specs_yml = YamlReader::get_value_in_tag(yml, SPECS_TAG);
Expand All @@ -153,7 +161,7 @@ void RecorderConfiguration::load_ddsrecorder_configuration_(

// Block ROS 2 services (RPC) topics
// RATIONALE:
// At the time of this writting, services in ROS 2 behave in the following manner: a ROS 2 service
// At the time of this writing, services in ROS 2 behave in the following manner: a ROS 2 service
// client awaits to discover a server, and it is then when a request is sent to this (and only this) server,
// from which a response is expected.
// Hence, if these topics are not blocked, the client would wrongly believe DDS-Recorder is a server, thus
Expand Down Expand Up @@ -210,6 +218,18 @@ void RecorderConfiguration::load_recorder_configuration_(
const Yaml& yml,
const YamlReaderVersion& version)
{
const std::set<TagType> tags{
RECORDER_OUTPUT_TAG,
RECORDER_BUFFER_SIZE_TAG,
RECORDER_EVENT_WINDOW_TAG,
RECORDER_LOG_PUBLISH_TIME_TAG,
RECORDER_ONLY_WITH_TYPE_TAG,
RECORDER_COMPRESSION_SETTINGS_TAG,
RECORDER_RECORD_TYPES_TAG,
RECORDER_ROS2_TYPES_TAG};

YamlValidator::validate_tags(yml, tags);

if (YamlReader::is_tag_present(yml, RECORDER_OUTPUT_TAG))
{
auto output_yml = YamlReader::get_value_in_tag(yml, RECORDER_OUTPUT_TAG);
Expand Down Expand Up @@ -337,10 +357,60 @@ void RecorderConfiguration::load_recorder_configuration_(
}
}

void RecorderConfiguration::load_output_configuration_(
const Yaml& yml,
const YamlReaderVersion& version)
{
const std::set<TagType> tags{
RECORDER_OUTPUT_PATH_FILE_TAG,
RECORDER_OUTPUT_FILE_NAME_TAG,
RECORDER_OUTPUT_TIMESTAMP_FORMAT_TAG,
RECORDER_OUTPUT_LOCAL_TIMESTAMP_TAG};

YamlValidator::validate_tags(yml, tags);

/////
// Get optional file path
if (YamlReader::is_tag_present(yml, RECORDER_OUTPUT_PATH_FILE_TAG))
{
output_filepath = YamlReader::get<std::string>(yml, RECORDER_OUTPUT_PATH_FILE_TAG, version);
}

/////
// Get optional file name
if (YamlReader::is_tag_present(yml, RECORDER_OUTPUT_FILE_NAME_TAG))
{
output_filename = YamlReader::get<std::string>(yml, RECORDER_OUTPUT_FILE_NAME_TAG, version);
}

/////
// Get optional timestamp format
if (YamlReader::is_tag_present(yml, RECORDER_OUTPUT_TIMESTAMP_FORMAT_TAG))
{
output_timestamp_format = YamlReader::get<std::string>(yml, RECORDER_OUTPUT_TIMESTAMP_FORMAT_TAG, version);
}

/////
// Get optional timestamp format
if (YamlReader::is_tag_present(yml, RECORDER_OUTPUT_LOCAL_TIMESTAMP_TAG))
{
output_local_timestamp = YamlReader::get<bool>(yml, RECORDER_OUTPUT_LOCAL_TIMESTAMP_TAG, version);
}
}

void RecorderConfiguration::load_controller_configuration_(
const Yaml& yml,
const YamlReaderVersion& version)
{
const std::set<TagType> tags{
RECORDER_REMOTE_CONTROLLER_ENABLE_TAG,
DOMAIN_ID_TAG,
RECORDER_REMOTE_CONTROLLER_INITIAL_STATE_TAG,
RECORDER_REMOTE_CONTROLLER_COMMAND_TOPIC_NAME_TAG,
RECORDER_REMOTE_CONTROLLER_STATUS_TOPIC_NAME_TAG};

YamlValidator::validate_tags(yml, tags);

// Get optional enable remote controller
if (YamlReader::is_tag_present(yml, RECORDER_REMOTE_CONTROLLER_ENABLE_TAG))
{
Expand Down Expand Up @@ -383,6 +453,14 @@ void RecorderConfiguration::load_specs_configuration_(
const Yaml& yml,
const YamlReaderVersion& version)
{
const std::set<TagType> tags{
NUMBER_THREADS_TAG,
SPECS_QOS_TAG,
RECORDER_SPECS_MAX_PENDING_SAMPLES_TAG,
RECORDER_SPECS_CLEANUP_PERIOD_TAG};

YamlValidator::validate_tags(yml, tags);

// Get number of threads
if (YamlReader::is_tag_present(yml, NUMBER_THREADS_TAG))
{
Expand All @@ -393,14 +471,15 @@ void RecorderConfiguration::load_specs_configuration_(
// Get optional Topic QoS
if (YamlReader::is_tag_present(yml, SPECS_QOS_TAG))
{
YamlReader::fill<TopicQoS>(topic_qos, YamlReader::get_value_in_tag(yml, SPECS_QOS_TAG), version);
topic_qos = YamlReader::get<TopicQoS>(yml, SPECS_QOS_TAG, version);
TopicQoS::default_topic_qos.set_value(topic_qos);
}

// Get max pending samples
if (YamlReader::is_tag_present(yml, RECORDER_SPECS_MAX_PENDING_SAMPLES_TAG))
{
max_pending_samples = YamlReader::get<int>(yml, RECORDER_SPECS_MAX_PENDING_SAMPLES_TAG, version);

if (max_pending_samples < -1)
{
throw eprosima::utils::ConfigurationException(
Expand Down Expand Up @@ -434,6 +513,18 @@ void RecorderConfiguration::load_dds_configuration_(
const Yaml& yml,
const YamlReaderVersion& version)
{
const std::set<TagType> tags{
DOMAIN_ID_TAG,
WHITELIST_INTERFACES_TAG,
TRANSPORT_DESCRIPTORS_TRANSPORT_TAG,
IGNORE_PARTICIPANT_FLAGS_TAG,
ALLOWLIST_TAG,
BLOCKLIST_TAG,
TOPICS_TAG,
BUILTIN_TAG};

YamlValidator::validate_tags(yml, tags);

// Get optional DDS domain
if (YamlReader::is_tag_present(yml, DOMAIN_ID_TAG))
{
Expand Down

0 comments on commit 94c3ff1

Please sign in to comment.