summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Grobelny <krzysztof.grobelny@intel.com>2022-08-11 10:52:56 +0300
committerKrzysztof Grobelny <krzysztof.grobelny@intel.com>2022-08-29 12:53:34 +0300
commit9b12d1f9b0cfe4f7f5cf62a3439bbd24a2c08587 (patch)
treee8740bf8053f0b9893be09daea7190271c72cb7f
parent0e643a099e82cf0a8da397b1be2a985e27f0344f (diff)
downloadbmcweb-9b12d1f9b0cfe4f7f5cf62a3439bbd24a2c08587.tar.xz
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 <krzysztof.grobelny@intel.com>
-rw-r--r--redfish-core/lib/certificate_service.hpp129
1 files 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 <app.hpp>
#include <async_resp.hpp>
#include <boost/system/linux_error.hpp>
@@ -7,6 +9,8 @@
#include <http_response.hpp>
#include <query.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
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<std::string>* 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<std::string>(&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<std::string>* value =
- std::get_if<std::vector<std::string>>(&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<std::string>(&property.second);
- if (value != nullptr)
- {
- updateCertIssuerOrSubject(
- asyncResp->res.jsonValue["Issuer"], *value);
- }
- }
- else if (property.first == "Subject")
- {
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value != nullptr)
- {
- updateCertIssuerOrSubject(
- asyncResp->res.jsonValue["Subject"], *value);
- }
- }
- else if (property.first == "ValidNotAfter")
- {
- const uint64_t* value = std::get_if<uint64_t>(&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<uint64_t>(&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);
+ });
}
/**