diff options
author | Ed Tanous <edtanous@google.com> | 2022-08-03 03:07:54 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-10-07 21:06:08 +0300 |
commit | bb759e3aeaadfec9f3aac4485f253bcc8a523e4c (patch) | |
tree | 52e48fbdd2a77c2c6ba583a2d41750e265336a77 /redfish-core/lib | |
parent | 40e4f380d645c6bbe6bd8050e501203798a0c488 (diff) | |
download | bmcweb-bb759e3aeaadfec9f3aac4485f253bcc8a523e4c.tar.xz |
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
Diffstat (limited to 'redfish-core/lib')
-rw-r--r-- | redfish-core/lib/redfish_sessions.hpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp index 37527dd059..d1314a5767 100644 --- a/redfish-core/lib/redfish_sessions.hpp +++ b/redfish-core/lib/redfish_sessions.hpp @@ -34,14 +34,19 @@ inline void fillSessionObject(crow::Response& res, res.jsonValue["UserName"] = session.username; res.jsonValue["@odata.id"] = "/redfish/v1/SessionService/Sessions/" + session.uniqueId; - res.jsonValue["@odata.type"] = "#Session.v1_3_0.Session"; + res.jsonValue["@odata.type"] = "#Session.v1_5_0.Session"; res.jsonValue["Name"] = "User Session"; res.jsonValue["Description"] = "Manager User Session"; res.jsonValue["ClientOriginIPAddress"] = session.clientIp; + if (session.clientId) + { + res.jsonValue["Context"] = *session.clientId; + } +// The below implementation is deprecated in leiu of Session.Context #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE res.jsonValue["Oem"]["OpenBMC"]["@odata.type"] = "#OemSession.v1_0_0.Session"; - res.jsonValue["Oem"]["OpenBMC"]["ClientID"] = session.clientId; + res.jsonValue["Oem"]["OpenBMC"]["ClientID"] = session.clientId.value_or(""); #endif } @@ -187,9 +192,10 @@ inline void handleSessionCollectionPost( std::string username; std::string password; std::optional<nlohmann::json> oemObject; - std::string clientId; + std::optional<std::string> clientId; if (!json_util::readJsonPatch(req, asyncResp->res, "UserName", username, - "Password", password, "Oem", oemObject)) + "Password", password, "Context", clientId, + "Oem", oemObject)) { return; } @@ -226,11 +232,23 @@ inline void handleSessionCollectionPost( { return; } - if (!json_util::readJson(*bmcOem, asyncResp->res, "ClientID", clientId)) + + std::optional<std::string> oemClientId; + if (!json_util::readJson(*bmcOem, asyncResp->res, "ClientID", + oemClientId)) { BMCWEB_LOG_ERROR << "Could not read ClientId"; return; } + if (oemClientId) + { + if (clientId) + { + messages::propertyValueConflict(*oemClientId, *clientId); + return; + } + clientId = *oemClientId; + } } #endif |