summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0017-Add-MutualExclusiveProperties-registry.patch
blob: 2b510e0b56f03b2bff5299bc4a29afaff30ddc25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
From 891a0a2deb616b7e3f135b5df8501947ce5d6ad4 Mon Sep 17 00:00:00 2001
From: AppaRao Puli <apparao.puli@linux.intel.com>
Date: Tue, 8 Sep 2020 01:53:21 +0530
Subject: [PATCH] Add MutualExclusiveProperties registry

Add MutualExclusiveProperties message registry entry
and error message.
As per redfish specification, "RegistryPrefixes" and
"MessageIds" are mutually exclusive. So add check for
same in EventService and return MutualExclusiveProperties
error message.

Tested:
 - Create subscription failed with error(bad request)
   when the request body contain both "RegistryPrefixes"
   and "MessageIds".

Change-Id: I4c14f946977bce2ced8a7f96eb85855117fde9a8
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
---
 redfish-core/include/error_messages.hpp            | 14 +++++++++++
 .../include/registries/base_message_registry.hpp   | 18 +++++++++++++-
 redfish-core/lib/event_service.hpp                 | 10 ++++++++
 redfish-core/src/error_messages.cpp                | 29 ++++++++++++++++++++++
 4 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index 0243be9..9a2d1ca 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -787,6 +787,20 @@ nlohmann::json invalidUpload(const std::string& arg1, const std::string& arg2);
 void invalidUpload(crow::Response& res, const std::string& arg1,
                    const std::string& arg2);
 
+/**
+ * @brief Formats MutualExclusiveProperties message into JSON
+ * Message body: "The properties <arg1> and <arg2> are mutually exclusive."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ * @param[in] arg2 Parameter of message that will replace %2 in its body.
+ *
+ * @returns Message MutualExclusiveProperties formatted to JSON */
+nlohmann::json mutualExclusiveProperties(const std::string& arg1,
+                                         const std::string& arg2);
+
+void mutualExclusiveProperties(crow::Response& res, const std::string& arg1,
+                               const std::string& arg2);
+
 } // namespace messages
 
 } // namespace redfish
diff --git a/redfish-core/include/registries/base_message_registry.hpp b/redfish-core/include/registries/base_message_registry.hpp
index 90aef56..7c385a0 100644
--- a/redfish-core/include/registries/base_message_registry.hpp
+++ b/redfish-core/include/registries/base_message_registry.hpp
@@ -36,7 +36,7 @@ const Header header = {
 constexpr const char* url =
     "https://redfish.dmtf.org/registries/Base.1.8.1.json";
 
-constexpr std::array<MessageEntry, 73> registry = {
+constexpr std::array<MessageEntry, 74> registry = {
     MessageEntry{
         "AccessDenied",
         {
@@ -429,6 +429,22 @@ constexpr std::array<MessageEntry, 73> registry = {
             "Resolve other reported errors and retry the current operation.",
         }},
     MessageEntry{
+        "MutualExclusiveProperties",
+        {
+            "Indicates that the requested operation could not be completed, "
+            "because of a conflict properties.",
+            "The properties '%1' and '%2' are mutually exclusive.",
+            "Warning",
+            "Warning",
+            2,
+            {
+                "string",
+                "string",
+            },
+            "Ensure that the request body doesn't have mutually exclusive "
+            "properties and resubmit the request.",
+        }},
+    MessageEntry{
         "NoOperation",
         {
             "Indicates that the requested operation will not perform any "
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index f59d093..4804d26 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -242,6 +242,16 @@ class EventDestinationCollection : public Node
             return;
         }
 
+        if (regPrefixes && msgIds)
+        {
+            if (regPrefixes->size() && msgIds->size())
+            {
+                messages::mutualExclusiveProperties(
+                    asyncResp->res, "RegistryPrefixes", "MessageIds");
+                return;
+            }
+        }
+
         // Validate the URL using regex expression
         // Format: <protocol>://<host>:<port>/<uri>
         // protocol: http/https
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index 160b73f..c6938ba 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -1750,6 +1750,35 @@ nlohmann::json invalidUpload(const std::string& arg1, const std::string& arg2)
         {"Resolution", "None."}};
 }
 
+/**
+ * @internal
+ * @brief Formats MutualExclusiveProperties into JSON
+ *
+ * See header file for more information
+ * @endinternal
+ */
+nlohmann::json mutualExclusiveProperties(const std::string& arg1,
+                                         const std::string& arg2)
+{
+    return nlohmann::json{
+        {"@odata.type", "#Message.v1_0_0.Message"},
+        {"MessageId", "Base.1.5.0.MutualExclusiveProperties"},
+        {"Message", "The properties " + arg1 + " and " + arg2 +
+                        " are mutually exclusive."},
+        {"MessageArgs", {arg1, arg2}},
+        {"Severity", "Warning"},
+        {"Resolution",
+         "Ensure that the request body doesn't contain mutually exclusive "
+         "properties and resubmit the request."}};
+}
+
+void mutualExclusiveProperties(crow::Response& res, const std::string& arg1,
+                               const std::string& arg2)
+{
+    res.result(boost::beast::http::status::bad_request);
+    addMessageToErrorJson(res.jsonValue, mutualExclusiveProperties(arg1, arg2));
+}
+
 } // namespace messages
 
 } // namespace redfish
-- 
2.7.4