ORE Studio 0.0.4
Loading...
Searching...
No Matches
system_flags.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_VARIABILITY_DOMAIN_SYSTEM_FLAGS_HPP
21#define ORES_VARIABILITY_DOMAIN_SYSTEM_FLAGS_HPP
22
23#include <array>
24#include <string>
25#include <ostream>
26#include <optional>
27#include <stdexcept>
28#include <string_view>
29#include <magic_enum/magic_enum.hpp>
30
32
83
88 system_flag flag;
89 bool default_enabled;
90 std::string_view description;
91};
92
100inline constexpr std::array system_flag_definitions = {
103 .default_enabled = true,
104 .description = "Indicates whether the system is in bootstrap mode "
105 "(waiting for initial admin account)."
106 },
109 .default_enabled = false,
110 .description = "Controls whether user self-registration is allowed."
111 },
114 .default_enabled = false,
115 .description = "Controls whether new signups require admin authorization. "
116 "NOT YET IMPLEMENTED - enabling will cause signup to fail."
117 },
120 .default_enabled = false,
121 .description = "When enabled, disables strict password validation. "
122 "FOR TESTING/DEVELOPMENT ONLY."
123 }
124};
125
135[[nodiscard]] inline std::string to_flag_name(system_flag flag) {
136 return std::string("system.") + std::string(magic_enum::enum_name(flag));
137}
138
145[[nodiscard]] inline std::optional<system_flag> from_flag_name(std::string_view name) {
146 constexpr std::string_view prefix = "system.";
147 if (!name.starts_with(prefix)) {
148 return std::nullopt;
149 }
150
151 auto enum_name = name.substr(prefix.size());
152 return magic_enum::enum_cast<system_flag>(enum_name);
153}
154
161[[nodiscard]] inline const system_flag_definition&
163 for (const auto& def : system_flag_definitions) {
164 if (def.flag == flag)
165 return def;
166 }
167 // This should never happen for valid enum values.
168 throw std::logic_error("Definition for system_flag not found.");
169}
170
176inline std::ostream& operator<<(std::ostream& os, system_flag flag) {
177 return os << to_flag_name(flag);
178}
179
180}
181
182#endif
Domain types for system variability.
Definition feature_flags.hpp:26
std::ostream & operator<<(std::ostream &s, const feature_flags &v)
Dumps the feature flags object to a stream in JSON format.
Definition feature_flags_json_io.cpp:29
const system_flag_definition & get_definition(system_flag flag)
Gets the definition for a system flag.
Definition system_flags.hpp:162
std::optional< system_flag > from_flag_name(std::string_view name)
Attempts to parse a database flag name to a system_flag enum.
Definition system_flags.hpp:145
constexpr std::array system_flag_definitions
Compile-time manifest of all system flags with their defaults.
Definition system_flags.hpp:100
system_flag
Enumeration of well-known system flags.
Definition system_flags.hpp:44
@ bootstrap_mode
Indicates whether the system is in bootstrap mode.
@ disable_password_validation
Controls whether password policy validation is disabled.
@ user_signups
Controls whether user self-registration is allowed.
@ signup_requires_authorization
Controls whether new signups require admin authorization.
std::string to_flag_name(system_flag flag)
Converts a system_flag enum value to its database name.
Definition system_flags.hpp:135
Metadata for a system flag including its default state and description.
Definition system_flags.hpp:87