Move ClientID parameter out of OEM
In 2022.2, Redfish added support for the Context parameter on the
Session Resource. This parameter has the same function that the
OemSession.ClientId field served. This commit moves all the existing
ClientId code to produce Context as well.
Functionally, this has one important difference, in that Context in
Redfish is optionally provided by the user, which means we need to omit
it if not given by the user. The old implementation left it set to
empty string ("").
Because of this, a few minor interfaces need to change to use
std::optional. Existing uses of clientId are moved to using
value_or("") to keep the same behavior as before.
Tested:
curl --insecure -X POST -d "{\"UserName\": \"root\", \"Password\":
\"0penBmc\"}" https://192.168.7.2/redfish/v1/SessionService/Sessions
Returns a Session object with no Context key present
curl --insecure -X POST -d "{\"UserName\": \"root\", \"Password\":
\"0penBmc\", \"Context\": \"Foobar\"}"
https://192.168.7.2/redfish/v1/SessionService/Sessions
Returns a Session object with:
"Context": "Foobar"
Subsequent Gets of /redfish/v1/SessionService/Sessions/<sid>
return the same session objects, both with and without Context.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I4df358623f93f3e6cb659e99970ad909cefebc62
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 79b344a..94a0755 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -8,6 +8,7 @@
#include <utils/ip_utils.hpp>
#include <csignal>
+#include <optional>
#include <random>
#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
#include <ibm/locks.hpp>
@@ -33,7 +34,7 @@
std::string sessionToken;
std::string username;
std::string csrfToken;
- std::string clientId;
+ std::optional<std::string> clientId;
std::string clientIp;
std::chrono::time_point<std::chrono::steady_clock> lastUpdated;
PersistenceType persistence{PersistenceType::TIMEOUT};
@@ -88,12 +89,10 @@
{
userSession->username = *thisValue;
}
-#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
else if (element.key() == "client_id")
{
userSession->clientId = *thisValue;
}
-#endif
else if (element.key() == "client_ip")
{
userSession->clientIp = *thisValue;
@@ -204,7 +203,7 @@
std::shared_ptr<UserSession> generateUserSession(
const std::string_view username,
const boost::asio::ip::address& clientIp,
- const std::string_view clientId,
+ const std::optional<std::string>& clientId,
PersistenceType persistence = PersistenceType::TIMEOUT,
bool isConfigureSelfOnly = false)
{
@@ -255,8 +254,8 @@
}
auto session = std::make_shared<UserSession>(UserSession{
- uniqueId, sessionToken, std::string(username), csrfToken,
- std::string(clientId), redfish::ip_util::toString(clientIp),
+ uniqueId, sessionToken, std::string(username), csrfToken, clientId,
+ redfish::ip_util::toString(clientIp),
std::chrono::steady_clock::now(), persistence, false,
isConfigureSelfOnly});
auto it = authTokens.emplace(sessionToken, session);