From 9b12d1f9b0cfe4f7f5cf62a3439bbd24a2c08587 Mon Sep 17 00:00:00 2001 From: Krzysztof Grobelny Date: Thu, 11 Aug 2022 09:52:56 +0200 Subject: used sdbusplus::unpackPropertiesNoThrow part 4 used sdbusplus::unpackPropertiesNoThrow in certificate_service.hpp, also replaced all usages of "GetAll" with sdbusplus::asio::getAllProperties bmcweb size: 2668888 -> 2664776 (-4112) compressed size: 1127280 -> 1125100 (-2180) Tested: Performed get on: - /redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/1 Get result before and after the change was in same format, values for: ValidNotAfter, ValidNotBefore and CertificateString were different (but it is expected behaiour) Change-Id: If94adea317dea18cb984788dc1515778ce4097c6 Signed-off-by: Krzysztof Grobelny --- redfish-core/lib/certificate_service.hpp | 129 +++++++++++++++---------------- 1 file changed, 62 insertions(+), 67 deletions(-) diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp index 471b45a25a..c2a3dd672b 100644 --- a/redfish-core/lib/certificate_service.hpp +++ b/redfish-core/lib/certificate_service.hpp @@ -1,5 +1,7 @@ #pragma once +#include "utils/dbus_utils.hpp" + #include #include #include @@ -7,6 +9,8 @@ #include #include #include +#include +#include namespace redfish { @@ -622,7 +626,8 @@ static void getCertificateProperties( { BMCWEB_LOG_DEBUG << "getCertificateProperties Path=" << objectPath << " certId=" << certId << " certURl=" << certURL; - crow::connections::systemBus->async_method_call( + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, service, objectPath, certs::certPropIntf, [asyncResp, certURL, certId, name](const boost::system::error_code ec, const dbus::utility::DBusPropertiesMap& properties) { @@ -632,83 +637,73 @@ static void getCertificateProperties( messages::resourceNotFound(asyncResp->res, name, certId); return; } + + const std::string* certificateString = nullptr; + const std::vector* keyUsage = nullptr; + const std::string* issuer = nullptr; + const std::string* subject = nullptr; + const uint64_t* validNotAfter = nullptr; + const uint64_t* validNotBefore = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), properties, "CertificateString", + certificateString, "KeyUsage", keyUsage, "Issuer", issuer, + "Subject", subject, "ValidNotAfter", validNotAfter, + "ValidNotBefore", validNotBefore); + + if (!success) + { + messages::internalError(asyncResp->res); + return; + } + asyncResp->res.jsonValue["@odata.id"] = certURL; asyncResp->res.jsonValue["@odata.type"] = "#Certificate.v1_0_0.Certificate"; asyncResp->res.jsonValue["Id"] = certId; asyncResp->res.jsonValue["Name"] = name; asyncResp->res.jsonValue["Description"] = name; - for (const auto& property : properties) + asyncResp->res.jsonValue["CertificateString"] = ""; + asyncResp->res.jsonValue["KeyUsage"] = nlohmann::json::array(); + + if (certificateString != nullptr) { - if (property.first == "CertificateString") - { - asyncResp->res.jsonValue["CertificateString"] = ""; - const std::string* value = - std::get_if(&property.second); - if (value != nullptr) - { - asyncResp->res.jsonValue["CertificateString"] = *value; - } - } - else if (property.first == "KeyUsage") - { - nlohmann::json& keyUsage = asyncResp->res.jsonValue["KeyUsage"]; - keyUsage = nlohmann::json::array(); - const std::vector* value = - std::get_if>(&property.second); - if (value != nullptr) - { - for (const std::string& usage : *value) - { - keyUsage.push_back(usage); - } - } - } - else if (property.first == "Issuer") - { - const std::string* value = - std::get_if(&property.second); - if (value != nullptr) - { - updateCertIssuerOrSubject( - asyncResp->res.jsonValue["Issuer"], *value); - } - } - else if (property.first == "Subject") - { - const std::string* value = - std::get_if(&property.second); - if (value != nullptr) - { - updateCertIssuerOrSubject( - asyncResp->res.jsonValue["Subject"], *value); - } - } - else if (property.first == "ValidNotAfter") - { - const uint64_t* value = std::get_if(&property.second); - if (value != nullptr) - { - asyncResp->res.jsonValue["ValidNotAfter"] = - redfish::time_utils::getDateTimeUint(*value); - } - } - else if (property.first == "ValidNotBefore") - { - const uint64_t* value = std::get_if(&property.second); - if (value != nullptr) - { - asyncResp->res.jsonValue["ValidNotBefore"] = - redfish::time_utils::getDateTimeUint(*value); - } - } + asyncResp->res.jsonValue["CertificateString"] = *certificateString; + } + + if (keyUsage != nullptr) + { + asyncResp->res.jsonValue["KeyUsage"] = *keyUsage; + } + + if (issuer != nullptr) + { + updateCertIssuerOrSubject(asyncResp->res.jsonValue["Issuer"], + *issuer); + } + + if (subject != nullptr) + { + updateCertIssuerOrSubject(asyncResp->res.jsonValue["Subject"], + *subject); + } + + if (validNotAfter != nullptr) + { + asyncResp->res.jsonValue["ValidNotAfter"] = + redfish::time_utils::getDateTimeUint(*validNotAfter); } + + if (validNotBefore != nullptr) + { + asyncResp->res.jsonValue["ValidNotBefore"] = + redfish::time_utils::getDateTimeUint(*validNotBefore); + } + asyncResp->res.addHeader( boost::beast::http::field::location, std::string_view(certURL.data(), certURL.size())); - }, - service, objectPath, certs::dbusPropIntf, "GetAll", - certs::certPropIntf); + }); } /** -- cgit v1.2.3