Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ConfigurationParser to parse YAML instead of TOML #103

Closed
4 tasks done
Tracked by #241
TomasTurina opened this issue Aug 22, 2024 · 2 comments · Fixed by #266
Closed
4 tasks done
Tracked by #241

Change ConfigurationParser to parse YAML instead of TOML #103

TomasTurina opened this issue Aug 22, 2024 · 2 comments · Fixed by #266
Assignees
Labels
level/task Task issue module/agent mvp Minimum Viable Product refinement type/enhancement Enhancement issue

Comments

@TomasTurina
Copy link
Member

TomasTurina commented Aug 22, 2024

Parent Issue: #241

Description

The current implementation of the ConfigurationParser can parse TOML files, but after some consideration we need to change this and make the parser able to interpret YAML files, as that will be the configuration format across all Wazuh components.

Tasks to be accomplished:

  • Select and use a common and maintained library, mention the advantages and disadvantages of its use.
  • Replace the TOML library with the selected YAML library.
  • Rename the default configuration file to wazuh-agent.yml, which must be installed into /etc/wazuh-agent/wazuh-agent.yml.
  • Adapt and create new UT for the 'ConfigurationParser'.
@Nicogp
Copy link
Member

Nicogp commented Oct 31, 2024

Research of yaml libraries available for C++

The official YAML page lists the following libraries:

YAML Frameworks and Tools:
C/C++:

  • libfyaml # "C" YAML 1.2 processor (YTS)
  • libyaml # "C" Fast YAML 1.1 (YTS)
  • libcyaml # YAML de/serialization of C data (using libyaml)
  • yaml-cpp # C++ YAML 1.2 implementation
    the only one native for C++ is yaml-cpp, the rest are native for C.

If we take cppreference as a source, here it names only yaml-cpp:
image

Comparison of libraries:

While researching, we also found the rapidyaml library that was included for comparison.

YAML-CPP:
https://github.com/jbeder/yaml-cpp

  • Advantages:

    • Supports recent YAML versions. Full support for YAML specification
    • Open source, widely used and supported
    • Easy to install (available in vcpkg).
    • Provides intuitive data access for hierarchical structures.
    • Integrates smoothly into projects using CMake.
  • Disadvantages:

    • Can be heavy for small projects or those with strict performance requirements.

libyaml:
https://pyyaml.org/wiki/LibYAML

  • Advantages:

    • Lightweight and fast.
    • Suitable for projects needing high performance and simple data access.
  • Disadvantages:

    • Less intuitive interface compared to YAML-CPP.
    • More complex API
    • Requires more manual parsing code
    • Less user-friendly for direct use
    • Limited support for advanced YAML features, potentially lacking full YAML specification support.

RapidYAML:
https://github.com/biojppm/rapidyaml

  • Advantages:

    • Excellent performance, ideal for large YAML files.
    • Modern, efficient API.
  • Disadvantages:

    • Relatively young project, so it might lack advanced features or community support compared to YAML-CPP.
    • Fewer features than other libraries
    • Limited support for complex YAML structures.
    • Less intuitive syntax

libfyaml:
https://github.com/pantoniou/libfyaml

  • Advantages:

    • Provides full YAML 1.2 compliance, including advanced YAML features.
    • Very fast and optimized for performance, with a focus on low-level flexibility.
    • Highly modular design, making it adaptable for many types of applications.
  • Disadvantages:

    • Primarily a C library, so using it with C++ may require some wrappers or adaptations for optimal integration.
    • Still a relatively new library, so it might have less documentation and community support compared to more mature libraries.

libcyaml:
https://github.com/tlsa/libcyaml

  • Advantages:

    • Type-safe parsing due to schema definitions, which reduces runtime errors.
    • Lightweight and performs well due to its schema-based approach.
    • Well-suited for projects needing strict type control and reliable error handling.
  • Disadvantages:

    • Limited YAML feature support; works best with simple, well-defined YAML structures.
    • Schemas may be restrictive for more flexible YAML formats and can add setup complexity.

Conclusion

With the analysis of all the libraries, I choose for the moment to use yaml-cpp, because it is native to C++, fully supports the YAML specifications, is OpenSource and is widely used and maintained.

@Nicogp
Copy link
Member

Nicogp commented Nov 2, 2024

Work update

2024/11/01

  • I started to make the changes
  • I changed the toml11 library to yaml-cpp
  • I changed in the configurationParser module to use the new library

2024/11/04

  • Fixed a typo in the configuration parser for FileReader.
  • I have made the changes requested in the reviews
  • PR approved and merged

@wazuhci wazuhci moved this from In progress to Pending review in XDR+SIEM/Release 5.0.0 Nov 4, 2024
@wazuhci wazuhci moved this from Pending review to Done in XDR+SIEM/Release 5.0.0 Nov 4, 2024
@vikman90 vikman90 added this to the MVP Agent refinement (I) milestone Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/task Task issue module/agent mvp Minimum Viable Product refinement type/enhancement Enhancement issue
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants