diff options
author | Jiaqing Zhao <jiaqing.zhao@intel.com> | 2022-06-14 07:58:09 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-08-04 19:50:25 +0300 |
commit | 1e31259812dd195015f4e415675ed97b804829a6 (patch) | |
tree | 0a4c3d116616075a1bcf7058c5a907f778f732c4 | |
parent | 13548d8598b164684d40f62d6a875f164593f509 (diff) | |
download | bmcweb-1e31259812dd195015f4e415675ed97b804829a6.tar.xz |
certificate: Use urlFromPieces to generate URL
urlFromPieces is a better way for generating URLs as it automatically
escapes special characters. Use it.
Tested:
Verified reading and uploading certificates are responded with correct
URL to the certificate, and Redfish Service Validator passed.
Change-Id: I7a4fb76d0a0baa2dacff192973aa61b478e91158
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
-rw-r--r-- | redfish-core/lib/certificate_service.hpp | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp index 6da91ff65e..9e958cb98c 100644 --- a/redfish-core/lib/certificate_service.hpp +++ b/redfish-core/lib/certificate_service.hpp @@ -615,7 +615,7 @@ static void static void getCertificateProperties( const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& objectPath, const std::string& service, - const std::string& certId, const std::string& certURL, + const std::string& certId, const boost::urls::url& certURL, const std::string& name) { BMCWEB_LOG_DEBUG << "getCertificateProperties Path=" << objectPath @@ -701,7 +701,8 @@ static void getCertificateProperties( } } } - asyncResp->res.addHeader("Location", certURL); + asyncResp->res.addHeader( + "Location", std::string_view(certURL.data(), certURL.size())); }, service, objectPath, certs::dbusPropIntf, "GetAll", certs::certPropIntf); @@ -811,7 +812,7 @@ inline void requestRoutesCertificateActionsReplaceCertificate(App& app) std::shared_ptr<CertificateFile> certFile = std::make_shared<CertificateFile>(certificate); crow::connections::systemBus->async_method_call( - [asyncResp, certFile, objectPath, service, certURI, id, + [asyncResp, certFile, objectPath, service, url{*parsedUrl}, id, name](const boost::system::error_code ec) { if (ec) { @@ -825,8 +826,8 @@ inline void requestRoutesCertificateActionsReplaceCertificate(App& app) messages::internalError(asyncResp->res); return; } - getCertificateProperties(asyncResp, objectPath, service, id, - certURI, name); + getCertificateProperties(asyncResp, objectPath, service, id, url, + name); BMCWEB_LOG_DEBUG << "HTTPS certificate install file=" << certFile->getCertFilePath(); }, @@ -846,26 +847,26 @@ inline void requestRoutesHTTPSCertificate(App& app) app, "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/<str>/") .privileges(redfish::privileges::getCertificate) - .methods( - boost::beast::http::verb:: - get)([&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& id) -> void { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } + .methods(boost::beast::http::verb::get)( + [&app](const crow::Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& id) -> void { + if (!redfish::setUpRedfishRoute(app, req, asyncResp)) + { + return; + } - BMCWEB_LOG_DEBUG << "HTTPS Certificate ID=" << id; - std::string certURL = - "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/" + - id; - std::string objPath = - sdbusplus::message::object_path(certs::httpsObjectPath) / id; - getCertificateProperties(asyncResp, objPath, - certs::httpsServiceName, id, certURL, - "HTTPS Certificate"); - }); + BMCWEB_LOG_DEBUG << "HTTPS Certificate ID=" << id; + const boost::urls::url certURL = crow::utility::urlFromPieces( + "redfish", "v1", "Managers", "bmc", "NetworkProtocol", + "HTTPS", "Certificates", id); + std::string objPath = + sdbusplus::message::object_path(certs::httpsObjectPath) / + id; + getCertificateProperties(asyncResp, objPath, + certs::httpsServiceName, id, certURL, + "HTTPS Certificate"); + }); } /** @@ -936,9 +937,9 @@ inline void requestRoutesHTTPSCertificateCollection(App& app) sdbusplus::message::object_path path(objectPath); std::string certId = path.filename(); - std::string certURL = - "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/" + - certId; + const boost::urls::url certURL = crow::utility::urlFromPieces( + "redfish", "v1", "Managers", "bmc", "NetworkProtocol", "HTTPS", + "Certificates", certId); getCertificateProperties(asyncResp, objectPath, certs::httpsServiceName, certId, certURL, "HTTPS Certificate"); @@ -1043,8 +1044,9 @@ inline void requestRoutesLDAPCertificateCollection(App& app) sdbusplus::message::object_path path(objectPath); std::string certId = path.filename(); - std::string certURL = - "/redfish/v1/AccountService/LDAP/Certificates/" + certId; + const boost::urls::url certURL = + crow::utility::urlFromPieces("redfish", "v1", "AccountService", + "LDAP", "Certificates", certId); getCertificateProperties(asyncResp, objectPath, certs::ldapServiceName, certId, certURL, "LDAP Certificate"); @@ -1074,8 +1076,8 @@ inline void requestRoutesLDAPCertificate(App& app) } BMCWEB_LOG_DEBUG << "LDAP Certificate ID=" << id; - std::string certURL = - "/redfish/v1/AccountService/LDAP/Certificates/" + id; + const boost::urls::url certURL = crow::utility::urlFromPieces( + "redfish", "v1", "AccountService", "LDAP", "Certificates", id); std::string objPath = sdbusplus::message::object_path(certs::ldapObjectPath) / id; getCertificateProperties(asyncResp, objPath, certs::ldapServiceName, id, @@ -1142,8 +1144,9 @@ inline void requestRoutesTrustStoreCertificateCollection(App& app) sdbusplus::message::object_path path(objectPath); std::string certId = path.filename(); - std::string certURL = - "/redfish/v1/Managers/bmc/Truststore/Certificates/" + certId; + const boost::urls::url certURL = crow::utility::urlFromPieces( + "redfish", "v1", "Managers", "bmc", "Truststore", + "Certificates", certId); getCertificateProperties(asyncResp, objectPath, certs::authorityServiceName, certId, certURL, "TrustStore Certificate"); @@ -1173,8 +1176,9 @@ inline void requestRoutesTrustStoreCertificate(App& app) } BMCWEB_LOG_DEBUG << "Truststore Certificate ID=" << id; - std::string certURL = - "/redfish/v1/Managers/bmc/Truststore/Certificates/" + id; + const boost::urls::url certURL = + crow::utility::urlFromPieces("redfish", "v1", "Managers", "bmc", + "Truststore", "Certificates", id); std::string objPath = sdbusplus::message::object_path(certs::authorityObjectPath) / id; getCertificateProperties(asyncResp, objPath, |