Dont Reparse Body in HandleInstallTrustBundle
Duplicate parsing of body here
#tlbmc
#bmc-bloom
PiperOrigin-RevId: 822808500
Change-Id: I46ae989dfa690445d243094f4b852154cd37b318
diff --git a/tlbmc/redfish/routes/certificate_service.cc b/tlbmc/redfish/routes/certificate_service.cc
index 699da6a..4aa68ef 100644
--- a/tlbmc/redfish/routes/certificate_service.cc
+++ b/tlbmc/redfish/routes/certificate_service.cc
@@ -29,15 +29,8 @@
namespace {
-void HandleInstallTrustBundle(const RedfishRequest& req,
+void HandleInstallTrustBundle(const nlohmann::json& body,
RedfishResponse& resp) {
- auto body = nlohmann::json::parse(req.Body(), nullptr, false);
- if (body.is_discarded()) {
- resp.SetToAbslStatus(absl::InvalidArgumentError(
- "The request body is missing or malformed."));
- return;
- }
-
const std::string* cert_type =
milotic::authz::GetValueAsString(body, "CertificateType");
if (cert_type == nullptr || *cert_type != "PEM") {
@@ -198,7 +191,7 @@
if (*uri ==
absl::StrCat(kCertificatesPath, "/", kCertificateNameTrustBundle)) {
- HandleInstallTrustBundle(req, resp);
+ HandleInstallTrustBundle(body, resp);
} else if (*uri ==
absl::StrCat(kCertificatesPath, "/", kCertificateNameServerCert)) {
HandleInstallServerCert(req, resp);