diff options
35 files changed, 646 insertions, 640 deletions
diff --git a/config/bmcweb_config.h.in b/config/bmcweb_config.h.in index eb0c79c77a..81a61c8b17 100644 --- a/config/bmcweb_config.h.in +++ b/config/bmcweb_config.h.in @@ -1,29 +1,57 @@ #pragma once #include <cstdint> -#include <cstddef> #include <string_view> // clang-format off -constexpr const bool bmcwebInsecureEnableQueryParams = @BMCWEB_INSECURE_ENABLE_QUERY_PARAMS@ == 1; - -constexpr const size_t bmcwebHttpReqBodyLimitMb = @BMCWEB_HTTP_REQ_BODY_LIMIT_MB@; - -constexpr const char* mesonInstallPrefix = "@MESON_INSTALL_PREFIX@"; - -constexpr const bool bmcwebInsecureEnableHttpPushStyleEventing = @BMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING@ == 1; - -constexpr const char* bmcwebLoggingLevel = "@BMCWEB_LOGGING_LEVEL@"; - -constexpr const bool bmcwebEnableMultiHost = @BMCWEB_ENABLE_MULTI_HOST@ == 1; - -constexpr const bool bmcwebEnableHTTP2 = @BMCWEB_ENABLE_HTTP2@ == 1; - -constexpr const bool bmcwebEnableTLS = @BMCWEB_ENABLE_TLS@ == 1; - -constexpr const bool bmcwebMTLSCommonNameParsingMeta = @BMCWEB_ENABLE_MTLS_COMMON_NAME_PARSING_META@ == 1; - -constexpr const bool bmcwebNbdProxy = @BMCWEB_VIRTUAL_MEDIA_NBD@ == 1; - -constexpr const bool bmcwebVmWebsocket = @BMCWEB_VIRTUAL_MEDIA_VM@ == 1; +// NOLINTBEGIN(readability-identifier-naming) + +// String params +constexpr const std::string_view BMCWEB_LOGGING_LEVEL = "@LOGGING_LEVEL@"; +constexpr const std::string_view BMCWEB_MUTUAL_TLS_COMMON_NAME_PARSING = "@MUTUAL_TLS_COMMON_NAME_PARSING@"; +constexpr const std::string_view BMCWEB_DNS_RESOLVER = "@DNS_RESOLVER@"; + +// Integer params +constexpr const uint64_t BMCWEB_HTTP_BODY_LIMIT = @HTTP_BODY_LIMIT@; +constexpr const uint16_t BMCWEB_HTTPS_PORT = @HTTPS_PORT@; + +// Feature Params +constexpr const bool BMCWEB_BASIC_AUTH = @BASIC_AUTH@; +constexpr const bool BMCWEB_COOKIE_AUTH = @COOKIE_AUTH@; +constexpr const bool BMCWEB_EXPERIMENTAL_HTTP2 = @EXPERIMENTAL_HTTP2@; +constexpr const bool BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM = @EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM@; +constexpr const bool BMCWEB_HOST_SERIAL_SOCKET = @HOST_SERIAL_SOCKET@; +constexpr const bool BMCWEB_INSECURE_DISABLE_AUTH = @INSECURE_DISABLE_AUTH@; +constexpr const bool BMCWEB_INSECURE_DISABLE_CSRF = @INSECURE_DISABLE_CSRF@; +constexpr const bool BMCWEB_INSECURE_DISABLE_SSL = @INSECURE_DISABLE_SSL@; +constexpr const bool BMCWEB_INSECURE_ENABLE_REDFISH_QUERY = @INSECURE_ENABLE_REDFISH_QUERY@; +constexpr const bool BMCWEB_INSECURE_IGNORE_CONTENT_TYPE = @INSECURE_IGNORE_CONTENT_TYPE@; +constexpr const bool BMCWEB_INSECURE_PUSH_STYLE_NOTIFICATION = @INSECURE_PUSH_STYLE_NOTIFICATION@; +constexpr const bool BMCWEB_INSECURE_TFTP_UPDATE = @INSECURE_TFTP_UPDATE@; +constexpr const bool BMCWEB_KVM = @KVM@; +constexpr const bool BMCWEB_MUTUAL_TLS_AUTH = @MUTUAL_TLS_AUTH@; +constexpr const bool BMCWEB_REDFISH_AGGREGATION = @REDFISH_AGGREGATION@; +constexpr const bool BMCWEB_REDFISH_ALLOW_DEPRECATED_POWER_THERMAL = @REDFISH_ALLOW_DEPRECATED_POWER_THERMAL@; +constexpr const bool BMCWEB_REDFISH_BMC_JOURNAL = @REDFISH_BMC_JOURNAL@; +constexpr const bool BMCWEB_REDFISH_CPU_LOG = @REDFISH_CPU_LOG@; +constexpr const bool BMCWEB_REDFISH_DBUS_LOG = @REDFISH_DBUS_LOG@; +constexpr const bool BMCWEB_REDFISH_DUMP_LOG = @REDFISH_DUMP_LOG@; +constexpr const bool BMCWEB_REDFISH_HOST_LOGGER = @REDFISH_HOST_LOGGER@; +constexpr const bool BMCWEB_REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM = @REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM@; +constexpr const bool BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA = @REDFISH_OEM_MANAGER_FAN_DATA@; +constexpr const bool BMCWEB_REDFISH_PROVISIONING_FEATURE = @REDFISH_PROVISIONING_FEATURE@; +constexpr const bool BMCWEB_REDFISH = @REDFISH@; +constexpr const bool BMCWEB_REST = @REST@; +constexpr const bool BMCWEB_SESSION_AUTH = @SESSION_AUTH@; +constexpr const bool BMCWEB_STATIC_HOSTING = @STATIC_HOSTING@; +constexpr const bool BMCWEB_TESTS = @TESTS@; +constexpr const bool BMCWEB_VM_WEBSOCKET = @VM_WEBSOCKET@; +constexpr const bool BMCWEB_VM_NBDPROXY = false; +constexpr const bool BMCWEB_XTOKEN_AUTH = @XTOKEN_AUTH@; + +// Company specific params +constexpr const bool BMCWEB_GOOGLE_API = @GOOGLE_API@; +constexpr const bool BMCWEB_IBM_MANAGEMENT_CONSOLE = @IBM_MANAGEMENT_CONSOLE@; + +// NOLINTEND(readability-identifier-naming) // clang-format on diff --git a/config/meson.build b/config/meson.build index 9533bd6b46..4b862b49eb 100644 --- a/config/meson.build +++ b/config/meson.build @@ -1,30 +1,74 @@ # Gather the Configuration data conf_data = configuration_data() -conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit')) -enable_redfish_query = get_option('insecure-enable-redfish-query') -conf_data.set10('BMCWEB_INSECURE_ENABLE_QUERY_PARAMS', enable_redfish_query.allowed()) -# enable_redfish_aggregation = get_option('redfish-aggregation') -# conf_data.set10('BMCWEB_ENABLE_REDFISH_AGGREGATION', enable_redfish_aggregation.allowed()) -insecure_push_style_notification = get_option('insecure-push-style-notification') -conf_data.set10( - 'BMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING', - insecure_push_style_notification.allowed(), -) -conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix')) -conf_data.set('HTTPS_PORT', get_option('https_port')) -enable_multi_host = get_option('experimental-redfish-multi-computer-system') -conf_data.set10('BMCWEB_ENABLE_MULTI_HOST', enable_multi_host.allowed()) -enable_http2 = get_option('experimental-http2') -conf_data.set10('BMCWEB_ENABLE_HTTP2', enable_http2.allowed()) -enable_tls = get_option('insecure-disable-ssl') -conf_data.set10('BMCWEB_ENABLE_TLS', enable_tls.disabled()) +feature_options = [ + 'basic-auth', + 'cookie-auth', + 'dns-resolver', + 'experimental-http2', + 'experimental-redfish-multi-computer-system', + 'google-api', + 'host-serial-socket', + 'http-body-limit', + 'https_port', + 'ibm-management-console', + 'insecure-disable-auth', + 'insecure-disable-csrf', + 'insecure-disable-ssl', + 'insecure-enable-redfish-query', + 'insecure-ignore-content-type', + 'insecure-push-style-notification', + 'insecure-tftp-update', + 'kvm', + 'mutual-tls-auth', + 'mutual-tls-common-name-parsing', + 'redfish-aggregation', + 'redfish-allow-deprecated-power-thermal', + 'redfish-bmc-journal', + 'redfish-cpu-log', + 'redfish-dbus-log', + 'redfish-dump-log', + 'redfish-host-logger', + 'redfish-new-powersubsystem-thermalsubsystem', + 'redfish-oem-manager-fan-data', + 'redfish-provisioning-feature', + 'redfish', + 'rest', + 'session-auth', + 'static-hosting', + 'tests', + 'vm-websocket', + 'xtoken-auth', +] -conf_data.set10( - 'BMCWEB_ENABLE_MTLS_COMMON_NAME_PARSING_META', - get_option('mutual-tls-common-name-parsing') == 'meta', -) +string_options = [ + 'dns-resolver', + 'mutual-tls-common-name-parsing', +] + +int_options = [ + 'http-body-limit', + 'https_port', +] + +foreach option_key : feature_options + + option_key_config = option_key.to_upper() + option_key_config = option_key_config.replace('-', '_') + + message(option_key_config) + opt = get_option(option_key) + if string_options.contains(option_key) + elif int_options.contains(option_key) + else + opt = opt.allowed().to_string() + endif + conf_data.set(option_key_config, opt) + summary(option_key, opt, section: 'Features') +endforeach + +conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix')) conf_data.set10('BMCWEB_VIRTUAL_MEDIA_VM', get_option('vm-websocket').allowed()) conf_data.set10('BMCWEB_VIRTUAL_MEDIA_NBD', false) @@ -32,11 +76,11 @@ conf_data.set10('BMCWEB_VIRTUAL_MEDIA_NBD', false) # Logging level loglvlopt = get_option('bmcweb-logging') if get_option('buildtype').startswith('debug') and loglvlopt == 'disabled' - # Override logging level as 'debug' if 'bmcweb-logging' is set as 'dsiabled' + # Override logging level as 'debug' if 'bmcweb-logging' is set as 'disabled' loglvlopt = 'debug' endif loglvlopt = loglvlopt.to_upper() -conf_data.set('BMCWEB_LOGGING_LEVEL', loglvlopt) +conf_data.set('LOGGING_LEVEL', loglvlopt) conf_h_dep = declare_dependency( include_directories: include_directories('.'), diff --git a/http/app.hpp b/http/app.hpp index 01ad7558ad..eea13058e1 100644 --- a/http/app.hpp +++ b/http/app.hpp @@ -35,8 +35,8 @@ class App using ssl_socket_t = boost::asio::ssl::stream<boost::asio::ip::tcp::socket>; using raw_socket_t = boost::asio::ip::tcp::socket; - using socket_type = - std::conditional_t<bmcwebEnableTLS, ssl_socket_t, raw_socket_t>; + using socket_type = std::conditional_t<BMCWEB_INSECURE_DISABLE_SSL, + raw_socket_t, ssl_socket_t>; using server_type = Server<App, socket_type>; explicit App(std::shared_ptr<boost::asio::io_context> ioIn = diff --git a/http/http_client.hpp b/http/http_client.hpp index 860a7d45a8..ac231b42e7 100644 --- a/http/http_client.hpp +++ b/http/http_client.hpp @@ -149,11 +149,9 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo> boost::asio::io_context& ioc; -#ifdef BMCWEB_DBUS_DNS_RESOLVER - using Resolver = async_resolve::Resolver; -#else - using Resolver = boost::asio::ip::tcp::resolver; -#endif + using Resolver = std::conditional_t<BMCWEB_DNS_RESOLVER == "systemd-dbus", + async_resolve::Resolver, + boost::asio::ip::tcp::resolver>; Resolver resolver; boost::asio::ip::tcp::socket conn; diff --git a/http/http_connection.hpp b/http/http_connection.hpp index d0aa5d5be4..e02c518ebb 100644 --- a/http/http_connection.hpp +++ b/http/http_connection.hpp @@ -38,9 +38,8 @@ namespace crow // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static int connectionCount = 0; -// request body limit size set by the bmcwebHttpReqBodyLimitMb option -constexpr uint64_t httpReqBodyLimit = 1024UL * 1024UL * - bmcwebHttpReqBodyLimitMb; +// request body limit size set by the BMCWEB_HTTP_BODY_LIMIT option +constexpr uint64_t httpReqBodyLimit = 1024UL * 1024UL * BMCWEB_HTTP_BODY_LIMIT; constexpr uint64_t loggedOutPostBodyLimit = 4096U; @@ -70,9 +69,10 @@ class Connection : { initParser(); -#ifdef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION - prepareMutualTls(); -#endif // BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION + if constexpr (BMCWEB_MUTUAL_TLS_AUTH) + { + prepareMutualTls(); + } connectionCount++; @@ -187,7 +187,7 @@ class Connection : void afterSslHandshake() { // If http2 is enabled, negotiate the protocol - if constexpr (bmcwebEnableHTTP2) + if constexpr (BMCWEB_EXPERIMENTAL_HTTP2) { const unsigned char* alpn = nullptr; unsigned int alpnlen = 0; diff --git a/http/http_server.hpp b/http/http_server.hpp index a3708944b7..206a0d175e 100644 --- a/http/http_server.hpp +++ b/http/http_server.hpp @@ -74,7 +74,7 @@ class Server void loadCertificate() { - if constexpr (!bmcwebEnableTLS) + if constexpr (BMCWEB_INSECURE_DISABLE_SSL) { return; } diff --git a/http/logging.hpp b/http/logging.hpp index 9b1a36b143..cf908771bb 100644 --- a/http/logging.hpp +++ b/http/logging.hpp @@ -54,7 +54,7 @@ constexpr crow::LogLevel getLogLevelFromName(std::string_view name) // configured bmcweb LogLevel constexpr crow::LogLevel bmcwebCurrentLoggingLevel = - getLogLevelFromName(bmcwebLoggingLevel); + getLogLevelFromName(BMCWEB_LOGGING_LEVEL); template <typename T> const void* logPtr(T p) diff --git a/http/mutual_tls.hpp b/http/mutual_tls.hpp index 9f9f82b297..5392549b16 100644 --- a/http/mutual_tls.hpp +++ b/http/mutual_tls.hpp @@ -94,7 +94,7 @@ inline std::shared_ptr<persistent_data::UserSession> sslUser.resize(lastChar); // Meta Inc. CommonName parsing - if (bmcwebMTLSCommonNameParsingMeta) + if constexpr (BMCWEB_MUTUAL_TLS_COMMON_NAME_PARSING == "meta") { std::optional<std::string_view> sslUserMeta = mtlsMetaParseSslUser(sslUser); diff --git a/http/utility.hpp b/http/utility.hpp index 1d6750098f..da174e538f 100644 --- a/http/utility.hpp +++ b/http/utility.hpp @@ -497,7 +497,7 @@ inline void setProtocolDefaults(boost::urls::url& url, } if (url.port_number() == 80) { - if (bmcwebInsecureEnableHttpPushStyleEventing) + if constexpr (BMCWEB_INSECURE_PUSH_STYLE_NOTIFICATION) { url.set_scheme("http"); } diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp index 798c3e8964..2d9899d1a4 100644 --- a/include/async_resolve.hpp +++ b/include/async_resolve.hpp @@ -1,5 +1,4 @@ #pragma once -#ifdef BMCWEB_DBUS_DNS_RESOLVER #include "dbus_singleton.hpp" #include "logging.hpp" @@ -124,4 +123,3 @@ class Resolver }; } // namespace async_resolve -#endif diff --git a/include/authentication.hpp b/include/authentication.hpp index ad9759bf49..6483365bef 100644 --- a/include/authentication.hpp +++ b/include/authentication.hpp @@ -32,8 +32,7 @@ inline void cleanupTempSession(const Request& req) } } -#ifdef BMCWEB_ENABLE_BASIC_AUTHENTICATION -static std::shared_ptr<persistent_data::UserSession> +inline std::shared_ptr<persistent_data::UserSession> performBasicAuth(const boost::asio::ip::address& clientIp, std::string_view authHeader) { @@ -86,10 +85,8 @@ static std::shared_ptr<persistent_data::UserSession> user, clientIp, std::nullopt, persistent_data::PersistenceType::SINGLE_REQUEST, isConfigureSelfOnly); } -#endif -#ifdef BMCWEB_ENABLE_SESSION_AUTHENTICATION -static std::shared_ptr<persistent_data::UserSession> +inline std::shared_ptr<persistent_data::UserSession> performTokenAuth(std::string_view authHeader) { BMCWEB_LOG_DEBUG("[AuthMiddleware] Token authentication"); @@ -102,10 +99,8 @@ static std::shared_ptr<persistent_data::UserSession> persistent_data::SessionStore::getInstance().loginSessionByToken(token); return sessionOut; } -#endif -#ifdef BMCWEB_ENABLE_XTOKEN_AUTHENTICATION -static std::shared_ptr<persistent_data::UserSession> +inline std::shared_ptr<persistent_data::UserSession> performXtokenAuth(const boost::beast::http::header<true>& reqHeader) { BMCWEB_LOG_DEBUG("[AuthMiddleware] X-Auth-Token authentication"); @@ -119,10 +114,8 @@ static std::shared_ptr<persistent_data::UserSession> persistent_data::SessionStore::getInstance().loginSessionByToken(token); return sessionOut; } -#endif -#ifdef BMCWEB_ENABLE_COOKIE_AUTHENTICATION -static std::shared_ptr<persistent_data::UserSession> +inline std::shared_ptr<persistent_data::UserSession> performCookieAuth(boost::beast::http::verb method [[maybe_unused]], const boost::beast::http::header<true>& reqHeader) { @@ -159,37 +152,36 @@ static std::shared_ptr<persistent_data::UserSession> return nullptr; } sessionOut->cookieAuth = true; -#ifndef BMCWEB_INSECURE_DISABLE_CSRF_PREVENTION - // RFC7231 defines methods that need csrf protection - if (method != boost::beast::http::verb::get) + + if constexpr (BMCWEB_INSECURE_DISABLE_CSRF) { - std::string_view csrf = reqHeader["X-XSRF-TOKEN"]; - // Make sure both tokens are filled - if (csrf.empty() || sessionOut->csrfToken.empty()) + // RFC7231 defines methods that need csrf protection + if (method != boost::beast::http::verb::get) { - return nullptr; - } + std::string_view csrf = reqHeader["X-XSRF-TOKEN"]; + // Make sure both tokens are filled + if (csrf.empty() || sessionOut->csrfToken.empty()) + { + return nullptr; + } - if (csrf.size() != persistent_data::sessionTokenSize) - { - return nullptr; - } - // Reject if csrf token not available - if (!crow::utility::constantTimeStringCompare( - csrf, sessionOut->csrfToken)) - { - return nullptr; + if (csrf.size() != persistent_data::sessionTokenSize) + { + return nullptr; + } + // Reject if csrf token not available + if (!crow::utility::constantTimeStringCompare( + csrf, sessionOut->csrfToken)) + { + return nullptr; + } } } -#endif - return sessionOut; } return nullptr; } -#endif -#ifdef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION -static std::shared_ptr<persistent_data::UserSession> +inline std::shared_ptr<persistent_data::UserSession> performTLSAuth(Response& res, const boost::beast::http::header<true>& reqHeader, const std::weak_ptr<persistent_data::UserSession>& session) @@ -219,11 +211,9 @@ static std::shared_ptr<persistent_data::UserSession> } return nullptr; } -#endif // checks if request can be forwarded without authentication -[[maybe_unused]] static bool isOnAllowlist(std::string_view url, - boost::beast::http::verb method) +inline bool isOnAllowlist(std::string_view url, boost::beast::http::verb method) { if (boost::beast::http::verb::get == method) { @@ -257,51 +247,54 @@ static std::shared_ptr<persistent_data::UserSession> return false; } -[[maybe_unused]] static std::shared_ptr<persistent_data::UserSession> - authenticate( - const boost::asio::ip::address& ipAddress [[maybe_unused]], - Response& res [[maybe_unused]], - boost::beast::http::verb method [[maybe_unused]], - const boost::beast::http::header<true>& reqHeader, - [[maybe_unused]] const std::shared_ptr<persistent_data::UserSession>& - session) +inline std::shared_ptr<persistent_data::UserSession> authenticate( + const boost::asio::ip::address& ipAddress [[maybe_unused]], + Response& res [[maybe_unused]], + boost::beast::http::verb method [[maybe_unused]], + const boost::beast::http::header<true>& reqHeader, + [[maybe_unused]] const std::shared_ptr<persistent_data::UserSession>& + session) { const persistent_data::AuthConfigMethods& authMethodsConfig = persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); std::shared_ptr<persistent_data::UserSession> sessionOut = nullptr; -#ifdef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION - if (authMethodsConfig.tls) + if constexpr (BMCWEB_MUTUAL_TLS_AUTH) { - sessionOut = performTLSAuth(res, reqHeader, session); + if (authMethodsConfig.tls) + { + sessionOut = performTLSAuth(res, reqHeader, session); + } } -#endif -#ifdef BMCWEB_ENABLE_XTOKEN_AUTHENTICATION - if (sessionOut == nullptr && authMethodsConfig.xtoken) + if constexpr (BMCWEB_XTOKEN_AUTH) { - sessionOut = performXtokenAuth(reqHeader); + if (sessionOut == nullptr && authMethodsConfig.xtoken) + { + sessionOut = performXtokenAuth(reqHeader); + } } -#endif -#ifdef BMCWEB_ENABLE_COOKIE_AUTHENTICATION - if (sessionOut == nullptr && authMethodsConfig.cookie) + if constexpr (BMCWEB_COOKIE_AUTH) { - sessionOut = performCookieAuth(method, reqHeader); + if (sessionOut == nullptr && authMethodsConfig.cookie) + { + sessionOut = performCookieAuth(method, reqHeader); + } } -#endif std::string_view authHeader = reqHeader["Authorization"]; BMCWEB_LOG_DEBUG("authHeader={}", authHeader); - - if (sessionOut == nullptr && authMethodsConfig.sessionToken) + if constexpr (BMCWEB_SESSION_AUTH) { -#ifdef BMCWEB_ENABLE_SESSION_AUTHENTICATION - sessionOut = performTokenAuth(authHeader); -#endif + if (sessionOut == nullptr && authMethodsConfig.sessionToken) + { + sessionOut = performTokenAuth(authHeader); + } } - if (sessionOut == nullptr && authMethodsConfig.basic) + if constexpr (BMCWEB_BASIC_AUTH) { -#ifdef BMCWEB_ENABLE_BASIC_AUTHENTICATION - sessionOut = performBasicAuth(ipAddress, authHeader); -#endif + if (sessionOut == nullptr && authMethodsConfig.basic) + { + sessionOut = performBasicAuth(ipAddress, authHeader); + } } if (sessionOut != nullptr) { diff --git a/include/sessions.hpp b/include/sessions.hpp index 1d0b620fb1..50299b8f20 100644 --- a/include/sessions.hpp +++ b/include/sessions.hpp @@ -134,35 +134,11 @@ struct UserSession struct AuthConfigMethods { -#ifdef BMCWEB_ENABLE_BASIC_AUTHENTICATION - bool basic = true; -#else - bool basic = false; -#endif - -#ifdef BMCWEB_ENABLE_SESSION_AUTHENTICATION - bool sessionToken = true; -#else - bool sessionToken = false; -#endif - -#ifdef BMCWEB_ENABLE_XTOKEN_AUTHENTICATION - bool xtoken = true; -#else - bool xtoken = false; -#endif - -#ifdef BMCWEB_ENABLE_COOKIE_AUTHENTICATION - bool cookie = true; -#else - bool cookie = false; -#endif - -#ifdef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION - bool tls = true; -#else - bool tls = false; -#endif + bool basic = BMCWEB_BASIC_AUTH; + bool sessionToken = BMCWEB_SESSION_AUTH; + bool xtoken = BMCWEB_XTOKEN_AUTH; + bool cookie = BMCWEB_COOKIE_AUTH; + bool tls = BMCWEB_MUTUAL_TLS_AUTH; void fromJson(const nlohmann::json& j) { diff --git a/include/ssl_key_handler.hpp b/include/ssl_key_handler.hpp index d7255dd87d..36477da02c 100644 --- a/include/ssl_key_handler.hpp +++ b/include/ssl_key_handler.hpp @@ -485,7 +485,7 @@ inline std::shared_ptr<boost::asio::ssl::context> mSslContext->use_private_key_file(sslPemFile, boost::asio::ssl::context::pem); - if constexpr (bmcwebEnableHTTP2) + if constexpr (BMCWEB_EXPERIMENTAL_HTTP2) { SSL_CTX_set_next_protos_advertised_cb(mSslContext->native_handle(), nextProtoCallback, nullptr); diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp index 14672e59d8..b489a4265f 100644 --- a/include/vm_websocket.hpp +++ b/include/vm_websocket.hpp @@ -517,10 +517,10 @@ namespace obmc_vm inline void requestRoutes(App& app) { static_assert( - !(bmcwebVmWebsocket && bmcwebNbdProxy), + !(BMCWEB_VM_WEBSOCKET && BMCWEB_VM_NBDPROXY), "nbd proxy cannot be turned on at the same time as vm websocket."); - if constexpr (bmcwebNbdProxy) + if constexpr (BMCWEB_VM_NBDPROXY) { BMCWEB_ROUTE(app, "/nbd/<str>") .privileges({{"ConfigureComponents", "ConfigureManager"}}) @@ -536,7 +536,7 @@ inline void requestRoutes(App& app) .onclose(nbd_proxy::onClose) .onmessageex(nbd_proxy::onMessage); } - if constexpr (bmcwebVmWebsocket) + if constexpr (BMCWEB_VM_WEBSOCKET) { BMCWEB_ROUTE(app, "/vm/0/0") .privileges({{"ConfigureComponents", "ConfigureManager"}}) diff --git a/meson.build b/meson.build index 5bb3fdfc18..101c0ce296 100644 --- a/meson.build +++ b/meson.build @@ -57,85 +57,8 @@ endif incdir = include_directories('include', 'redfish-core/include', 'redfish-core/lib', 'http') -# Get the options and enable the respective features -## create a MAP of "options : feature_flag" - -feature_map = { - 'basic-auth': '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION', - 'cookie-auth': '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION', - 'google-api': '-DBMCWEB_ENABLE_GOOGLE_API', - 'host-serial-socket': '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET', - 'ibm-management-console': '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE', - 'insecure-disable-auth': '-DBMCWEB_INSECURE_DISABLE_AUTHX', - 'insecure-disable-csrf': '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION', - 'insecure-disable-ssl': '-DBMCWEB_INSECURE_DISABLE_SSL', - 'insecure-push-style-notification': '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING', - 'insecure-tftp-update': '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE', - 'insecure-ignore-content-type': '-DBMCWEB_INSECURE_IGNORE_CONTENT_TYPE', - 'kvm': '-DBMCWEB_ENABLE_KVM', - 'mutual-tls-auth': '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION', - 'redfish-aggregation': '-DBMCWEB_ENABLE_REDFISH_AGGREGATION', - 'redfish-allow-deprecated-power-thermal': '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL', - 'redfish-bmc-journal': '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL', - 'redfish-cpu-log': '-DBMCWEB_ENABLE_REDFISH_CPU_LOG', - 'redfish-dbus-log': '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES', - 'redfish-dump-log': '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG', - 'redfish-host-logger': '-DBMCWEB_ENABLE_REDFISH_HOST_LOGGER', - 'redfish-new-powersubsystem-thermalsubsystem': '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM', - 'redfish-oem-manager-fan-data': '-DBMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA', - 'redfish-provisioning-feature': '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE', - 'redfish': '-DBMCWEB_ENABLE_REDFISH', - 'rest': '-DBMCWEB_ENABLE_DBUS_REST', - 'session-auth': '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION', - 'static-hosting': '-DBMCWEB_ENABLE_STATIC_HOSTING', - 'experimental-redfish-multi-computer-system': '-DBMCWEB_ENABLE_MULTI_COMPUTERSYSTEM', - 'xtoken-auth': '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION', - #'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY', -} - -# Get the options status and build a project summary to show which flags are -# being enabled during the configuration time. - -foreach option_key, option_value : feature_map - if (get_option(option_key).allowed()) - if ( - option_key == 'mutual-tls-auth' - or option_key == 'insecure-disable-ssl' - ) - if ( - get_option('insecure-disable-ssl').disabled() - or get_option('mutual-tls-auth').disabled() - ) - add_project_arguments(option_value, language: 'cpp') - summary(option_key, option_value, section: 'Enabled Features') - endif - elif ( - option_key in [ - 'basic-auth', - 'cookie-auth', - 'session-auth', - 'xtoken-auth', - 'mutual-tls-auth', - ] - ) - if (get_option('insecure-disable-auth').disabled()) - add_project_arguments(option_value, language: 'cpp') - summary(option_key, option_value, section: 'Enabled Features') - endif - else - summary(option_key, option_value, section: 'Enabled Features') - add_project_arguments(option_value, language: 'cpp') - endif - else - if (option_key == 'insecure-disable-ssl') - summary('ssl', '-DBMCWEB_ENABLE_SSL', section: 'Enabled Features') - add_project_arguments('-DBMCWEB_ENABLE_SSL', language: 'cpp') - endif - endif -endforeach - if (get_option('tests').allowed()) - summary('unittest', 'NA', section: 'Enabled Features') + summary('unittest', 'NA', section: 'Features') endif # Add compiler arguments @@ -211,16 +134,6 @@ if (get_option('buildtype') != 'plain') endif endif endif - -if ( - get_option('bmcweb-logging') != 'disabled' - or get_option('buildtype').startswith('debug') -) - add_project_arguments(['-DBMCWEB_ENABLE_DEBUG'], language: 'cpp') - - summary('debug', '-DBMCWEB_ENABLE_DEBUG', section: 'Enabled Features') -endif - # Set Compiler Security flags security_flags = [ diff --git a/redfish-core/include/query.hpp b/redfish-core/include/query.hpp index e68b89ae00..063f1a8ef2 100644 --- a/redfish-core/include/query.hpp +++ b/redfish-core/include/query.hpp @@ -147,13 +147,15 @@ inline bool handleIfMatch(crow::App& app, const crow::Request& req, bool needToCallHandlers = true; -#ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION - needToCallHandlers = RedfishAggregator::beginAggregation(req, asyncResp) == - Result::LocalHandle; + if constexpr (BMCWEB_REDFISH_AGGREGATION) + { + needToCallHandlers = RedfishAggregator::beginAggregation( + req, asyncResp) == Result::LocalHandle; - // If the request should be forwarded to a satellite BMC then we don't want - // to write anything to the asyncResp since it will get overwritten later. -#endif + // If the request should be forwarded to a satellite BMC then we don't + // want to write anything to the asyncResp since it will get overwritten + // later. + } // If this isn't a get, no need to do anything with parameters if (req.method() != boost::beast::http::verb::get) diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp index 2441c9f3c0..eadb66ed5c 100644 --- a/redfish-core/include/utils/query_param.hpp +++ b/redfish-core/include/utils/query_param.hpp @@ -389,7 +389,7 @@ inline std::optional<Query> parseParameters(boost::urls::params_view urlParams, } ret.isOnly = true; } - else if (it.key == "$expand" && bmcwebInsecureEnableQueryParams) + else if (it.key == "$expand" && BMCWEB_INSECURE_ENABLE_REDFISH_QUERY) { if (!getExpandType(it.value, ret)) { 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; diff --git a/redfish-core/lib/bios.hpp b/redfish-core/lib/bios.hpp index 025f4361c8..477c15e1d0 100644 --- a/redfish-core/lib/bios.hpp +++ b/redfish-core/lib/bios.hpp @@ -19,7 +19,7 @@ inline void { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -70,7 +70,7 @@ inline void return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp index 9ee10b5c62..19728a470e 100644 --- a/redfish-core/lib/chassis.hpp +++ b/redfish-core/lib/chassis.hpp @@ -402,23 +402,28 @@ inline void handleDecoratorAssetProperties( asyncResp->res.jsonValue["Name"] = chassisId; asyncResp->res.jsonValue["Id"] = chassisId; -#ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL - asyncResp->res.jsonValue["Thermal"]["@odata.id"] = - boost::urls::format("/redfish/v1/Chassis/{}/Thermal", chassisId); - // Power object - asyncResp->res.jsonValue["Power"]["@odata.id"] = - boost::urls::format("/redfish/v1/Chassis/{}/Power", chassisId); -#endif -#ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM - asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] = - boost::urls::format("/redfish/v1/Chassis/{}/ThermalSubsystem", - chassisId); - asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] = - boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", chassisId); - asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] = - boost::urls::format("/redfish/v1/Chassis/{}/EnvironmentMetrics", - chassisId); -#endif + + if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_POWER_THERMAL) + { + asyncResp->res.jsonValue["Thermal"]["@odata.id"] = + boost::urls::format("/redfish/v1/Chassis/{}/Thermal", chassisId); + // Power object + asyncResp->res.jsonValue["Power"]["@odata.id"] = + boost::urls::format("/redfish/v1/Chassis/{}/Power", chassisId); + } + + if constexpr (BMCWEB_REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM) + { + asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] = + boost::urls::format("/redfish/v1/Chassis/{}/ThermalSubsystem", + chassisId); + asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] = + boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", + chassisId); + asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] = + boost::urls::format("/redfish/v1/Chassis/{}/EnvironmentMetrics", + chassisId); + } // SensorCollection asyncResp->res.jsonValue["Sensors"]["@odata.id"] = boost::urls::format("/redfish/v1/Chassis/{}/Sensors", chassisId); diff --git a/redfish-core/lib/fabric_adapters.hpp b/redfish-core/lib/fabric_adapters.hpp index 87015dd3c5..46e67d2b49 100644 --- a/redfish-core/lib/fabric_adapters.hpp +++ b/redfish-core/lib/fabric_adapters.hpp @@ -266,7 +266,7 @@ inline void { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -293,7 +293,7 @@ inline void handleFabricAdapterCollectionGet( { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -333,7 +333,7 @@ inline void handleFabricAdapterCollectionHead( { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -391,7 +391,7 @@ inline void return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 1e5a34f15b..1453a4b11f 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -865,7 +865,7 @@ inline void const std::string& entryID, const std::string& dumpType) { - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1276,7 +1276,7 @@ inline void requestRoutesSystemLogServiceCollection(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1305,25 +1305,29 @@ inline void requestRoutesSystemLogServiceCollection(App& app) eventLog["@odata.id"] = "/redfish/v1/Systems/system/LogServices/EventLog"; logServiceArray.emplace_back(std::move(eventLog)); -#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG - nlohmann::json::object_t dumpLog; - dumpLog["@odata.id"] = "/redfish/v1/Systems/system/LogServices/Dump"; - logServiceArray.emplace_back(std::move(dumpLog)); -#endif - -#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG - nlohmann::json::object_t crashdump; - crashdump["@odata.id"] = - "/redfish/v1/Systems/system/LogServices/Crashdump"; - logServiceArray.emplace_back(std::move(crashdump)); -#endif + if constexpr (BMCWEB_REDFISH_DUMP_LOG) + { + nlohmann::json::object_t dumpLog; + dumpLog["@odata.id"] = + "/redfish/v1/Systems/system/LogServices/Dump"; + logServiceArray.emplace_back(std::move(dumpLog)); + } -#ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER - nlohmann::json::object_t hostlogger; - hostlogger["@odata.id"] = - "/redfish/v1/Systems/system/LogServices/HostLogger"; - logServiceArray.emplace_back(std::move(hostlogger)); -#endif + if constexpr (BMCWEB_REDFISH_DUMP_LOG) + { + nlohmann::json::object_t crashdump; + crashdump["@odata.id"] = + "/redfish/v1/Systems/system/LogServices/Crashdump"; + logServiceArray.emplace_back(std::move(crashdump)); + } + + if constexpr (BMCWEB_REDFISH_HOST_LOGGER) + { + nlohmann::json::object_t hostlogger; + hostlogger["@odata.id"] = + "/redfish/v1/Systems/system/LogServices/HostLogger"; + logServiceArray.emplace_back(std::move(hostlogger)); + } asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); @@ -1556,7 +1560,7 @@ inline void requestRoutesJournalEventLogEntryCollection(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1661,7 +1665,7 @@ inline void requestRoutesJournalEventLogEntry(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1738,7 +1742,7 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1935,7 +1939,7 @@ inline void requestRoutesDBusEventLogEntry(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -2049,7 +2053,7 @@ inline void requestRoutesDBusEventLogEntry(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -2089,7 +2093,7 @@ inline void requestRoutesDBusEventLogEntry(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -2229,7 +2233,7 @@ inline void requestRoutesSystemHostLogger(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -2273,7 +2277,7 @@ inline void requestRoutesSystemHostLoggerCollection(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -2357,7 +2361,7 @@ inline void requestRoutesSystemHostLoggerLogEntry(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -2435,57 +2439,59 @@ inline void handleBMCLogServicesCollectionGet( nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; logServiceArray = nlohmann::json::array(); -#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL - nlohmann::json::object_t journal; - journal["@odata.id"] = "/redfish/v1/Managers/bmc/LogServices/Journal"; - logServiceArray.emplace_back(std::move(journal)); -#endif + if constexpr (BMCWEB_REDFISH_BMC_JOURNAL) + { + nlohmann::json::object_t journal; + journal["@odata.id"] = "/redfish/v1/Managers/bmc/LogServices/Journal"; + logServiceArray.emplace_back(std::move(journal)); + } asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size(); -#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG - constexpr std::array<std::string_view, 1> interfaces = { - "xyz.openbmc_project.Collection.DeleteAll"}; - dbus::utility::getSubTreePaths( - "/xyz/openbmc_project/dump", 0, interfaces, - [asyncResp]( - const boost::system::error_code& ec, - const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) { - if (ec) - { - BMCWEB_LOG_ERROR( - "handleBMCLogServicesCollectionGet respHandler got error {}", - ec); - // Assume that getting an error simply means there are no dump - // LogServices. Return without adding any error response. - return; - } - - nlohmann::json& logServiceArrayLocal = - asyncResp->res.jsonValue["Members"]; - - for (const std::string& path : subTreePaths) - { - if (path == "/xyz/openbmc_project/dump/bmc") + if constexpr (BMCWEB_REDFISH_DUMP_LOG) + { + constexpr std::array<std::string_view, 1> interfaces = { + "xyz.openbmc_project.Collection.DeleteAll"}; + dbus::utility::getSubTreePaths( + "/xyz/openbmc_project/dump", 0, interfaces, + [asyncResp](const boost::system::error_code& ec, + const dbus::utility::MapperGetSubTreePathsResponse& + subTreePaths) { + if (ec) { - nlohmann::json::object_t member; - member["@odata.id"] = - "/redfish/v1/Managers/bmc/LogServices/Dump"; - logServiceArrayLocal.emplace_back(std::move(member)); + BMCWEB_LOG_ERROR( + "handleBMCLogServicesCollectionGet respHandler got error {}", + ec); + // Assume that getting an error simply means there are no dump + // LogServices. Return without adding any error response. + return; } - else if (path == "/xyz/openbmc_project/dump/faultlog") + + nlohmann::json& logServiceArrayLocal = + asyncResp->res.jsonValue["Members"]; + + for (const std::string& path : subTreePaths) { - nlohmann::json::object_t member; - member["@odata.id"] = - "/redfish/v1/Managers/bmc/LogServices/FaultLog"; - logServiceArrayLocal.emplace_back(std::move(member)); + if (path == "/xyz/openbmc_project/dump/bmc") + { + nlohmann::json::object_t member; + member["@odata.id"] = + "/redfish/v1/Managers/bmc/LogServices/Dump"; + logServiceArrayLocal.emplace_back(std::move(member)); + } + else if (path == "/xyz/openbmc_project/dump/faultlog") + { + nlohmann::json::object_t member; + member["@odata.id"] = + "/redfish/v1/Managers/bmc/LogServices/FaultLog"; + logServiceArrayLocal.emplace_back(std::move(member)); + } } - } - asyncResp->res.jsonValue["Members@odata.count"] = - logServiceArrayLocal.size(); - }); -#endif + asyncResp->res.jsonValue["Members@odata.count"] = + logServiceArrayLocal.size(); + }); + } } inline void requestRoutesBMCLogServiceCollection(App& app) @@ -3004,7 +3010,7 @@ inline void handleLogServicesDumpCollectDiagnosticDataComputerSystemPost( return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3040,7 +3046,7 @@ inline void handleLogServicesDumpClearLogComputerSystemPost( { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3242,7 +3248,7 @@ inline void requestRoutesCrashdumpService(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3300,7 +3306,7 @@ void inline requestRoutesCrashdumpClear(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3417,7 +3423,7 @@ inline void requestRoutesCrashdumpEntryCollection(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3493,7 +3499,7 @@ inline void requestRoutesCrashdumpEntry(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3527,7 +3533,7 @@ inline void requestRoutesCrashdumpFile(App& app) // Do not call getRedfishRoute here since the crashdump file is not a // Redfish resource. - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3633,7 +3639,7 @@ inline void requestRoutesCrashdumpCollect(App& app) return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3769,7 +3775,7 @@ inline void requestRoutesDBusLogServiceActionsClear(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3823,7 +3829,7 @@ inline void requestRoutesPostCodesLogService(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3875,7 +3881,7 @@ inline void requestRoutesPostCodesClear(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -4236,7 +4242,7 @@ inline void requestRoutesPostCodesEntryCollection(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -4287,7 +4293,7 @@ inline void requestRoutesPostCodesEntryAdditionalData(App& app) asyncResp->res.result(boost::beast::http::status::bad_request); return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -4373,7 +4379,7 @@ inline void requestRoutesPostCodesEntry(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp index 592bbd8642..e6f42bea8c 100644 --- a/redfish-core/lib/managers.hpp +++ b/redfish-core/lib/managers.hpp @@ -1945,7 +1945,7 @@ inline void requestRoutesManager(App& app) asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = "/redfish/v1/Managers/bmc/EthernetInterfaces"; - if constexpr (bmcwebNbdProxy) + if constexpr (BMCWEB_VM_NBDPROXY) { asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = "/redfish/v1/Managers/bmc/VirtualMedia"; @@ -1998,15 +1998,18 @@ inline void requestRoutesManager(App& app) asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = nlohmann::json::array_t({"IPMI", "SSH"}); -#ifdef BMCWEB_ENABLE_KVM - // Fill in GraphicalConsole info - asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; - asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = - 4; - asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = - nlohmann::json::array_t({"KVMIP"}); -#endif // BMCWEB_ENABLE_KVM - if constexpr (!bmcwebEnableMultiHost) + if constexpr (BMCWEB_KVM) + { + // Fill in GraphicalConsole info + asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = + true; + asyncResp->res + .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; + asyncResp->res + .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = + nlohmann::json::array_t({"KVMIP"}); + } + if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1; @@ -2031,10 +2034,11 @@ inline void requestRoutesManager(App& app) managerDiagnosticData["@odata.id"] = "/redfish/v1/Managers/bmc/ManagerDiagnosticData"; -#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA - auto pids = std::make_shared<GetPIDValues>(asyncResp); - pids->run(); -#endif + if constexpr (BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA) + { + auto pids = std::make_shared<GetPIDValues>(asyncResp); + pids->run(); + } getMainChassisId(asyncResp, [](const std::string& chassisId, @@ -2217,36 +2221,39 @@ inline void requestRoutesManager(App& app) if (pidControllers || fanControllers || fanZones || stepwiseControllers || profile) { -#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA - std::vector< - std::pair<std::string, std::optional<nlohmann::json::object_t>>> - configuration; - if (pidControllers) - { - configuration.emplace_back("PidControllers", - std::move(pidControllers)); - } - if (fanControllers) - { - configuration.emplace_back("FanControllers", - std::move(fanControllers)); - } - if (fanZones) + if constexpr (BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA) { - configuration.emplace_back("FanZones", std::move(fanZones)); + std::vector<std::pair<std::string, + std::optional<nlohmann::json::object_t>>> + configuration; + if (pidControllers) + { + configuration.emplace_back("PidControllers", + std::move(pidControllers)); + } + if (fanControllers) + { + configuration.emplace_back("FanControllers", + std::move(fanControllers)); + } + if (fanZones) + { + configuration.emplace_back("FanZones", std::move(fanZones)); + } + if (stepwiseControllers) + { + configuration.emplace_back("StepwiseControllers", + std::move(stepwiseControllers)); + } + auto pid = std::make_shared<SetPIDValues>( + asyncResp, std::move(configuration), profile); + pid->run(); } - if (stepwiseControllers) + else { - configuration.emplace_back("StepwiseControllers", - std::move(stepwiseControllers)); + messages::propertyUnknown(asyncResp->res, "Oem"); + return; } - auto pid = std::make_shared<SetPIDValues>( - asyncResp, std::move(configuration), profile); - pid->run(); -#else - messages::propertyUnknown(asyncResp->res, "Oem"); - return; -#endif } if (activeSoftwareImageOdataId) diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp index 2882da0ea7..49d19623fa 100644 --- a/redfish-core/lib/memory.hpp +++ b/redfish-core/lib/memory.hpp @@ -778,7 +778,7 @@ inline void requestRoutesMemoryCollection(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -822,7 +822,7 @@ inline void requestRoutesMemory(App& app) return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp index 223522b5f0..af78cc8ab2 100644 --- a/redfish-core/lib/pcie.hpp +++ b/redfish-core/lib/pcie.hpp @@ -108,7 +108,7 @@ static inline void handlePCIeDeviceCollectionGet( { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -566,7 +566,7 @@ inline void { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -639,7 +639,7 @@ inline void handlePCIeFunctionCollectionGet( { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -790,7 +790,7 @@ inline void { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp index ff17ebdcc3..481c2a5df3 100644 --- a/redfish-core/lib/processor.hpp +++ b/redfish-core/lib/processor.hpp @@ -1105,7 +1105,7 @@ inline void requestRoutesOperatingConfigCollection(App& app) return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1184,7 +1184,7 @@ inline void requestRoutesOperatingConfig(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1263,7 +1263,7 @@ inline void requestRoutesProcessorCollection(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1318,7 +1318,7 @@ inline void requestRoutesProcessor(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -1356,7 +1356,7 @@ inline void requestRoutesProcessor(App& app) { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index 75eaa7cde1..906888849a 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -64,21 +64,30 @@ constexpr auto powerPaths = std::to_array<std::string_view>({ "/xyz/openbmc_project/sensors/power" }); -constexpr auto sensorPaths = std::to_array<std::string_view>({ - "/xyz/openbmc_project/sensors/power", - "/xyz/openbmc_project/sensors/current", - "/xyz/openbmc_project/sensors/airflow", - "/xyz/openbmc_project/sensors/humidity", -#ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM - "/xyz/openbmc_project/sensors/voltage", - "/xyz/openbmc_project/sensors/fan_tach", - "/xyz/openbmc_project/sensors/temperature", - "/xyz/openbmc_project/sensors/fan_pwm", - "/xyz/openbmc_project/sensors/altitude", - "/xyz/openbmc_project/sensors/energy", -#endif - "/xyz/openbmc_project/sensors/utilization" -}); +constexpr auto getSensorPaths(){ + if constexpr(BMCWEB_REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM){ + return std::to_array<std::string_view>({ + "/xyz/openbmc_project/sensors/power", + "/xyz/openbmc_project/sensors/current", + "/xyz/openbmc_project/sensors/airflow", + "/xyz/openbmc_project/sensors/humidity", + "/xyz/openbmc_project/sensors/voltage", + "/xyz/openbmc_project/sensors/fan_tach", + "/xyz/openbmc_project/sensors/temperature", + "/xyz/openbmc_project/sensors/fan_pwm", + "/xyz/openbmc_project/sensors/altitude", + "/xyz/openbmc_project/sensors/energy", + "/xyz/openbmc_project/sensors/utilization"}); + } else { + return std::to_array<std::string_view>({"/xyz/openbmc_project/sensors/power", + "/xyz/openbmc_project/sensors/current", + "/xyz/openbmc_project/sensors/airflow", + "/xyz/openbmc_project/sensors/humidity", + "/xyz/openbmc_project/sensors/utilization"}); +} +} + +constexpr auto sensorPaths = getSensorPaths(); constexpr auto thermalPaths = std::to_array<std::string_view>({ "/xyz/openbmc_project/sensors/fan_tach", diff --git a/redfish-core/lib/service_root.hpp b/redfish-core/lib/service_root.hpp index 6ae16c3780..2fc35150dd 100644 --- a/redfish-core/lib/service_root.hpp +++ b/redfish-core/lib/service_root.hpp @@ -62,10 +62,11 @@ inline void handleServiceRootGetImpl( "/redfish/v1/SessionService/Sessions"; asyncResp->res.jsonValue["AccountService"]["@odata.id"] = "/redfish/v1/AccountService"; -#ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION - asyncResp->res.jsonValue["AggregationService"]["@odata.id"] = - "/redfish/v1/AggregationService"; -#endif + if constexpr (BMCWEB_REDFISH_AGGREGATION) + { + asyncResp->res.jsonValue["AggregationService"]["@odata.id"] = + "/redfish/v1/AggregationService"; + } asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis"; asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] = "/redfish/v1/JsonSchemas"; @@ -95,16 +96,18 @@ inline void handleServiceRootGetImpl( protocolFeatures["ExcerptQuery"] = false; protocolFeatures["ExpandQuery"]["ExpandAll"] = - bmcwebInsecureEnableQueryParams; + BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; // This is the maximum level defined in ServiceRoot.v1_13_0.json - if (bmcwebInsecureEnableQueryParams) + if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY) { protocolFeatures["ExpandQuery"]["MaxLevels"] = 6; } - protocolFeatures["ExpandQuery"]["Levels"] = bmcwebInsecureEnableQueryParams; - protocolFeatures["ExpandQuery"]["Links"] = bmcwebInsecureEnableQueryParams; + protocolFeatures["ExpandQuery"]["Levels"] = + BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; + protocolFeatures["ExpandQuery"]["Links"] = + BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; protocolFeatures["ExpandQuery"]["NoLinks"] = - bmcwebInsecureEnableQueryParams; + BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; protocolFeatures["FilterQuery"] = false; protocolFeatures["OnlyMemberQuery"] = true; protocolFeatures["SelectQuery"] = true; diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp index 9438144c12..c6141df555 100644 --- a/redfish-core/lib/storage.hpp +++ b/redfish-core/lib/storage.hpp @@ -193,7 +193,7 @@ inline void { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -690,7 +690,7 @@ inline void handleSystemsStorageDriveGet( { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index 5765af89ab..e12db494ab 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -1926,15 +1926,16 @@ inline void "PowerRestorePolicy", powerRestorePolicy); } -#ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE /** * @brief Retrieves provisioning status * - * @param[in] asyncResp Shared pointer for completing asynchronous calls. + * @param[in] asyncResp Shared pointer for completing asynchronous + * calls. * * @return None. */ -inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> asyncResp) +inline void + getProvisioningStatus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { BMCWEB_LOG_DEBUG("Get OEM information."); sdbusplus::asio::getAllProperties( @@ -1976,9 +1977,9 @@ inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> asyncResp) return; } - if (*provState == true) + if (*provState) { - if (*lockState == true) + if (*lockState) { oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; } @@ -1993,7 +1994,6 @@ inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> asyncResp) } }); } -#endif /** * @brief Translate the PowerMode string to enum value @@ -2773,7 +2773,7 @@ inline void handleComputerSystemCollectionGet( nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"]; ifaceArray = nlohmann::json::array(); - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { asyncResp->res.jsonValue["Members@odata.count"] = 0; // Option currently returns no systems. TBD @@ -2853,7 +2853,7 @@ inline void handleComputerSystemResetActionPost( systemName); return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -2991,7 +2991,7 @@ inline void return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3063,14 +3063,15 @@ inline void getPortStatusAndPath(std::span{protocolToDBusForSystems}, std::bind_front(afterPortRequest, asyncResp)); -#ifdef BMCWEB_ENABLE_KVM - // Fill in GraphicalConsole info - asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; - asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; - asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = - nlohmann::json::array_t({"KVMIP"}); - -#endif // BMCWEB_ENABLE_KVM + if constexpr (BMCWEB_KVM) + { + // Fill in GraphicalConsole info + asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; + asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = + 4; + asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = + nlohmann::json::array_t({"KVMIP"}); + } getMainChassisId(asyncResp, [](const std::string& chassisId, @@ -3097,9 +3098,10 @@ inline void getStopBootOnFault(asyncResp); getAutomaticRetryPolicy(asyncResp); getLastResetTime(asyncResp); -#ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE - getProvisioningStatus(asyncResp); -#endif + if constexpr (BMCWEB_REDFISH_PROVISIONING_FEATURE) + { + getProvisioningStatus(asyncResp); + } getTrustedModuleRequiredToBoot(asyncResp); getPowerMode(asyncResp); getIdlePowerSaver(asyncResp); @@ -3114,7 +3116,7 @@ inline void handleComputerSystemPatch( { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", @@ -3363,7 +3365,7 @@ inline void handleSystemCollectionResetActionGet( { return; } - if constexpr (bmcwebEnableMultiHost) + if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) { // Option currently returns no systems. TBD messages::resourceNotFound(asyncResp->res, "ComputerSystem", diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index 0418d269b9..6895cb4949 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -831,7 +831,7 @@ inline void asyncResp->res.jsonValue["FirmwareInventory"]["@odata.id"] = "/redfish/v1/UpdateService/FirmwareInventory"; // Get the MaxImageSizeBytes - asyncResp->res.jsonValue["MaxImageSizeBytes"] = bmcwebHttpReqBodyLimitMb * + asyncResp->res.jsonValue["MaxImageSizeBytes"] = BMCWEB_HTTP_BODY_LIMIT * 1024 * 1024; // Update Actions object. @@ -842,9 +842,10 @@ inline void nlohmann::json::array_t allowed; -#ifdef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE - allowed.emplace_back(update_service::TransferProtocolType::TFTP); -#endif + if constexpr (BMCWEB_INSECURE_PUSH_STYLE_NOTIFICATION) + { + allowed.emplace_back(update_service::TransferProtocolType::TFTP); + } updateSvcSimpleUpdate["TransferProtocol@Redfish.AllowableValues"] = std::move(allowed); diff --git a/redfish-core/src/redfish.cpp b/redfish-core/src/redfish.cpp index 66a43d76f0..e7a58c1f41 100644 --- a/redfish-core/src/redfish.cpp +++ b/redfish-core/src/redfish.cpp @@ -51,31 +51,34 @@ namespace redfish RedfishService::RedfishService(App& app) { requestAccountServiceRoutes(app); -#ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION - requestRoutesAggregationService(app); - requestRoutesAggregationSourceCollection(app); - requestRoutesAggregationSource(app); -#endif + if constexpr (BMCWEB_REDFISH_AGGREGATION) + { + requestRoutesAggregationService(app); + requestRoutesAggregationSourceCollection(app); + requestRoutesAggregationSource(app); + } requestRoutesRoles(app); requestRoutesRoleCollection(app); requestRoutesServiceRoot(app); requestRoutesNetworkProtocol(app); requestRoutesSession(app); requestEthernetInterfacesRoutes(app); -#ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL - requestRoutesThermal(app); - requestRoutesPower(app); -#endif -#ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM - requestRoutesEnvironmentMetrics(app); - requestRoutesPowerSubsystem(app); - requestRoutesPowerSupply(app); - requestRoutesPowerSupplyCollection(app); - requestRoutesThermalMetrics(app); - requestRoutesThermalSubsystem(app); - requestRoutesFan(app); - requestRoutesFanCollection(app); -#endif + if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_POWER_THERMAL) + { + requestRoutesThermal(app); + requestRoutesPower(app); + } + if constexpr (BMCWEB_REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM) + { + requestRoutesEnvironmentMetrics(app); + requestRoutesPowerSubsystem(app); + requestRoutesPowerSupply(app); + requestRoutesPowerSupplyCollection(app); + requestRoutesThermalMetrics(app); + requestRoutesThermalSubsystem(app); + requestRoutesFan(app); + requestRoutesFanCollection(app); + } requestRoutesManagerCollection(app); requestRoutesManager(app); requestRoutesManagerResetAction(app); @@ -106,47 +109,51 @@ RedfishService::RedfishService(App& app) requestRoutesPostCodesEntry(app); requestRoutesPostCodesEntryCollection(app); -#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG - requestRoutesSystemDumpService(app); - requestRoutesSystemDumpEntryCollection(app); - requestRoutesSystemDumpEntry(app); - requestRoutesSystemDumpCreate(app); - requestRoutesSystemDumpClear(app); - - requestRoutesBMCDumpService(app); - requestRoutesBMCDumpEntryCollection(app); - requestRoutesBMCDumpEntry(app); - requestRoutesBMCDumpEntryDownload(app); - requestRoutesBMCDumpCreate(app); - requestRoutesBMCDumpClear(app); - - requestRoutesFaultLogDumpService(app); - requestRoutesFaultLogDumpEntryCollection(app); - requestRoutesFaultLogDumpEntry(app); - requestRoutesFaultLogDumpClear(app); -#endif - -#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES - requestRoutesJournalEventLogEntryCollection(app); - requestRoutesJournalEventLogEntry(app); - requestRoutesJournalEventLogClear(app); -#endif + if constexpr (BMCWEB_REDFISH_DUMP_LOG) + { + requestRoutesSystemDumpService(app); + requestRoutesSystemDumpEntryCollection(app); + requestRoutesSystemDumpEntry(app); + requestRoutesSystemDumpCreate(app); + requestRoutesSystemDumpClear(app); + + requestRoutesBMCDumpService(app); + requestRoutesBMCDumpEntryCollection(app); + requestRoutesBMCDumpEntry(app); + requestRoutesBMCDumpEntryDownload(app); + requestRoutesBMCDumpCreate(app); + requestRoutesBMCDumpClear(app); + + requestRoutesFaultLogDumpService(app); + requestRoutesFaultLogDumpEntryCollection(app); + requestRoutesFaultLogDumpEntry(app); + requestRoutesFaultLogDumpClear(app); + } + + if constexpr (BMCWEB_REDFISH_DBUS_LOG) + { + requestRoutesJournalEventLogEntryCollection(app); + requestRoutesJournalEventLogEntry(app); + requestRoutesJournalEventLogClear(app); + } requestRoutesBMCLogServiceCollection(app); -#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL - requestRoutesBMCJournalLogService(app); - requestRoutesBMCJournalLogEntryCollection(app); - requestRoutesBMCJournalLogEntry(app); -#endif - -#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG - requestRoutesCrashdumpService(app); - requestRoutesCrashdumpEntryCollection(app); - requestRoutesCrashdumpEntry(app); - requestRoutesCrashdumpFile(app); - requestRoutesCrashdumpClear(app); - requestRoutesCrashdumpCollect(app); -#endif // BMCWEB_ENABLE_REDFISH_CPU_LOG + if constexpr (BMCWEB_REDFISH_BMC_JOURNAL) + { + requestRoutesBMCJournalLogService(app); + requestRoutesBMCJournalLogEntryCollection(app); + requestRoutesBMCJournalLogEntry(app); + } + + if constexpr (BMCWEB_REDFISH_CPU_LOG) + { + requestRoutesCrashdumpService(app); + requestRoutesCrashdumpEntryCollection(app); + requestRoutesCrashdumpEntry(app); + requestRoutesCrashdumpFile(app); + requestRoutesCrashdumpClear(app); + requestRoutesCrashdumpCollect(app); + } requestRoutesProcessorCollection(app); requestRoutesProcessor(app); @@ -160,22 +167,25 @@ RedfishService::RedfishService(App& app) requestRoutesBiosService(app); requestRoutesBiosReset(app); -#ifdef BMCWEB_ENABLE_VM_NBDPROXY - requestNBDVirtualMediaRoutes(app); -#endif // BMCWEB_ENABLE_VM_NBDPROXY - -#ifdef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES - requestRoutesDBusLogServiceActionsClear(app); - requestRoutesDBusEventLogEntryCollection(app); - requestRoutesDBusEventLogEntry(app); - requestRoutesDBusEventLogEntryDownload(app); -#endif - -#ifdef BMCWEB_ENABLE_REDFISH_HOST_LOGGER - requestRoutesSystemHostLogger(app); - requestRoutesSystemHostLoggerCollection(app); - requestRoutesSystemHostLoggerLogEntry(app); -#endif + if constexpr (BMCWEB_VM_NBDPROXY) + { + requestNBDVirtualMediaRoutes(app); + } + + if constexpr (BMCWEB_REDFISH_DBUS_LOG) + { + requestRoutesDBusLogServiceActionsClear(app); + requestRoutesDBusEventLogEntryCollection(app); + requestRoutesDBusEventLogEntry(app); + requestRoutesDBusEventLogEntryDownload(app); + } + + if constexpr (BMCWEB_REDFISH_HOST_LOGGER) + { + requestRoutesSystemHostLogger(app); + requestRoutesSystemHostLoggerCollection(app); + requestRoutesSystemHostLoggerLogEntry(app); + } requestRoutesMessageRegistryFileCollection(app); requestRoutesMessageRegistryFile(app); diff --git a/src/webserver_run.cpp b/src/webserver_run.cpp index 81a78cc5b3..808859620b 100644 --- a/src/webserver_run.cpp +++ b/src/webserver_run.cpp @@ -37,64 +37,67 @@ int run() // Static assets need to be initialized before Authorization, because auth // needs to build the whitelist from the static routes -#ifdef BMCWEB_ENABLE_STATIC_HOSTING - crow::webassets::requestRoutes(app); -#endif + if constexpr (BMCWEB_STATIC_HOSTING) + { + crow::webassets::requestRoutes(app); + } -#ifdef BMCWEB_ENABLE_KVM - crow::obmc_kvm::requestRoutes(app); -#endif + if constexpr (BMCWEB_KVM) + { + crow::obmc_kvm::requestRoutes(app); + } -#ifdef BMCWEB_ENABLE_REDFISH - redfish::RedfishService redfish(app); + if constexpr (BMCWEB_REDFISH) + { + redfish::RedfishService redfish(app); - // Create EventServiceManager instance and initialize Config - redfish::EventServiceManager::getInstance(&*io); + // Create EventServiceManager instance and initialize Config + redfish::EventServiceManager::getInstance(&*io); -#ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION - // Create RedfishAggregator instance and initialize Config - redfish::RedfishAggregator::getInstance(&*io); -#endif -#endif + if constexpr (BMCWEB_REDFISH_AGGREGATION) + { + // Create RedfishAggregator instance and initialize Config + redfish::RedfishAggregator::getInstance(&*io); + } + } -#ifdef BMCWEB_ENABLE_DBUS_REST - crow::dbus_monitor::requestRoutes(app); - crow::image_upload::requestRoutes(app); - crow::openbmc_mapper::requestRoutes(app); -#endif + if constexpr (BMCWEB_REST) + { + crow::dbus_monitor::requestRoutes(app); + crow::image_upload::requestRoutes(app); + crow::openbmc_mapper::requestRoutes(app); + } -#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET - crow::obmc_console::requestRoutes(app); -#endif + if constexpr (BMCWEB_HOST_SERIAL_SOCKET) + { + crow::obmc_console::requestRoutes(app); + } -#ifdef BMCWEB_ENABLE_VM_WEBSOCKET crow::obmc_vm::requestRoutes(app); -#endif -#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE - crow::ibm_mc::requestRoutes(app); -#endif + if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE) + { + crow::ibm_mc::requestRoutes(app); + } -#ifdef BMCWEB_ENABLE_GOOGLE_API - crow::google_api::requestRoutes(app); -#endif + if constexpr (BMCWEB_GOOGLE_API) + { + crow::google_api::requestRoutes(app); + } crow::login_routes::requestRoutes(app); -#ifdef BMCWEB_ENABLE_VM_NBDPROXY - crow::nbd_proxy::requestRoutes(app); -#endif - -#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES - int rc = redfish::EventServiceManager::startEventLogMonitor(*io); - if (rc != 0) + if constexpr (BMCWEB_REDFISH_DBUS_LOG) { - BMCWEB_LOG_ERROR("Redfish event handler setup failed..."); - return rc; + int rc = redfish::EventServiceManager::startEventLogMonitor(*io); + if (rc != 0) + { + BMCWEB_LOG_ERROR("Redfish event handler setup failed..."); + return rc; + } } -#endif - if constexpr (bmcwebEnableTLS) + if constexpr (!BMCWEB_INSECURE_DISABLE_SSL) { BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); crow::hostname_monitor::registerHostnameSignal(); diff --git a/test/redfish-core/include/utils/query_param_test.cpp b/test/redfish-core/include/utils/query_param_test.cpp index 46cc64d003..b466f81a70 100644 --- a/test/redfish-core/include/utils/query_param_test.cpp +++ b/test/redfish-core/include/utils/query_param_test.cpp @@ -546,7 +546,7 @@ TEST(QueryParams, ParseParametersExpand) crow::Response res; std::optional<Query> query = parseParameters(ret->params(), res); - if constexpr (bmcwebInsecureEnableQueryParams) + if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY) { ASSERT_TRUE(query); if (!query) diff --git a/test/redfish-core/lib/service_root_test.cpp b/test/redfish-core/lib/service_root_test.cpp index 3d47221041..01e48a1d76 100644 --- a/test/redfish-core/lib/service_root_test.cpp +++ b/test/redfish-core/lib/service_root_test.cpp @@ -84,14 +84,14 @@ void assertServiceRootGet(crow::Response& res) EXPECT_EQ(json["ProtocolFeaturesSupported"].size(), 6); EXPECT_FALSE(json["ProtocolFeaturesSupported"]["ExcerptQuery"]); EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["ExpandAll"], - bmcwebInsecureEnableQueryParams); + BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Levels"], - bmcwebInsecureEnableQueryParams); + BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["Links"], - bmcwebInsecureEnableQueryParams); + BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["NoLinks"], - bmcwebInsecureEnableQueryParams); - if (bmcwebInsecureEnableQueryParams) + BMCWEB_INSECURE_ENABLE_REDFISH_QUERY); + if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY) { EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"].size(), 5); EXPECT_EQ(json["ProtocolFeaturesSupported"]["ExpandQuery"]["MaxLevels"], |