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

Method HandleRequest

lib/remote/createobjecthandler.cpp:19–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17REGISTER_URLHANDLER("/v1/objects", CreateObjectHandler);
18
19bool CreateObjectHandler::HandleRequest(
20 const WaitGroup::Ptr& waitGroup,
21 const HttpApiRequest& request,
22 HttpApiResponse& response,
23 boost::asio::yield_context&
24)
25{
26 namespace http = boost::beast::http;
27
28 auto url = request.Url();
29 auto user = request.User();
30 auto params = request.Params();
31
32 if (url->GetPath().size() != 4)
33 return false;
34
35 if (request.method() != http::verb::put)
36 return false;
37
38 Type::Ptr type = FilterUtility::TypeFromPluralName(url->GetPath()[2]);
39
40 if (!type) {
41 HttpUtility::SendJsonError(response, params, 400, "Invalid type specified.");
42 return true;
43 }
44
45 FilterUtility::CheckPermission(user, "objects/create/" + type->GetName());
46
47 String name = url->GetPath()[3];
48 Array::Ptr templates = params->Get("templates");
49 Dictionary::Ptr attrs = params->Get("attrs");
50
51 /* Put created objects into the local zone if not explicitly defined.
52 * This allows additional zone members to sync the
53 * configuration at some later point.
54 */
55 Zone::Ptr localZone = Zone::GetLocalZone();
56 String localZoneName;
57
58 if (localZone) {
59 localZoneName = localZone->GetName();
60
61 if (!attrs) {
62 attrs = new Dictionary({
63 { "zone", localZoneName }
64 });
65 } else if (!attrs->Contains("zone")) {
66 attrs->Set("zone", localZoneName);
67 }
68 }
69
70 /* Sanity checks for unique groups array. */
71 if (attrs->Contains("groups")) {
72 Array::Ptr groups = attrs->Get("groups");
73
74 if (groups)
75 attrs->Set("groups", groups->Unique());
76 }

Callers

nothing calls this directly

Calls 13

ParamsMethod · 0.80
UniqueMethod · 0.80
UrlMethod · 0.45
UserMethod · 0.45
sizeMethod · 0.45
GetPathMethod · 0.45
GetNameMethod · 0.45
GetMethod · 0.45
ContainsMethod · 0.45
SetMethod · 0.45
AddMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected