MCPcopy Create free account
hub / github.com/Icinga/icinga2 / HandleRequest

Method HandleRequest

lib/remote/eventshandler.cpp:43–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41const String l_ApiQuery ("<API query>");
42
43bool EventsHandler::HandleRequest(
44 const WaitGroup::Ptr&,
45 const HttpApiRequest& request,
46 HttpApiResponse& response,
47 boost::asio::yield_context& yc
48)
49{
50 namespace asio = boost::asio;
51 namespace http = boost::beast::http;
52
53 auto url = request.Url();
54 auto user = request.User();
55 auto params = request.Params();
56
57 if (url->GetPath().size() != 2)
58 return false;
59
60 if (request.method() != http::verb::post)
61 return false;
62
63 if (request.version() == 10) {
64 HttpUtility::SendJsonError(response, params, 400, "HTTP/1.0 not supported for event streams.");
65 return true;
66 }
67
68 Array::Ptr types = params->Get("types");
69
70 if (!types) {
71 HttpUtility::SendJsonError(response, params, 400, "'types' query parameter is required.");
72 return true;
73 }
74
75 {
76 ObjectLock olock(types);
77 for (String type : types) {
78 FilterUtility::CheckPermission(user, "events/" + type);
79 }
80 }
81
82 std::set<EventType> eventTypes;
83
84 {
85 ObjectLock olock(types);
86 for (String type : types) {
87 auto typeId (l_EventTypes.find(type));
88
89 if (typeId != l_EventTypes.end()) {
90 eventTypes.emplace(typeId->second);
91 }
92 }
93 }
94
95 String filter = "";
96 if (params && params->Contains("filter")) {
97 if (!FilterUtility::HasPermission(request.User(), ApiUser::FilterExpressionPerm, nullptr)) {
98 HttpUtility::SendJsonError(response, params, 403,
99 "Missing permission: " + ApiUser::FilterExpressionPerm);
100 return true;

Callers

nothing calls this directly

Calls 15

ParamsMethod · 0.80
findMethod · 0.80
emplaceMethod · 0.80
StartStreamingMethod · 0.80
GetJsonEncoderMethod · 0.80
ShiftMethod · 0.80
IsClientDisconnectedMethod · 0.80
UrlMethod · 0.45
UserMethod · 0.45
sizeMethod · 0.45
GetPathMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected