3#include "rpc/common/APIVersion.hpp"
4#include "util/config/Error.hpp"
5#include "util/config/Types.hpp"
6#include "util/log/Logger.hpp"
29static constexpr std::array<std::string_view, 6>
kLogLevels = {
41static constexpr std::array<std::string_view, 5>
kLogTags = {
61static constexpr std::array<std::string_view, 1>
kDatabaseType = {
"cassandra"};
66static constexpr std::array<std::string_view, 2>
kProcessingPolicy = {
"parallel",
"sequent"};
71static constexpr std::array<std::string_view, 2>
kProvider = {
"cassandra",
"aws_keyspace"};
90 if (
auto const maybeError =
checkTypeImpl(val); maybeError.has_value())
106 template <std::
size_t ArrSize>
107 [[nodiscard]]
constexpr std::string
109 std::string_view key,
111 std::array<std::string_view, ArrSize> arr
115 auto const valueStr = std::visit([](
auto const& v) {
return fmt::format(
"{}", v); }, value);
119 R
"(You provided value "{}". Key "{}"'s value must be one of the following: {})",
132 [[nodiscard]]
virtual std::optional<Error>
141 [[nodiscard]]
virtual std::optional<Error>
150 print(std::ostream& stream)
const = 0;
181 [[nodiscard]] std::optional<Error>
182 checkTypeImpl(
Value const& port)
const override;
190 [[nodiscard]] std::optional<Error>
191 checkValueImpl(
Value const& port)
const override;
199 print(std::ostream& stream)
const override
201 stream << fmt::format(
202 "The minimum value is `{}`. The maximum value is `{}`.", kPortMin, kPortMax
206 static constexpr uint32_t kPortMin = 1;
207 static constexpr uint32_t kPortMax = 65535;
224 [[nodiscard]] std::optional<Error>
225 checkTypeImpl(
Value const& ip)
const override;
233 [[nodiscard]] std::optional<Error>
234 checkValueImpl(
Value const& ip)
const override;
242 print(std::ostream& stream)
const override
244 stream <<
"The value must be a valid IP address.";
254template <std::
size_t ArrSize>
264 constexpr OneOf(std::string_view key, std::array<std::string_view, ArrSize> arr)
265 : key_{key}, arr_{arr}
269 constexpr ~OneOf() noexcept override = default;
278 [[nodiscard]] std::optional<
Error>
279 checkTypeImpl(
Value const& val)
const override
281 if (!std::holds_alternative<std::string>(val))
282 return Error{fmt::format(R
"(Key "{}"'s value must be a string)", key_)};
292 [[nodiscard]] std::optional<Error>
293 checkValueImpl(
Value const& val)
const override
295 namespace rg = std::ranges;
296 auto const check = [&val](std::string_view name) {
297 return std::get<std::string>(val) == name;
299 if (rg::any_of(arr_, check))
311 print(std::ostream& stream)
const override
313 std::string valuesStream;
314 std::ranges::for_each(arr_, [&valuesStream](std::string_view elem) {
315 valuesStream += fmt::format(
" `{}`,", elem);
318 valuesStream.back() =
'.';
319 stream << fmt::format(
"The value must be one of the following:{}", valuesStream);
322 std::string_view key_;
323 std::array<std::string_view, ArrSize> arr_;
331template <
typename NumType>
353 [[nodiscard]] std::optional<
Error>
354 checkTypeImpl(
Value const& num)
const override
356 if (!std::holds_alternative<int64_t>(num))
357 return Error{
"Number must be of type integer"};
367 [[nodiscard]] std::optional<Error>
368 checkValueImpl(
Value const& num)
const override
370 auto const numValue = std::get<int64_t>(num);
371 if (numValue >=
static_cast<int64_t
>(min_) && numValue <=
static_cast<int64_t
>(max_))
373 return Error{fmt::format(
"Number must be between {} and {}", min_, max_)};
382 print(std::ostream& stream)
const override
384 stream << fmt::format(
"The minimum value is `{}`. The maximum value is `{}`.", min_, max_);
405 [[nodiscard]] std::optional<Error>
406 checkTypeImpl(
Value const& num)
const override;
414 [[nodiscard]] std::optional<Error>
415 checkValueImpl(
Value const& num)
const override;
423 print(std::ostream& stream)
const override
425 stream <<
"The value must be a positive double number.";
440 [[nodiscard]] std::optional<Error>
441 checkTypeImpl(
Value const& value)
const override;
449 [[nodiscard]] std::optional<Error>
450 checkValueImpl(
Value const& value)
const override;
458 print(std::ostream& stream)
const override
460 stream <<
"Checks whether provided RPC name is valid";
507 std::numeric_limits<uint16_t>::max()
515 std::numeric_limits<uint16_t>::max()
523 std::numeric_limits<uint16_t>::max()
531 std::numeric_limits<uint32_t>::max()
538 std::numeric_limits<uint32_t>::max()
static constexpr std::array< std::string_view, 8 > kChannels
The predefined log channels; loggers for other channels are created dynamically.
Definition Logger.hpp:168
Represents the config values for Json/Yaml config.
Definition ConfigValue.hpp:28
An interface to enforce constraints on certain values within ClioConfigDefinition.
Definition ConfigConstraints.hpp:76
friend std::ostream & operator<<(std::ostream &stream, Constraint const &cons)
Custom output stream for constraint.
Definition ConfigConstraints.hpp:160
virtual void print(std::ostream &stream) const =0
Prints to the output stream for this specific constraint.
virtual std::optional< Error > checkValueImpl(Value const &val) const =0
Check if the value is within the constraint.
constexpr std::string makeErrorMsg(std::string_view key, Value const &value, std::array< std::string_view, ArrSize > arr) const
Creates an error message for all constraints that must satisfy certain hard-coded values.
Definition ConfigConstraints.hpp:108
std::optional< Error > checkConstraint(Value const &val) const
Check if the value meets the specific constraint.
Definition ConfigConstraints.hpp:88
virtual std::optional< Error > checkTypeImpl(Value const &val) const =0
Check if the value is of a correct type for the constraint.
A constraint class to ensure an integer value is between two numbers (inclusive).
Definition ConfigConstraints.hpp:332
constexpr NumberValueConstraint(NumType min, NumType max)
Constructs a constraint where the number must be between min_ and max_.
Definition ConfigConstraints.hpp:340
A constraint class to ensure the provided value is one of the specified values in an array.
Definition ConfigConstraints.hpp:255
constexpr OneOf(std::string_view key, std::array< std::string_view, ArrSize > arr)
Constructs a constraint where the value must be one of the values in the provided array.
Definition ConfigConstraints.hpp:264
A constraint to ensure the port number is within a valid range.
Definition ConfigConstraints.hpp:170
A constraint to ensure a number (int or double) is non-negative.
Definition ConfigConstraints.hpp:394
A constraint to ensure the value is a valid RPC command name.
Definition ConfigConstraints.hpp:432
A constraint to ensure the value is a valid IP address or hostname.
Definition ConfigConstraints.hpp:213
Provides view into ConfigValues that represents values in Clio Config.
Definition ValueView.hpp:27
std::unexpected< CassandraError > Error
A database error.
Definition Types.hpp:67
static constexpr uint32_t kApiVersionMin
Minimum API version supported by this build.
Definition APIVersion.hpp:19
static constexpr uint32_t kApiVersionMax
Maximum API version supported by this build.
Definition APIVersion.hpp:24
Clio configuration: definitions of the supported keys, their types, constraints and defaults,...
Definition HandlerRegistry.hpp:24
static constexpr std::array< std::string_view, 3 > kLoadCacheMode
specific values that are accepted for cache loading in config.
Definition ConfigConstraints.hpp:52
static constinit NumberValueConstraint< uint32_t > gValidateNonNegativeUint32
Validates a non-negative uint32 value (0 is allowed).
Definition ConfigConstraints.hpp:536
static constinit OneOf gValidateLoadMode
Validates the cache load mode.
Definition ConfigConstraints.hpp:482
static constinit RpcNameConstraint gRpcNameConstraint
Validates that a value is a valid RPC command name.
Definition ConfigConstraints.hpp:551
static constinit OneOf gValidateProcessingPolicy
Validates the server request processing policy.
Definition ConfigConstraints.hpp:490
static constinit OneOf gValidateProvider
Validates the Cassandra-compatible database provider.
Definition ConfigConstraints.hpp:494
static constinit NumberValueConstraint< uint16_t > gValidateNumMarkers
Validates the number of markers used for the initial ledger load; must be in [1, 256].
Definition ConfigConstraints.hpp:501
static constinit OneOf gValidateChannelName
Validates a log channel name.
Definition ConfigConstraints.hpp:470
std::variant< int64_t, std::string, bool, double > Value
Represents the supported Config Values.
Definition Types.hpp:38
static constinit PortConstraint gValidatePort
Validates a network port number.
Definition ConfigConstraints.hpp:464
static constinit NumberValueConstraint< uint32_t > gValidateUint32
Validates a positive (non-zero) uint32 value.
Definition ConfigConstraints.hpp:529
static constexpr std::array< std::string_view, 1 > kDatabaseType
specific values that are accepted for database type in config.
Definition ConfigConstraints.hpp:61
static constexpr std::array< std::string_view, 2 > kProcessingPolicy
specific values that are accepted for server's processing_policy in config.
Definition ConfigConstraints.hpp:66
static constinit OneOf gValidateLogLevelName
Validates a log level name.
Definition ConfigConstraints.hpp:474
static constexpr std::array< std::string_view, 2 > kProvider
specific values that are accepted for database provider in config.
Definition ConfigConstraints.hpp:71
static constinit NumberValueConstraint< uint32_t > gValidateApiVersion
Validates an API version; must be within the supported range of API versions.
Definition ConfigConstraints.hpp:543
static constexpr std::array< std::string_view, 6 > kLogLevels
specific values that are accepted for logger levels in config.
Definition ConfigConstraints.hpp:29
static constinit NumberValueConstraint< uint16_t > gValidateReplicationFactor
Validates the database replication factor; 0 is allowed.
Definition ConfigConstraints.hpp:513
static constinit ValidIPConstraint gValidateIp
Validates an IP address or hostname.
Definition ConfigConstraints.hpp:465
static constinit NumberValueConstraint< uint16_t > gValidateUint16
Validates a positive (non-zero) uint16 value.
Definition ConfigConstraints.hpp:521
static constinit PositiveDouble gValidatePositiveDouble
Validates a number is non-negative.
Definition ConfigConstraints.hpp:496
static constinit OneOf gValidateCassandraName
Validates the database type.
Definition ConfigConstraints.hpp:478
static constinit NumberValueConstraint< uint16_t > gValidateNumCursors
Validates a number of cache loading cursors; any uint16 value, including 0.
Definition ConfigConstraints.hpp:505
static constinit OneOf gValidateLogTag
Validates the log tag style.
Definition ConfigConstraints.hpp:486
static constexpr std::array< std::string_view, 5 > kLogTags
specific values that are accepted for logger tag style in config.
Definition ConfigConstraints.hpp:41
Displays the different errors when parsing user config.
Definition Error.hpp:14