Skip to content

Commit

Permalink
config: Conversion functions for fips_mode_flag
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Boquard <michael@redpanda.com>
  • Loading branch information
michael-redpanda committed Jun 4, 2024
1 parent 822216a commit cfbb182
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/v/config/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,34 @@ struct convert<model::recovery_validation_mode> {
}
};

template<>
struct convert<config::fips_mode_flag> {
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<std::string>();
if (
std::find(acceptable_values.begin(), acceptable_values.end(), value)
== acceptable_values.end()) {
return false;
}

rhs = string_switch<type>(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
2 changes: 2 additions & 0 deletions src/v/config/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ consteval std::string_view property_type_name() {
} else if constexpr (std::
is_same_v<type, model::recovery_validation_mode>) {
return "recovery_validation_mode";
} else if constexpr (std::is_same_v<type, config::fips_mode_flag>) {
return "string";
} else {
static_assert(
base::unsupported_type<T>::value, "Type name not defined");
Expand Down
7 changes: 7 additions & 0 deletions src/v/config/rjson_serialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "config/rjson_serialization.h"

#include "config/types.h"

namespace json {

void rjson_serialize(
Expand Down Expand Up @@ -210,4 +212,9 @@ void rjson_serialize(
w.EndObject();
}

void rjson_serialize(
json::Writer<json::StringBuffer>& w, const config::fips_mode_flag& f) {
stringize(w, f);
}

} // namespace json
5 changes: 5 additions & 0 deletions src/v/config/rjson_serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -114,4 +115,8 @@ void rjson_serialize(

void rjson_serialize(
json::Writer<json::StringBuffer>&, const model::recovery_validation_mode&);

void rjson_serialize(
json::Writer<json::StringBuffer>&, const config::fips_mode_flag& f);

} // namespace json

0 comments on commit cfbb182

Please sign in to comment.