From cfbb18292c83546ea2007bcb3b88cce718a293a7 Mon Sep 17 00:00:00 2001 From: Michael Boquard Date: Mon, 3 Jun 2024 21:50:28 -0400 Subject: [PATCH] config: Conversion functions for fips_mode_flag Signed-off-by: Michael Boquard --- src/v/config/convert.h | 30 +++++++++++++++++++++++++++++ src/v/config/property.h | 2 ++ src/v/config/rjson_serialization.cc | 7 +++++++ src/v/config/rjson_serialization.h | 5 +++++ 4 files changed, 44 insertions(+) diff --git a/src/v/config/convert.h b/src/v/config/convert.h index 291ae54d78a4b..460ffc63291f5 100644 --- a/src/v/config/convert.h +++ b/src/v/config/convert.h @@ -574,4 +574,34 @@ struct convert { } }; +template<> +struct convert { + using type = config::fips_mode_flag; + + static constexpr auto acceptable_values = std::to_array( + {to_string_view(type::disabled), + to_string_view(type::enabled), + to_string_view(type::permissive)}); + + static Node encode(const type& rhs) { + Node node; + return node = fmt::format("{}", rhs); + } + static bool decode(const Node& node, type& rhs) { + auto value = node.as(); + if ( + std::find(acceptable_values.begin(), acceptable_values.end(), value) + == acceptable_values.end()) { + return false; + } + + rhs = string_switch(std::string_view{value}) + .match(to_string_view(type::disabled), type::disabled) + .match(to_string_view(type::enabled), type::enabled) + .match(to_string_view(type::permissive), type::disabled); + + return true; + } +}; + } // namespace YAML diff --git a/src/v/config/property.h b/src/v/config/property.h index 25ea581b4e5f8..46c999f0b9f95 100644 --- a/src/v/config/property.h +++ b/src/v/config/property.h @@ -651,6 +651,8 @@ consteval std::string_view property_type_name() { } else if constexpr (std:: is_same_v) { return "recovery_validation_mode"; + } else if constexpr (std::is_same_v) { + return "string"; } else { static_assert( base::unsupported_type::value, "Type name not defined"); diff --git a/src/v/config/rjson_serialization.cc b/src/v/config/rjson_serialization.cc index 537503c2b91e0..c005d3220f157 100644 --- a/src/v/config/rjson_serialization.cc +++ b/src/v/config/rjson_serialization.cc @@ -9,6 +9,8 @@ #include "config/rjson_serialization.h" +#include "config/types.h" + namespace json { void rjson_serialize( @@ -210,4 +212,9 @@ void rjson_serialize( w.EndObject(); } +void rjson_serialize( + json::Writer& w, const config::fips_mode_flag& f) { + stringize(w, f); +} + } // namespace json diff --git a/src/v/config/rjson_serialization.h b/src/v/config/rjson_serialization.h index 46ed6a2c7d612..d500e43b52924 100644 --- a/src/v/config/rjson_serialization.h +++ b/src/v/config/rjson_serialization.h @@ -16,6 +16,7 @@ #include "config/endpoint_tls_config.h" #include "config/seed_server.h" #include "config/tls_config.h" +#include "config/types.h" #include "json/json.h" #include "json/stringbuffer.h" #include "json/writer.h" @@ -114,4 +115,8 @@ void rjson_serialize( void rjson_serialize( json::Writer&, const model::recovery_validation_mode&); + +void rjson_serialize( + json::Writer&, const config::fips_mode_flag& f); + } // namespace json