diff options
author | Ed Tanous <ed.tanous@intel.com> | 2018-11-12 22:11:15 +0300 |
---|---|---|
committer | Ed Tanous <ed.tanous@intel.com> | 2018-11-20 20:18:23 +0300 |
commit | f839dfee32b930537d2d198f4bf236ff03b7581d (patch) | |
tree | fabd4546ec24653fac0c1f17ad9501f60c06c01a /include/openbmc_dbus_rest.hpp | |
parent | b1556427d980393a9c93f84faaccbd6376022f9a (diff) | |
download | bmcweb-f839dfee32b930537d2d198f4bf236ff03b7581d.tar.xz |
bmcweb:Properly implement the / operator in dbus
Per the documentation here:
https://github.com/openbmc/docs/blob/master/rest-api.md
It states:
"When a path has a trailing-slash, the response will list the sub
objects of the URL. For example, using the same object path as above,
but adding a slash"
This subtlety was missed by the original author of this stuff, and as
such, didn't work the way the old APIs were expecting.
Tested By:
HTTP GET /xyz/openbmc_project/
Before this patchset, returns an empty object
{
"data": [],
"message": "200 OK",
"status": "ok"
}
After this patchset, returns:
{
"data": [
"/xyz/openbmc_project/EntityManager",
"/xyz/openbmc_project/FruDevice",
"/xyz/openbmc_project/bios",
"/xyz/openbmc_project/control",
"/xyz/openbmc_project/dump",
"/xyz/openbmc_project/events",
"/xyz/openbmc_project/inventory",
"/xyz/openbmc_project/logging",
"/xyz/openbmc_project/network",
"/xyz/openbmc_project/object_mapper",
"/xyz/openbmc_project/software",
"/xyz/openbmc_project/user"
],
"message": "200 OK",
"status": "ok"
}
Note, to get the exact same responses (which don't include the root
object) this patchset is required:
https://gerrit.openbmc-project.xyz/#/c/openbmc/phosphor-objmgr/+/15545/
Change-Id: I79b192bc26879cdfa25977f403940d3608eb3e22
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Diffstat (limited to 'include/openbmc_dbus_rest.hpp')
-rw-r--r-- | include/openbmc_dbus_rest.hpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index 6cdc24bc2a..c242539843 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -735,7 +735,8 @@ void handleAction(const crow::Request &req, crow::Response &res, std::array<std::string, 0>()); } -void handleList(crow::Response &res, const std::string &objectPath) +void handleList(crow::Response &res, const std::string &objectPath, + int32_t depth = 0) { crow::connections::systemBus->async_method_call( [&res](const boost::system::error_code ec, @@ -755,7 +756,7 @@ void handleList(crow::Response &res, const std::string &objectPath) "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", objectPath, - static_cast<int32_t>(0), std::array<std::string, 0>()); + depth, std::array<std::string, 0>()); } void handleEnumerate(crow::Response &res, const std::string &objectPath) @@ -1132,11 +1133,6 @@ void handlePut(const crow::Request &req, crow::Response &res, inline void handleDBusUrl(const crow::Request &req, crow::Response &res, std::string &objectPath) { - // Trim any trailing "/" at the end - if (boost::ends_with(objectPath, "/")) - { - objectPath.pop_back(); - } // If accessing a single attribute, fill in and update objectPath, // otherwise leave destProperty blank @@ -1180,7 +1176,16 @@ inline void handleDBusUrl(const crow::Request &req, crow::Response &res, } else { - handleGet(res, objectPath, destProperty); + // Trim any trailing "/" at the end + if (boost::ends_with(objectPath, "/")) + { + objectPath.pop_back(); + handleList(res, objectPath, 1); + } + else + { + handleGet(res, objectPath, destProperty); + } } return; } |