diff options
author | Ed Tanous <ed@tanous.net> | 2024-04-18 01:40:31 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-05-01 18:14:17 +0300 |
commit | 25b54dba775b31021a3a4677eb79e9771bcb97f7 (patch) | |
tree | fcf84de17508887775cc14a9c15ad4a41d72b049 /redfish-core/lib/account_service.hpp | |
parent | aca174983be5a0d2af08044dd93487908ae6cfe5 (diff) | |
download | bmcweb-25b54dba775b31021a3a4677eb79e9771bcb97f7.tar.xz |
Bring consistency to config options
The configuration options that exist in bmcweb are an amalgimation of
CROW options, CMAKE options using #define, pre-bmcweb ifdef mechanisms
and meson options using a config file. This history has led to a lot of
different ways to configure code in the codebase itself, which has led
to problems, and issues in consistency.
ifdef options do no compile time checking of code not within the branch.
This is good when you have optional dependencies, but not great when
you're trying to ensure both options compile.
This commit moves all internal configuration options to:
1. A namespace called bmcweb
2. A naming scheme matching the meson option. hyphens are replaced with
underscores, and the option is uppercased. This consistent transform
allows matching up option keys with their code counterparts, without
naming changes.
3. All options are bool true = enabled, and any options with _ENABLED or
_DISABLED postfixes have those postfixes removed. (note, there are
still some options with disable in the name, those are left as-is)
4. All options are now constexpr booleans, without an explicit compare.
To accomplish this, unfortunately an option list in config/meson.build
is required, given that meson doesn't provide a way to dump all options,
as is a manual entry in bmcweb_config.h.in, in addition to the
meson_options. This obsoletes the map in the main meson.build, which
helps some of the complexity.
Now that we've done this, we have some rules that will be documented.
1. Runtime behavior changes should be added as a constexpr bool to
bmcweb_config.h
2. Options that require optionally pulling in a dependency shall use an
ifdef, defined in the primary meson.build. (note, there are no
options that currently meet this class, but it's included for
completeness.)
Note, that this consolidation means that at configure time, all options
are printed. This is a good thing and allows direct comparison of
configs in log files.
Tested: Code compiles
Server boots, and shows options configured in the default build. (HTTPS,
log level, etc)
Change-Id: I94e79a56bcdc01755036e4e7278c7e69e25809ce
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'redfish-core/lib/account_service.hpp')
-rw-r--r-- | redfish-core/lib/account_service.hpp | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index aab116e6b1..972512b145 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -829,56 +829,62 @@ inline void if (auth.basicAuth) { -#ifndef BMCWEB_ENABLE_BASIC_AUTHENTICATION - messages::actionNotSupported( - asyncResp->res, - "Setting BasicAuth when basic-auth feature is disabled"); - return; -#endif + if constexpr (!BMCWEB_BASIC_AUTH) + { + messages::actionNotSupported( + asyncResp->res, + "Setting BasicAuth when basic-auth feature is disabled"); + return; + } + authMethodsConfig.basic = *auth.basicAuth; } if (auth.cookie) { -#ifndef BMCWEB_ENABLE_COOKIE_AUTHENTICATION - messages::actionNotSupported( - asyncResp->res, - "Setting Cookie when cookie-auth feature is disabled"); - return; -#endif + if constexpr (!BMCWEB_COOKIE_AUTH) + { + messages::actionNotSupported( + asyncResp->res, + "Setting Cookie when cookie-auth feature is disabled"); + return; + } authMethodsConfig.cookie = *auth.cookie; } if (auth.sessionToken) { -#ifndef BMCWEB_ENABLE_SESSION_AUTHENTICATION - messages::actionNotSupported( - asyncResp->res, - "Setting SessionToken when session-auth feature is disabled"); - return; -#endif + if constexpr (!BMCWEB_SESSION_AUTH) + { + messages::actionNotSupported( + asyncResp->res, + "Setting SessionToken when session-auth feature is disabled"); + return; + } authMethodsConfig.sessionToken = *auth.sessionToken; } if (auth.xToken) { -#ifndef BMCWEB_ENABLE_XTOKEN_AUTHENTICATION - messages::actionNotSupported( - asyncResp->res, - "Setting XToken when xtoken-auth feature is disabled"); - return; -#endif + if constexpr (!BMCWEB_XTOKEN_AUTH) + { + messages::actionNotSupported( + asyncResp->res, + "Setting XToken when xtoken-auth feature is disabled"); + return; + } authMethodsConfig.xtoken = *auth.xToken; } if (auth.tls) { -#ifndef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION - messages::actionNotSupported( - asyncResp->res, - "Setting TLS when mutual-tls-auth feature is disabled"); - return; -#endif + if constexpr (!BMCWEB_MUTUAL_TLS_AUTH) + { + messages::actionNotSupported( + asyncResp->res, + "Setting TLS when mutual-tls-auth feature is disabled"); + return; + } authMethodsConfig.tls = *auth.tls; } @@ -1705,11 +1711,13 @@ inline void boost::beast::http::field::link, "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby"); -#ifdef BMCWEB_INSECURE_DISABLE_AUTHENTICATION - // If authentication is disabled, there are no user accounts - messages::resourceNotFound(asyncResp->res, "ManagerAccount", accountName); - return; -#endif // BMCWEB_INSECURE_DISABLE_AUTHENTICATION + if constexpr (BMCWEB_INSECURE_DISABLE_AUTH) + { + // If authentication is disabled, there are no user accounts + messages::resourceNotFound(asyncResp->res, "ManagerAccount", + accountName); + return; + } if (req.session == nullptr) { @@ -1882,12 +1890,12 @@ inline void return; } -#ifdef BMCWEB_INSECURE_DISABLE_AUTHENTICATION - // If authentication is disabled, there are no user accounts - messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); - return; - -#endif // BMCWEB_INSECURE_DISABLE_AUTHENTICATION + if constexpr (BMCWEB_INSECURE_DISABLE_AUTH) + { + // If authentication is disabled, there are no user accounts + messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); + return; + } sdbusplus::message::object_path tempObjPath(rootUserDbusPath); tempObjPath /= username; const std::string userPath(tempObjPath); @@ -1916,12 +1924,12 @@ inline void { return; } -#ifdef BMCWEB_INSECURE_DISABLE_AUTHENTICATION - // If authentication is disabled, there are no user accounts - messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); - return; - -#endif // BMCWEB_INSECURE_DISABLE_AUTHENTICATION + if constexpr (BMCWEB_INSECURE_DISABLE_AUTH) + { + // If authentication is disabled, there are no user accounts + messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); + return; + } std::optional<std::string> newUserName; std::optional<std::string> password; std::optional<bool> enabled; |