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

Method HandleRequest

lib/remote/typequeryhandler.cpp:48–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46};
47
48bool TypeQueryHandler::HandleRequest(
49 const WaitGroup::Ptr&,
50 const HttpApiRequest& request,
51 HttpApiResponse& response,
52 boost::asio::yield_context& yc
53)
54{
55 namespace http = boost::beast::http;
56
57 auto url = request.Url();
58 auto user = request.User();
59 auto params = request.Params();
60
61 if (url->GetPath().size() > 3)
62 return false;
63
64 if (request.method() != http::verb::get)
65 return false;
66
67 QueryDescription qd;
68 qd.Types.insert("Type");
69 qd.Permission = "types";
70 qd.Provider = new TypeTargetProvider();
71
72 if (params->Contains("type"))
73 params->Set("name", params->Get("type"));
74
75 params->Set("type", "Type");
76
77 if (url->GetPath().size() >= 3)
78 params->Set("name", url->GetPath()[2]);
79
80 std::vector<Value> objs;
81
82 try {
83 objs = FilterUtility::GetFilterTargets(qd, params, user);
84 } catch (const MissingPermissionError& ex) {
85 HttpUtility::SendJsonError(response, params, 403, ex.what());
86 return true;
87 } catch (const std::exception& ex) {
88 HttpUtility::SendJsonError(response, params, 404,
89 "No objects found.",
90 DiagnosticInformation(ex));
91 return true;
92 }
93
94 auto generatorFunc = [](const Type::Ptr& obj) -> Value {
95 Dictionary::Ptr result = new Dictionary();
96 Dictionary::Ptr resultAttrs = new Dictionary();
97 result->Set("name", obj->GetName());
98 result->Set("plural_name", obj->GetPluralName());
99 if (obj->GetBaseType())
100 result->Set("base", obj->GetBaseType()->GetName());
101 result->Set("abstract", obj->IsAbstract());
102 result->Set("fields", resultAttrs);
103
104 Dictionary::Ptr prototype = dynamic_pointer_cast<Dictionary>(obj->GetPrototype());
105 Array::Ptr prototypeKeys = new Array();

Callers

nothing calls this directly

Calls 15

ParamsMethod · 0.80
UrlMethod · 0.45
UserMethod · 0.45
sizeMethod · 0.45
GetPathMethod · 0.45
insertMethod · 0.45
ContainsMethod · 0.45
SetMethod · 0.45
GetMethod · 0.45
whatMethod · 0.45
GetNameMethod · 0.45
GetPluralNameMethod · 0.45

Tested by

no test coverage detected