blob: f1d6f5007d79cb58427d45eb6413afe547ee3e04 [file] [log] [blame]
AppaRao Pulie5aaf042020-03-20 01:05:52 +05301/*
2// Copyright (c) 2020 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
AppaRao Pulib52664e2020-04-09 21:36:51 +053017#include "event_service_manager.hpp"
AppaRao Pulie5aaf042020-03-20 01:05:52 +053018
John Edward Broadbent7e860f12021-04-08 15:57:16 -070019#include <app.hpp>
Ed Tanoused398212021-06-09 17:05:54 -070020#include <registries/privilege_registry.hpp>
21
AppaRao Pulie5aaf042020-03-20 01:05:52 +053022namespace redfish
23{
24
AppaRao Puli156d6b02020-04-25 06:04:05 +053025static constexpr const std::array<const char*, 2> supportedEvtFormatTypes = {
26 eventFormatType, metricReportFormatType};
AppaRao Pulie5aaf042020-03-20 01:05:52 +053027static constexpr const std::array<const char*, 3> supportedRegPrefixes = {
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +053028 "Base", "OpenBMC", "TaskEvent"};
AppaRao Pulie5aaf042020-03-20 01:05:52 +053029static constexpr const std::array<const char*, 3> supportedRetryPolicies = {
30 "TerminateAfterRetries", "SuspendRetries", "RetryForever"};
31
Sunitha Harishe56f2542020-07-22 02:38:59 -050032#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
33static constexpr const std::array<const char*, 2> supportedResourceTypes = {
34 "IBMConfigFile", "Task"};
35#else
36static constexpr const std::array<const char*, 1> supportedResourceTypes = {
37 "Task"};
38#endif
39
AppaRao Pulie5aaf042020-03-20 01:05:52 +053040static constexpr const uint8_t maxNoOfSubscriptions = 20;
41
John Edward Broadbent7e860f12021-04-08 15:57:16 -070042inline void requestRoutesEventService(App& app)
AppaRao Pulie5aaf042020-03-20 01:05:52 +053043{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070044 BMCWEB_ROUTE(app, "/redfish/v1/EventService/")
Ed Tanoused398212021-06-09 17:05:54 -070045 .privileges(redfish::privileges::getEventService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070046 .methods(boost::beast::http::verb::get)(
47 [](const crow::Request&,
48 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
49 asyncResp->res.jsonValue = {
50 {"@odata.type", "#EventService.v1_5_0.EventService"},
51 {"Id", "EventService"},
52 {"Name", "Event Service"},
53 {"Subscriptions",
54 {{"@odata.id", "/redfish/v1/EventService/Subscriptions"}}},
55 {"Actions",
56 {{"#EventService.SubmitTestEvent",
57 {{"target", "/redfish/v1/EventService/Actions/"
58 "EventService.SubmitTestEvent"}}}}},
59 {"@odata.id", "/redfish/v1/EventService"}};
AppaRao Pulie5aaf042020-03-20 01:05:52 +053060
JunLin Chen28afb492021-02-24 17:13:29 +080061 const persistent_data::EventServiceConfig eventServiceConfig =
62 persistent_data::EventServiceStore::getInstance()
63 .getEventServiceConfig();
zhanghch058d1b46d2021-04-01 11:18:24 +080064
John Edward Broadbent7e860f12021-04-08 15:57:16 -070065 asyncResp->res.jsonValue["Status"]["State"] =
JunLin Chen28afb492021-02-24 17:13:29 +080066 (eventServiceConfig.enabled ? "Enabled" : "Disabled");
67 asyncResp->res.jsonValue["ServiceEnabled"] =
68 eventServiceConfig.enabled;
John Edward Broadbent7e860f12021-04-08 15:57:16 -070069 asyncResp->res.jsonValue["DeliveryRetryAttempts"] =
JunLin Chen28afb492021-02-24 17:13:29 +080070 eventServiceConfig.retryAttempts;
John Edward Broadbent7e860f12021-04-08 15:57:16 -070071 asyncResp->res.jsonValue["DeliveryRetryIntervalSeconds"] =
JunLin Chen28afb492021-02-24 17:13:29 +080072 eventServiceConfig.retryTimeoutInterval;
John Edward Broadbent7e860f12021-04-08 15:57:16 -070073 asyncResp->res.jsonValue["EventFormatTypes"] =
74 supportedEvtFormatTypes;
75 asyncResp->res.jsonValue["RegistryPrefixes"] =
76 supportedRegPrefixes;
77 asyncResp->res.jsonValue["ResourceTypes"] =
78 supportedResourceTypes;
AppaRao Pulie5aaf042020-03-20 01:05:52 +053079
John Edward Broadbent7e860f12021-04-08 15:57:16 -070080 nlohmann::json supportedSSEFilters = {
81 {"EventFormatType", true}, {"MessageId", true},
82 {"MetricReportDefinition", true}, {"RegistryPrefix", true},
83 {"OriginResource", false}, {"ResourceType", false}};
AppaRao Puli7d1cc382020-05-16 02:42:22 +053084
John Edward Broadbent7e860f12021-04-08 15:57:16 -070085 asyncResp->res.jsonValue["SSEFilterPropertiesSupported"] =
86 supportedSSEFilters;
87 });
Ayushi Smriti07941a82020-05-21 15:55:34 +053088
John Edward Broadbent7e860f12021-04-08 15:57:16 -070089 BMCWEB_ROUTE(app, "/redfish/v1/EventService/")
Ed Tanoused398212021-06-09 17:05:54 -070090 .privileges(redfish::privileges::patchEventService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070091 .methods(boost::beast::http::verb::patch)(
92 [](const crow::Request& req,
93 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ayushi Smriti07941a82020-05-21 15:55:34 +053094
AppaRao Pulie5aaf042020-03-20 01:05:52 +053095 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -070096 std::optional<bool> serviceEnabled;
97 std::optional<uint32_t> retryAttemps;
98 std::optional<uint32_t> retryInterval;
AppaRao Pulie5aaf042020-03-20 01:05:52 +053099
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700100 if (!json_util::readJson(
101 req, asyncResp->res, "ServiceEnabled", serviceEnabled,
102 "DeliveryRetryAttempts", retryAttemps,
103 "DeliveryRetryIntervalSeconds", retryInterval))
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530104 {
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530105 return;
106 }
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530107
JunLin Chen28afb492021-02-24 17:13:29 +0800108 persistent_data::EventServiceConfig eventServiceConfig =
109 persistent_data::EventServiceStore::getInstance()
110 .getEventServiceConfig();
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700111
112 if (serviceEnabled)
Sunitha Harishe56f2542020-07-22 02:38:59 -0500113 {
JunLin Chen28afb492021-02-24 17:13:29 +0800114 eventServiceConfig.enabled = *serviceEnabled;
Sunitha Harishe56f2542020-07-22 02:38:59 -0500115 }
Sunitha Harishe56f2542020-07-22 02:38:59 -0500116
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700117 if (retryAttemps)
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530118 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700119 // Supported range [1-3]
120 if ((*retryAttemps < 1) || (*retryAttemps > 3))
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530121 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700122 messages::queryParameterOutOfRange(
123 asyncResp->res, std::to_string(*retryAttemps),
124 "DeliveryRetryAttempts", "[1-3]");
125 }
126 else
127 {
JunLin Chen28afb492021-02-24 17:13:29 +0800128 eventServiceConfig.retryAttempts = *retryAttemps;
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530129 }
130 }
131
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700132 if (retryInterval)
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530133 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700134 // Supported range [30 - 180]
135 if ((*retryInterval < 30) || (*retryInterval > 180))
136 {
137 messages::queryParameterOutOfRange(
138 asyncResp->res, std::to_string(*retryInterval),
139 "DeliveryRetryIntervalSeconds", "[30-180]");
140 }
141 else
142 {
JunLin Chen28afb492021-02-24 17:13:29 +0800143 eventServiceConfig.retryTimeoutInterval =
144 *retryInterval;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700145 }
146 }
147
148 EventServiceManager::getInstance().setEventServiceConfig(
JunLin Chen28afb492021-02-24 17:13:29 +0800149 eventServiceConfig);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700150 });
151}
152
153inline void requestRoutesSubmitTestEvent(App& app)
154{
155
156 BMCWEB_ROUTE(
157 app, "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent/")
Ed Tanoused398212021-06-09 17:05:54 -0700158 .privileges(redfish::privileges::postEventService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700159 .methods(boost::beast::http::verb::post)(
160 [](const crow::Request&,
161 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
162 EventServiceManager::getInstance().sendTestEventLog();
163 asyncResp->res.result(boost::beast::http::status::no_content);
164 });
165}
166
167inline void requestRoutesEventDestinationCollection(App& app)
168{
169 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions")
Ed Tanoused398212021-06-09 17:05:54 -0700170 .privileges(redfish::privileges::getEventDestinationCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700171 .methods(boost::beast::http::verb::get)(
172 [](const crow::Request&,
173 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
174 asyncResp->res.jsonValue = {
175 {"@odata.type",
176 "#EventDestinationCollection.EventDestinationCollection"},
177 {"@odata.id", "/redfish/v1/EventService/Subscriptions"},
178 {"Name", "Event Destination Collections"}};
179
180 nlohmann::json& memberArray =
181 asyncResp->res.jsonValue["Members"];
182
183 std::vector<std::string> subscripIds =
184 EventServiceManager::getInstance().getAllIDs();
185 memberArray = nlohmann::json::array();
186 asyncResp->res.jsonValue["Members@odata.count"] =
187 subscripIds.size();
188
189 for (const std::string& id : subscripIds)
190 {
191 memberArray.push_back(
192 {{"@odata.id",
193 "/redfish/v1/EventService/Subscriptions/" + id}});
194 }
195 });
196 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/")
Ed Tanoused398212021-06-09 17:05:54 -0700197 // The below privilege is wrong, it should be ConfigureManager OR
198 // ConfigureComponents
199 //.privileges(redfish::privileges::postEventDestinationCollection)
Ed Tanous432a8902021-06-14 15:28:56 -0700200 .privileges({{"ConfigureManager"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700201 .methods(boost::beast::http::verb::post)(
202 [](const crow::Request& req,
203 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
204 if (EventServiceManager::getInstance()
205 .getNumberOfSubscriptions() >= maxNoOfSubscriptions)
206 {
207 messages::eventSubscriptionLimitExceeded(asyncResp->res);
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530208 return;
209 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700210 std::string destUrl;
211 std::string protocol;
212 std::optional<std::string> context;
213 std::optional<std::string> subscriptionType;
214 std::optional<std::string> eventFormatType2;
215 std::optional<std::string> retryPolicy;
216 std::optional<std::vector<std::string>> msgIds;
217 std::optional<std::vector<std::string>> regPrefixes;
218 std::optional<std::vector<std::string>> resTypes;
219 std::optional<std::vector<nlohmann::json>> headers;
220 std::optional<std::vector<nlohmann::json>> mrdJsonArray;
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530221
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700222 if (!json_util::readJson(
223 req, asyncResp->res, "Destination", destUrl, "Context",
224 context, "Protocol", protocol, "SubscriptionType",
225 subscriptionType, "EventFormatType", eventFormatType2,
226 "HttpHeaders", headers, "RegistryPrefixes", regPrefixes,
227 "MessageIds", msgIds, "DeliveryRetryPolicy",
228 retryPolicy, "MetricReportDefinitions", mrdJsonArray,
229 "ResourceTypes", resTypes))
AppaRao Puli144b6312020-08-03 22:23:12 +0530230 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700231 return;
232 }
233
234 if (regPrefixes && msgIds)
235 {
236 if (regPrefixes->size() && msgIds->size())
237 {
238 messages::mutualExclusiveProperties(
239 asyncResp->res, "RegistryPrefixes", "MessageIds");
240 return;
241 }
242 }
243
244 // Validate the URL using regex expression
245 // Format: <protocol>://<host>:<port>/<uri>
246 // protocol: http/https
247 // host: Exclude ' ', ':', '#', '?'
248 // port: Empty or numeric value with ':' separator.
249 // uri: Start with '/' and Exclude '#', ' '
250 // Can include query params(ex: '/event?test=1')
251 // TODO: Need to validate hostname extensively(as per rfc)
252 const std::regex urlRegex(
253 "(http|https)://([^/\\x20\\x3f\\x23\\x3a]+):?([0-9]*)(/"
254 "([^\\x20\\x23\\x3f]*\\x3f?([^\\x20\\x23\\x3f])*)?)");
255 std::cmatch match;
256 if (!std::regex_match(destUrl.c_str(), match, urlRegex))
257 {
258 messages::propertyValueFormatError(asyncResp->res, destUrl,
259 "Destination");
260 return;
261 }
262
263 std::string uriProto =
264 std::string(match[1].first, match[1].second);
265 if (uriProto == "http")
266 {
267#ifndef BMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING
268 messages::propertyValueFormatError(asyncResp->res, destUrl,
269 "Destination");
270 return;
271#endif
272 }
273
274 std::string host = std::string(match[2].first, match[2].second);
275 std::string port = std::string(match[3].first, match[3].second);
276 std::string path = std::string(match[4].first, match[4].second);
277 if (port.empty())
278 {
279 if (uriProto == "http")
280 {
281 port = "80";
282 }
283 else
284 {
285 port = "443";
286 }
287 }
288 if (path.empty())
289 {
290 path = "/";
291 }
292
293 std::shared_ptr<Subscription> subValue =
294 std::make_shared<Subscription>(host, port, path, uriProto);
295
296 subValue->destinationUrl = destUrl;
297
298 if (subscriptionType)
299 {
300 if (*subscriptionType != "RedfishEvent")
301 {
302 messages::propertyValueNotInList(asyncResp->res,
303 *subscriptionType,
304 "SubscriptionType");
305 return;
306 }
307 subValue->subscriptionType = *subscriptionType;
AppaRao Puli144b6312020-08-03 22:23:12 +0530308 }
309 else
310 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700311 subValue->subscriptionType = "RedfishEvent"; // Default
312 }
313
314 if (protocol != "Redfish")
315 {
316 messages::propertyValueNotInList(asyncResp->res, protocol,
317 "Protocol");
AppaRao Puli144b6312020-08-03 22:23:12 +0530318 return;
319 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700320 subValue->protocol = protocol;
AppaRao Puli156d6b02020-04-25 06:04:05 +0530321
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700322 if (eventFormatType2)
323 {
324 if (std::find(supportedEvtFormatTypes.begin(),
325 supportedEvtFormatTypes.end(),
326 *eventFormatType2) ==
327 supportedEvtFormatTypes.end())
328 {
329 messages::propertyValueNotInList(asyncResp->res,
330 *eventFormatType2,
331 "EventFormatType");
332 return;
333 }
334 subValue->eventFormatType = *eventFormatType2;
335 }
336 else
337 {
338 // If not specified, use default "Event"
339 subValue->eventFormatType = "Event";
340 }
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530341
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700342 if (context)
343 {
344 subValue->customText = *context;
345 }
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530346
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700347 if (headers)
348 {
349 subValue->httpHeaders = *headers;
350 }
351
352 if (regPrefixes)
353 {
354 for (const std::string& it : *regPrefixes)
355 {
356 if (std::find(supportedRegPrefixes.begin(),
357 supportedRegPrefixes.end(),
358 it) == supportedRegPrefixes.end())
359 {
360 messages::propertyValueNotInList(
361 asyncResp->res, it, "RegistryPrefixes");
362 return;
363 }
364 }
365 subValue->registryPrefixes = *regPrefixes;
366 }
367
368 if (resTypes)
369 {
370 for (const std::string& it : *resTypes)
371 {
372 if (std::find(supportedResourceTypes.begin(),
373 supportedResourceTypes.end(),
374 it) == supportedResourceTypes.end())
375 {
376 messages::propertyValueNotInList(asyncResp->res, it,
377 "ResourceTypes");
378 return;
379 }
380 }
381 subValue->resourceTypes = *resTypes;
382 }
383
384 if (msgIds)
385 {
386 std::vector<std::string> registryPrefix;
387
388 // If no registry prefixes are mentioned, consider all
389 // supported prefixes
390 if (subValue->registryPrefixes.empty())
391 {
392 registryPrefix.assign(supportedRegPrefixes.begin(),
393 supportedRegPrefixes.end());
394 }
395 else
396 {
397 registryPrefix = subValue->registryPrefixes;
398 }
399
400 for (const std::string& id : *msgIds)
401 {
402 bool validId = false;
403
404 // Check for Message ID in each of the selected Registry
405 for (const std::string& it : registryPrefix)
406 {
407 const boost::beast::span<
408 const redfish::message_registries::MessageEntry>
409 registry = redfish::message_registries::
410 getRegistryFromPrefix(it);
411
412 if (std::any_of(
413 registry.cbegin(), registry.cend(),
414 [&id](const redfish::message_registries::
415 MessageEntry& messageEntry) {
416 return !id.compare(messageEntry.first);
417 }))
418 {
419 validId = true;
420 break;
421 }
422 }
423
424 if (!validId)
425 {
426 messages::propertyValueNotInList(asyncResp->res, id,
427 "MessageIds");
428 return;
429 }
430 }
431
432 subValue->registryMsgIds = *msgIds;
433 }
434
435 if (retryPolicy)
436 {
437 if (std::find(supportedRetryPolicies.begin(),
438 supportedRetryPolicies.end(),
439 *retryPolicy) == supportedRetryPolicies.end())
440 {
441 messages::propertyValueNotInList(asyncResp->res,
442 *retryPolicy,
443 "DeliveryRetryPolicy");
444 return;
445 }
446 subValue->retryPolicy = *retryPolicy;
447 }
448 else
449 {
450 // Default "TerminateAfterRetries"
451 subValue->retryPolicy = "TerminateAfterRetries";
452 }
453
454 if (mrdJsonArray)
455 {
456 for (nlohmann::json& mrdObj : *mrdJsonArray)
457 {
458 std::string mrdUri;
459 if (json_util::getValueFromJsonObject(
460 mrdObj, "@odata.id", mrdUri))
461 {
462 subValue->metricReportDefinitions.emplace_back(
463 mrdUri);
464 }
465 else
466 {
467 messages::propertyValueFormatError(
468 asyncResp->res,
469 mrdObj.dump(
470 2, ' ', true,
471 nlohmann::json::error_handler_t::replace),
472 "MetricReportDefinitions");
473 return;
474 }
475 }
476 }
477
478 std::string id =
479 EventServiceManager::getInstance().addSubscription(
480 subValue);
481 if (id.empty())
482 {
483 messages::internalError(asyncResp->res);
484 return;
485 }
486
487 messages::created(asyncResp->res);
488 asyncResp->res.addHeader(
489 "Location", "/redfish/v1/EventService/Subscriptions/" + id);
490 });
491}
492
493inline void requestRoutesEventDestination(App& app)
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530494{
Ravi Teja9d41aec2021-07-23 01:57:01 -0500495 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700496 .privileges(redfish::privileges::getEventDestination)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700497 .methods(boost::beast::http::verb::get)(
498 [](const crow::Request&,
499 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
500 const std::string& param) {
501 std::shared_ptr<Subscription> subValue =
502 EventServiceManager::getInstance().getSubscription(param);
503 if (subValue == nullptr)
504 {
505 asyncResp->res.result(
506 boost::beast::http::status::not_found);
507 return;
508 }
509 const std::string& id = param;
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530510
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700511 asyncResp->res.jsonValue = {
512 {"@odata.type",
513 "#EventDestination.v1_7_0.EventDestination"},
514 {"Protocol", "Redfish"}};
515 asyncResp->res.jsonValue["@odata.id"] =
516 "/redfish/v1/EventService/Subscriptions/" + id;
517 asyncResp->res.jsonValue["Id"] = id;
518 asyncResp->res.jsonValue["Name"] = "Event Destination " + id;
519 asyncResp->res.jsonValue["Destination"] =
520 subValue->destinationUrl;
521 asyncResp->res.jsonValue["Context"] = subValue->customText;
522 asyncResp->res.jsonValue["SubscriptionType"] =
523 subValue->subscriptionType;
524 asyncResp->res.jsonValue["HttpHeaders"] = subValue->httpHeaders;
525 asyncResp->res.jsonValue["EventFormatType"] =
526 subValue->eventFormatType;
527 asyncResp->res.jsonValue["RegistryPrefixes"] =
528 subValue->registryPrefixes;
529 asyncResp->res.jsonValue["ResourceTypes"] =
530 subValue->resourceTypes;
zhanghch058d1b46d2021-04-01 11:18:24 +0800531
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700532 asyncResp->res.jsonValue["MessageIds"] =
533 subValue->registryMsgIds;
534 asyncResp->res.jsonValue["DeliveryRetryPolicy"] =
535 subValue->retryPolicy;
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530536
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700537 std::vector<nlohmann::json> mrdJsonArray;
538 for (const auto& mdrUri : subValue->metricReportDefinitions)
539 {
540 mrdJsonArray.push_back({{"@odata.id", mdrUri}});
541 }
542 asyncResp->res.jsonValue["MetricReportDefinitions"] =
543 mrdJsonArray;
544 });
545 /////redfish/v1/EventService/Subscriptions/
546 // ConfigureManager
Ravi Teja9d41aec2021-07-23 01:57:01 -0500547 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700548 // The below privilege is wrong, it should be ConfigureManager OR
549 // ConfigureSelf
550 // TODO(ed) follow up with DMTF spec and understand ConfigureSelf
551 //.privileges(redfish::privileges::patchEventDestination)
Ed Tanous432a8902021-06-14 15:28:56 -0700552 .privileges({{"ConfigureManager"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700553 .methods(boost::beast::http::verb::patch)(
554 [](const crow::Request& req,
555 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
556 const std::string& param) {
557 std::shared_ptr<Subscription> subValue =
558 EventServiceManager::getInstance().getSubscription(param);
559 if (subValue == nullptr)
560 {
561 asyncResp->res.result(
562 boost::beast::http::status::not_found);
563 return;
564 }
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530565
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700566 std::optional<std::string> context;
567 std::optional<std::string> retryPolicy;
568 std::optional<std::vector<nlohmann::json>> headers;
Sunitha Harishe56f2542020-07-22 02:38:59 -0500569
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700570 if (!json_util::readJson(req, asyncResp->res, "Context",
571 context, "DeliveryRetryPolicy",
572 retryPolicy, "HttpHeaders", headers))
573 {
574 return;
575 }
AppaRao Puli144b6312020-08-03 22:23:12 +0530576
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700577 if (context)
578 {
579 subValue->customText = *context;
580 }
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530581
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700582 if (headers)
583 {
584 subValue->httpHeaders = *headers;
585 }
zhanghch058d1b46d2021-04-01 11:18:24 +0800586
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700587 if (retryPolicy)
588 {
589 if (std::find(supportedRetryPolicies.begin(),
590 supportedRetryPolicies.end(),
591 *retryPolicy) == supportedRetryPolicies.end())
592 {
593 messages::propertyValueNotInList(asyncResp->res,
594 *retryPolicy,
595 "DeliveryRetryPolicy");
596 return;
597 }
598 subValue->retryPolicy = *retryPolicy;
599 subValue->updateRetryPolicy();
600 }
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530601
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700602 EventServiceManager::getInstance().updateSubscriptionData();
603 });
Ravi Teja9d41aec2021-07-23 01:57:01 -0500604 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700605 // The below privilege is wrong, it should be ConfigureManager OR
606 // ConfigureSelf
607 //.privileges(redfish::privileges::deleteEventDestination)
Ed Tanous432a8902021-06-14 15:28:56 -0700608 .privileges({{"ConfigureManager"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700609 .methods(boost::beast::http::verb::delete_)(
610 [](const crow::Request&,
611 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
612 const std::string& param) {
613 if (!EventServiceManager::getInstance().isSubscriptionExist(
614 param))
615 {
616 asyncResp->res.result(
617 boost::beast::http::status::not_found);
618 return;
619 }
620 EventServiceManager::getInstance().deleteSubscription(param);
621 });
622}
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530623
624} // namespace redfish