summaryrefslogtreecommitdiff
path: root/redfish-core/lib/redfish_sessions.hpp
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2018-05-23 01:27:24 +0300
committerEd Tanous <ed.tanous@intel.com>2018-07-27 01:54:37 +0300
commit55c7b7a2e58779580f33046d2dd8649243776700 (patch)
treeeed2d032dff3e18c4a8d4778e8f52ae5864620ee /redfish-core/lib/redfish_sessions.hpp
parent1752c9657b56a6e1950d8725f44f4298c9872c63 (diff)
downloadbmcweb-55c7b7a2e58779580f33046d2dd8649243776700.tar.xz
Move over to upstream c++ style
This patchset moves bmcweb over to the upstream style naming conventions for variables, classes, and functions, as well as imposes the latest clang-format file. This changeset was mostly built automatically by the included .clang-tidy file, which has the ability to autoformat and auto rename variables. At some point in the future I would like to see this in greater use, but for now, we will impose it on bmcweb, and see how it goes. Tested: Code still compiles, and appears to run, although other issues are possible and likely. Change-Id: If422a2e36df924e897736b3feffa89f411d9dac1 Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Diffstat (limited to 'redfish-core/lib/redfish_sessions.hpp')
-rw-r--r--redfish-core/lib/redfish_sessions.hpp91
1 files changed, 45 insertions, 46 deletions
diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp
index 9e793df049..a32a660754 100644
--- a/redfish-core/lib/redfish_sessions.hpp
+++ b/redfish-core/lib/redfish_sessions.hpp
@@ -42,52 +42,52 @@ class Sessions : public Node {
}
private:
- void doGet(crow::response& res, const crow::request& req,
+ void doGet(crow::Response& res, const crow::Request& req,
const std::vector<std::string>& params) override {
auto session =
- crow::PersistentData::SessionStore::getInstance().get_session_by_uid(
+ crow::persistent_data::SessionStore::getInstance().getSessionByUid(
params[0]);
if (session == nullptr) {
messages::addMessageToErrorJson(
- res.json_value, messages::resourceNotFound("Session", params[0]));
+ res.jsonValue, messages::resourceNotFound("Session", params[0]));
res.result(boost::beast::http::status::not_found);
res.end();
return;
}
- Node::json["Id"] = session->unique_id;
+ Node::json["Id"] = session->uniqueId;
Node::json["UserName"] = session->username;
Node::json["@odata.id"] =
- "/redfish/v1/SessionService/Sessions/" + session->unique_id;
+ "/redfish/v1/SessionService/Sessions/" + session->uniqueId;
- res.json_value = Node::json;
+ res.jsonValue = Node::json;
res.end();
}
- void doDelete(crow::response& res, const crow::request& req,
+ void doDelete(crow::Response& res, const crow::Request& req,
const std::vector<std::string>& params) override {
// Need only 1 param which should be id of session to be deleted
if (params.size() != 1) {
// This should be handled by crow and never happen
- CROW_LOG_ERROR
+ BMCWEB_LOG_ERROR
<< "Session DELETE has been called with invalid number of params";
res.result(boost::beast::http::status::bad_request);
- messages::addMessageToErrorJson(res.json_value, messages::generalError());
+ messages::addMessageToErrorJson(res.jsonValue, messages::generalError());
res.end();
return;
}
auto session =
- crow::PersistentData::SessionStore::getInstance().get_session_by_uid(
+ crow::persistent_data::SessionStore::getInstance().getSessionByUid(
params[0]);
if (session == nullptr) {
messages::addMessageToErrorJson(
- res.json_value, messages::resourceNotFound("Session", params[0]));
+ res.jsonValue, messages::resourceNotFound("Session", params[0]));
res.result(boost::beast::http::status::not_found);
res.end();
@@ -97,7 +97,7 @@ class Sessions : public Node {
// DELETE should return representation of object that will be removed
doGet(res, req, params);
- crow::PersistentData::SessionStore::getInstance().remove_session(session);
+ crow::persistent_data::SessionStore::getInstance().removeSession(session);
}
/**
@@ -131,29 +131,29 @@ class SessionCollection : public Node {
}
private:
- void doGet(crow::response& res, const crow::request& req,
+ void doGet(crow::Response& res, const crow::Request& req,
const std::vector<std::string>& params) override {
- std::vector<const std::string*> session_ids =
- crow::PersistentData::SessionStore::getInstance().get_unique_ids(
- false, crow::PersistentData::PersistenceType::TIMEOUT);
+ std::vector<const std::string*> sessionIds =
+ crow::persistent_data::SessionStore::getInstance().getUniqueIds(
+ false, crow::persistent_data::PersistenceType::TIMEOUT);
- Node::json["Members@odata.count"] = session_ids.size();
+ Node::json["Members@odata.count"] = sessionIds.size();
Node::json["Members"] = nlohmann::json::array();
- for (const std::string* uid : session_ids) {
+ for (const std::string* uid : sessionIds) {
Node::json["Members"].push_back(
{{"@odata.id", "/redfish/v1/SessionService/Sessions/" + *uid}});
}
- res.json_value = Node::json;
+ res.jsonValue = Node::json;
res.end();
}
- void doPost(crow::response& res, const crow::request& req,
+ void doPost(crow::Response& res, const crow::Request& req,
const std::vector<std::string>& params) override {
boost::beast::http::status status;
std::string username;
bool userAuthSuccessful =
- authenticateUser(req, status, username, res.json_value);
+ authenticateUser(req, status, username, res.jsonValue);
res.result(status);
if (!userAuthSuccessful) {
@@ -163,12 +163,12 @@ class SessionCollection : public Node {
// User is authenticated - create session for him
auto session =
- crow::PersistentData::SessionStore::getInstance().generate_user_session(
+ crow::persistent_data::SessionStore::getInstance().generateUserSession(
username);
- res.add_header("X-Auth-Token", session->session_token);
+ res.addHeader("X-Auth-Token", session->sessionToken);
// Return data for created session
- memberSession.doGet(res, req, {session->unique_id});
+ memberSession.doGet(res, req, {session->uniqueId});
// No need for res.end(), as it is called by doGet()
}
@@ -183,15 +183,15 @@ class SessionCollection : public Node {
*
* @return true if authentication was successful, false otherwise
*/
- bool authenticateUser(const crow::request& req,
+ bool authenticateUser(const crow::Request& req,
boost::beast::http::status& httpRespCode,
std::string& user, nlohmann::json& errJson) {
// We need only UserName and Password - nothing more, nothing less
static constexpr const unsigned int numberOfRequiredFieldsInReq = 2;
// call with exceptions disabled
- auto login_credentials = nlohmann::json::parse(req.body, nullptr, false);
- if (login_credentials.is_discarded()) {
+ auto loginCredentials = nlohmann::json::parse(req.body, nullptr, false);
+ if (loginCredentials.is_discarded()) {
httpRespCode = boost::beast::http::status::bad_request;
messages::addMessageToErrorJson(errJson, messages::malformedJSON());
@@ -200,7 +200,7 @@ class SessionCollection : public Node {
}
// Check that there are only as many fields as there should be
- if (login_credentials.size() != numberOfRequiredFieldsInReq) {
+ if (loginCredentials.size() != numberOfRequiredFieldsInReq) {
httpRespCode = boost::beast::http::status::bad_request;
messages::addMessageToErrorJson(errJson, messages::malformedJSON());
@@ -209,18 +209,17 @@ class SessionCollection : public Node {
}
// Find fields that we need - UserName and Password
- auto user_it = login_credentials.find("UserName");
- auto pass_it = login_credentials.find("Password");
- if (user_it == login_credentials.end() ||
- pass_it == login_credentials.end()) {
+ auto userIt = loginCredentials.find("UserName");
+ auto passIt = loginCredentials.find("Password");
+ if (userIt == loginCredentials.end() || passIt == loginCredentials.end()) {
httpRespCode = boost::beast::http::status::bad_request;
- if (user_it == login_credentials.end()) {
+ if (userIt == loginCredentials.end()) {
messages::addMessageToErrorJson(errJson,
messages::propertyMissing("UserName"));
}
- if (pass_it == login_credentials.end()) {
+ if (passIt == loginCredentials.end()) {
messages::addMessageToErrorJson(errJson,
messages::propertyMissing("Password"));
}
@@ -229,27 +228,27 @@ class SessionCollection : public Node {
}
// Check that given data is of valid type (string)
- if (!user_it->is_string() || !pass_it->is_string()) {
+ if (!userIt->is_string() || !passIt->is_string()) {
httpRespCode = boost::beast::http::status::bad_request;
- if (!user_it->is_string()) {
+ if (!userIt->is_string()) {
messages::addMessageToErrorJson(
errJson,
- messages::propertyValueTypeError(user_it->dump(), "UserName"));
+ messages::propertyValueTypeError(userIt->dump(), "UserName"));
}
- if (!pass_it->is_string()) {
+ if (!passIt->is_string()) {
messages::addMessageToErrorJson(
errJson,
- messages::propertyValueTypeError(user_it->dump(), "Password"));
+ messages::propertyValueTypeError(userIt->dump(), "Password"));
}
return false;
}
// Extract username and password
- std::string username = user_it->get<const std::string>();
- std::string password = pass_it->get<const std::string>();
+ std::string username = userIt->get<const std::string>();
+ std::string password = passIt->get<const std::string>();
// Verify that required fields are not empty
if (username.empty() || password.empty()) {
@@ -269,7 +268,7 @@ class SessionCollection : public Node {
}
// Finally - try to authenticate user
- if (!pam_authenticate_user(username, password)) {
+ if (!pamAuthenticateUser(username, password)) {
httpRespCode = boost::beast::http::status::unauthorized;
messages::addMessageToErrorJson(
@@ -304,8 +303,8 @@ class SessionService : public Node {
Node::json["Id"] = "SessionService";
Node::json["Description"] = "Session Service";
Node::json["SessionTimeout"] =
- crow::PersistentData::SessionStore::getInstance()
- .get_timeout_in_seconds();
+ crow::persistent_data::SessionStore::getInstance()
+ .getTimeoutInSeconds();
Node::json["ServiceEnabled"] = true;
entityPrivileges = {
@@ -318,9 +317,9 @@ class SessionService : public Node {
}
private:
- void doGet(crow::response& res, const crow::request& req,
+ void doGet(crow::Response& res, const crow::Request& req,
const std::vector<std::string>& params) override {
- res.json_value = Node::json;
+ res.jsonValue = Node::json;
res.end();
}
};