Implement OriginatedBy interface in dump entry dbus obj
This new interface "OriginatedBy" will be implemented
by all the dump entry dbus objects. It contains a property
"OriginatorId" which stores the unique id of the user that
has initiated the dump. The unique id in this case is a string
that contains the ip address of the client that initiated
the dump.
The dbus interface change for the same is at:
[1] https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-dbus-interfaces/+/47057
Tested By:
[1] busctl call xyz.openbmc_project.Dump.Manager /xyz/openbmc_project/dump/bmc xyz.openbmc_project.Dump.Create CreateDump a{sv} 2 "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorId" s "<unique-id>" "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType" s "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client" o "/xyz/openbmc_project/dump/bmc/entry/2"
[2] busctl --verbose call xyz.openbmc_project.Dump.Manager /xyz/openbmc_project/dump/resource xyz.openbmc_project.Dump.Create CreateDump a{sv} 4 "com.ibm.Dump.Create.CreateParameters.VSPString" s "vsp" "com.ibm.Dump.Create.CreateParameters.Password" s "password" "com.ibm.Dump.Create.CreateParameters.OriginatorId" s "<unique-id>" "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType" s "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client"
MESSAGE "o" {
OBJECT_PATH "/xyz/openbmc_project/dump/resource/entry/1";
};
[3] busctl call xyz.openbmc_project.Dump.Manager /xyz/openbmc_project/dump/system xyz.openbmc_project.Dump.Create CreateDump a{sv} 2 "com.ibm.Dump.Create.CreateParameters.OriginatorId" s "<unique-id>" "xyz.openbmc_project.Dump.Create.CreateParameters.OriginatorType" s "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Client" o "/xyz/openbmc_project/dump/system/entry/1"
Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: I23c9f769fd39cd84e042d6effbb3d71c7af4e889
diff --git a/dump_utils.hpp b/dump_utils.hpp
index 1a18844..6661bd4 100644
--- a/dump_utils.hpp
+++ b/dump_utils.hpp
@@ -1,9 +1,17 @@
#pragma once
+#include "dump_manager.hpp"
+
+#include <fmt/core.h>
#include <systemd/sd-event.h>
#include <unistd.h>
+#include <com/ibm/Dump/Create/server.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
#include <sdbusplus/bus.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/Dump/Create/server.hpp>
#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
#include <memory>
@@ -16,6 +24,9 @@
using BootProgress = sdbusplus::xyz::openbmc_project::State::Boot::server::
Progress::ProgressStages;
+using namespace phosphor::logging;
+using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+
/* Need a custom deleter for freeing up sd_event */
struct EventDeleter
{
@@ -92,5 +103,72 @@
*/
bool isHostRunning();
+inline void extractOriginatorProperties(phosphor::dump::DumpCreateParams params,
+ std::string& originatorId,
+ originatorTypes& originatorType)
+{
+ using InvalidArgument =
+ sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
+ using Argument = xyz::openbmc_project::Common::InvalidArgument;
+ using CreateParametersXYZ =
+ sdbusplus::xyz::openbmc_project::Dump::server::Create::CreateParameters;
+
+ auto iter = params.find(
+ sdbusplus::xyz::openbmc_project::Dump::server::Create::
+ convertCreateParametersToString(CreateParametersXYZ::OriginatorId));
+ if (iter == params.end())
+ {
+ log<level::INFO>("OriginatorId is not provided");
+ }
+ else
+ {
+ try
+ {
+ originatorId = std::get<std::string>(iter->second);
+ }
+ catch (const std::bad_variant_access& e)
+ {
+ // Exception will be raised if the input is not string
+ log<level::ERR>(
+ fmt::format(
+ "An invalid originatorId passed. It should be a string, "
+ "errormsg({})",
+ e.what())
+ .c_str());
+ elog<InvalidArgument>(Argument::ARGUMENT_NAME("ORIGINATOR_ID"),
+ Argument::ARGUMENT_VALUE("INVALID INPUT"));
+ }
+ }
+
+ iter = params.find(sdbusplus::xyz::openbmc_project::Dump::server::Create::
+ convertCreateParametersToString(
+ CreateParametersXYZ::OriginatorType));
+ if (iter == params.end())
+ {
+ log<level::INFO>("OriginatorType is not provided. Replacing the string "
+ "with the default value");
+ originatorType = originatorTypes::Internal;
+ }
+ else
+ {
+ try
+ {
+ std::string type = std::get<std::string>(iter->second);
+ originatorType = sdbusplus::xyz::openbmc_project::Common::server::
+ OriginatedBy::convertOriginatorTypesFromString(type);
+ }
+ catch (const std::bad_variant_access& e)
+ {
+ // Exception will be raised if the input is not string
+ log<level::ERR>(fmt::format("An invalid originatorType passed, "
+ "errormsg({})",
+ e.what())
+ .c_str());
+ elog<InvalidArgument>(Argument::ARGUMENT_NAME("ORIGINATOR_TYPE"),
+ Argument::ARGUMENT_VALUE("INVALID INPUT"));
+ }
+ }
+}
+
} // namespace dump
} // namespace phosphor