mirror of https://github.com/Icinga/icinga2.git
parent
ed14dd7b4e
commit
8a5d71a565
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_URLHANDLER("/v1", CreateObjectHandler);
|
REGISTER_URLHANDLER("/v1/objects", CreateObjectHandler);
|
||||||
|
|
||||||
bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
|
@ -36,19 +36,19 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() < 3) {
|
if (request.RequestUrl->GetPath().size() < 4) {
|
||||||
HttpUtility::SendJsonError(response, 400, "Object name is missing.");
|
HttpUtility::SendJsonError(response, 400, "Object name is missing.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]);
|
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[2]);
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
HttpUtility::SendJsonError(response, 403, "Erroneous type was supplied.");
|
HttpUtility::SendJsonError(response, 403, "Erroneous type was supplied.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = request.RequestUrl->GetPath()[2];
|
String name = request.RequestUrl->GetPath()[3];
|
||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
Array::Ptr templates = params->Get("templates");
|
Array::Ptr templates = params->Get("templates");
|
||||||
Dictionary::Ptr attrs = params->Get("attrs");
|
Dictionary::Ptr attrs = params->Get("attrs");
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_URLHANDLER("/v1", DeleteObjectHandler);
|
REGISTER_URLHANDLER("/v1/objects", DeleteObjectHandler);
|
||||||
|
|
||||||
bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
|
@ -39,13 +39,13 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() < 2) {
|
if (request.RequestUrl->GetPath().size() < 3) {
|
||||||
String path = boost::algorithm::join(request.RequestUrl->GetPath(), "/");
|
String path = boost::algorithm::join(request.RequestUrl->GetPath(), "/");
|
||||||
HttpUtility::SendJsonError(response, 404, "The requested path is too long to match any config tag requests.");
|
HttpUtility::SendJsonError(response, 404, "The requested path is too long to match any config tag requests.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]);
|
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[2]);
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
HttpUtility::SendJsonError(response, 400, "Erroneous type was supplied.");
|
HttpUtility::SendJsonError(response, 400, "Erroneous type was supplied.");
|
||||||
|
@ -54,15 +54,16 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
||||||
|
|
||||||
QueryDescription qd;
|
QueryDescription qd;
|
||||||
qd.Types.insert(type->GetName());
|
qd.Types.insert(type->GetName());
|
||||||
|
qd.Permission = "objects/delete/" + type->GetName();
|
||||||
|
|
||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
|
|
||||||
params->Set("type", type->GetName());
|
params->Set("type", type->GetName());
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 3) {
|
if (request.RequestUrl->GetPath().size() >= 4) {
|
||||||
String attr = type->GetName();
|
String attr = type->GetName();
|
||||||
boost::algorithm::to_lower(attr);
|
boost::algorithm::to_lower(attr);
|
||||||
params->Set(attr, request.RequestUrl->GetPath()[2]);
|
params->Set(attr, request.RequestUrl->GetPath()[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params);
|
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params);
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_URLHANDLER("/v1", ModifyObjectHandler);
|
REGISTER_URLHANDLER("/v1/objects", ModifyObjectHandler);
|
||||||
|
|
||||||
bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() < 2)
|
if (request.RequestUrl->GetPath().size() < 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]);
|
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]);
|
||||||
|
@ -47,15 +47,16 @@ bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
||||||
|
|
||||||
QueryDescription qd;
|
QueryDescription qd;
|
||||||
qd.Types.insert(type->GetName());
|
qd.Types.insert(type->GetName());
|
||||||
|
qd.Permission = "objects/modify/" + type->GetName();
|
||||||
|
|
||||||
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
|
||||||
|
|
||||||
params->Set("type", type->GetName());
|
params->Set("type", type->GetName());
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 3) {
|
if (request.RequestUrl->GetPath().size() >= 4) {
|
||||||
String attr = type->GetName();
|
String attr = type->GetName();
|
||||||
boost::algorithm::to_lower(attr);
|
boost::algorithm::to_lower(attr);
|
||||||
params->Set(attr, request.RequestUrl->GetPath()[2]);
|
params->Set(attr, request.RequestUrl->GetPath()[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params);
|
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params);
|
||||||
|
|
|
@ -28,17 +28,17 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_URLHANDLER("/v1", ObjectQueryHandler);
|
REGISTER_URLHANDLER("/v1/objects", ObjectQueryHandler);
|
||||||
|
|
||||||
bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
if (request.RequestMethod != "GET")
|
if (request.RequestMethod != "GET")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() < 2)
|
if (request.RequestUrl->GetPath().size() < 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]);
|
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[2]);
|
||||||
|
|
||||||
if (!type)
|
if (!type)
|
||||||
return false;
|
return false;
|
||||||
|
@ -60,10 +60,10 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
|
||||||
|
|
||||||
params->Set("type", type->GetName());
|
params->Set("type", type->GetName());
|
||||||
|
|
||||||
if (request.RequestUrl->GetPath().size() >= 3) {
|
if (request.RequestUrl->GetPath().size() >= 4) {
|
||||||
String attr = type->GetName();
|
String attr = type->GetName();
|
||||||
boost::algorithm::to_lower(attr);
|
boost::algorithm::to_lower(attr);
|
||||||
params->Set(attr, request.RequestUrl->GetPath()[2]);
|
params->Set(attr, request.RequestUrl->GetPath()[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params);
|
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params);
|
||||||
|
|
Loading…
Reference in New Issue