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

Method HandleRequest

lib/remote/templatequeryhandler.cpp:79–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77};
78
79bool TemplateQueryHandler::HandleRequest(
80 const WaitGroup::Ptr&,
81 const HttpApiRequest& request,
82 HttpApiResponse& response,
83 boost::asio::yield_context& yc
84)
85{
86 namespace http = boost::beast::http;
87
88 auto url = request.Url();
89 auto user = request.User();
90 auto params = request.Params();
91
92 if (url->GetPath().size() < 3 || url->GetPath().size() > 4)
93 return false;
94
95 if (request.method() != http::verb::get)
96 return false;
97
98 Type::Ptr type = FilterUtility::TypeFromPluralName(url->GetPath()[2]);
99
100 if (!type) {
101 HttpUtility::SendJsonError(response, params, 400, "Invalid type specified.");
102 return true;
103 }
104
105 QueryDescription qd;
106 qd.Types.insert(type->GetName());
107 qd.Permission = "templates/query/" + type->GetName();
108 qd.Provider = new TemplateTargetProvider();
109
110 params->Set("type", type->GetName());
111
112 if (url->GetPath().size() >= 4) {
113 String attr = type->GetName();
114 boost::algorithm::to_lower(attr);
115 params->Set(attr, url->GetPath()[3]);
116 }
117
118 std::vector<Value> objs;
119
120 try {
121 objs = FilterUtility::GetFilterTargets(qd, params, user, "tmpl");
122 } catch (const MissingPermissionError& ex) {
123 HttpUtility::SendJsonError(response, params, 403, ex.what());
124 return true;
125 } catch (const std::exception& ex) {
126 HttpUtility::SendJsonError(response, params, 404,
127 "No templates found.",
128 DiagnosticInformation(ex));
129 return true;
130 }
131
132 Array::Ptr resultArr = new Array(std::move(objs));
133 resultArr->Freeze();
134
135 Dictionary::Ptr result = new Dictionary{{"results", resultArr}};
136 result->Freeze();

Callers

nothing calls this directly

Calls 10

ParamsMethod · 0.80
UrlMethod · 0.45
UserMethod · 0.45
sizeMethod · 0.45
GetPathMethod · 0.45
insertMethod · 0.45
GetNameMethod · 0.45
SetMethod · 0.45
whatMethod · 0.45
FreezeMethod · 0.45

Tested by

no test coverage detected