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

Method HandleGet

lib/remote/configpackageshandler.cpp:43–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void ConfigPackagesHandler::HandleGet(const HttpApiRequest& request, HttpApiResponse& response, boost::asio::yield_context& yc)
44{
45 namespace http = boost::beast::http;
46
47 auto url = request.Url();
48 auto user = request.User();
49 auto params = request.Params();
50
51 FilterUtility::CheckPermission(user, "config/query");
52
53 std::vector<String> packages;
54
55 try {
56 packages = ConfigPackageUtility::GetPackages();
57 } catch (const std::exception& ex) {
58 HttpUtility::SendJsonError(response, params, 500, "Could not retrieve packages.",
59 DiagnosticInformation(ex));
60 return;
61 }
62
63 ArrayData results;
64
65 {
66 std::unique_lock<std::mutex> lock(ConfigPackageUtility::GetStaticPackageMutex());
67
68 for (const String& package : packages) {
69 String activeStage;
70
71 try {
72 activeStage = ConfigPackageUtility::GetActiveStage(package);
73 } catch (const std::exception&) { } /* Should never happen. */
74
75 results.emplace_back(new Dictionary({
76 { "name", package },
77 { "stages", Array::FromVector(ConfigPackageUtility::GetStages(package)) },
78 { "active-stage", activeStage }
79 }));
80 }
81 }
82
83 Array::Ptr resultsArr = new Array(std::move(results));
84 resultsArr->Freeze();
85
86 Dictionary::Ptr result = new Dictionary{{"results", resultsArr}};
87 result->Freeze();
88
89 response.result(http::status::ok);
90 HttpUtility::SendJsonBody(response, params, result, yc);
91}
92
93void ConfigPackagesHandler::HandlePost(const HttpApiRequest& request, HttpApiResponse& response)
94{

Callers

nothing calls this directly

Calls 4

ParamsMethod · 0.80
UrlMethod · 0.45
UserMethod · 0.45
FreezeMethod · 0.45

Tested by

no test coverage detected