From 8a5d71a56535be5a7cd880586e302eb4862cdb55 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 28 Sep 2015 08:37:50 +0200 Subject: [PATCH] Move /v1/ to /v1/objects/ refs #10212 --- lib/remote/createobjecthandler.cpp | 8 ++++---- lib/remote/deleteobjecthandler.cpp | 11 ++++++----- lib/remote/modifyobjecthandler.cpp | 9 +++++---- lib/remote/objectqueryhandler.cpp | 10 +++++----- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/remote/createobjecthandler.cpp b/lib/remote/createobjecthandler.cpp index fa1c3f2ef..a1d4d6d96 100644 --- a/lib/remote/createobjecthandler.cpp +++ b/lib/remote/createobjecthandler.cpp @@ -27,7 +27,7 @@ using namespace icinga; -REGISTER_URLHANDLER("/v1", CreateObjectHandler); +REGISTER_URLHANDLER("/v1/objects", CreateObjectHandler); 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; } - if (request.RequestUrl->GetPath().size() < 3) { + if (request.RequestUrl->GetPath().size() < 4) { HttpUtility::SendJsonError(response, 400, "Object name is missing."); return true; } - Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]); + Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[2]); if (!type) { HttpUtility::SendJsonError(response, 403, "Erroneous type was supplied."); return true; } - String name = request.RequestUrl->GetPath()[2]; + String name = request.RequestUrl->GetPath()[3]; Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request); Array::Ptr templates = params->Get("templates"); Dictionary::Ptr attrs = params->Get("attrs"); diff --git a/lib/remote/deleteobjecthandler.cpp b/lib/remote/deleteobjecthandler.cpp index f4b89d284..6e043091e 100644 --- a/lib/remote/deleteobjecthandler.cpp +++ b/lib/remote/deleteobjecthandler.cpp @@ -30,7 +30,7 @@ using namespace icinga; -REGISTER_URLHANDLER("/v1", DeleteObjectHandler); +REGISTER_URLHANDLER("/v1/objects", DeleteObjectHandler); 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; } - if (request.RequestUrl->GetPath().size() < 2) { + if (request.RequestUrl->GetPath().size() < 3) { String path = boost::algorithm::join(request.RequestUrl->GetPath(), "/"); HttpUtility::SendJsonError(response, 404, "The requested path is too long to match any config tag requests."); return true; } - Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]); + Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[2]); if (!type) { HttpUtility::SendJsonError(response, 400, "Erroneous type was supplied."); @@ -54,15 +54,16 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r QueryDescription qd; qd.Types.insert(type->GetName()); + qd.Permission = "objects/delete/" + type->GetName(); Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request); params->Set("type", type->GetName()); - if (request.RequestUrl->GetPath().size() >= 3) { + if (request.RequestUrl->GetPath().size() >= 4) { String attr = type->GetName(); boost::algorithm::to_lower(attr); - params->Set(attr, request.RequestUrl->GetPath()[2]); + params->Set(attr, request.RequestUrl->GetPath()[3]); } std::vector objs = FilterUtility::GetFilterTargets(qd, params); diff --git a/lib/remote/modifyobjecthandler.cpp b/lib/remote/modifyobjecthandler.cpp index 239578ce3..b01810fe6 100644 --- a/lib/remote/modifyobjecthandler.cpp +++ b/lib/remote/modifyobjecthandler.cpp @@ -28,7 +28,7 @@ using namespace icinga; -REGISTER_URLHANDLER("/v1", ModifyObjectHandler); +REGISTER_URLHANDLER("/v1/objects", ModifyObjectHandler); 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; } - if (request.RequestUrl->GetPath().size() < 2) + if (request.RequestUrl->GetPath().size() < 3) return false; Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]); @@ -47,15 +47,16 @@ bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r QueryDescription qd; qd.Types.insert(type->GetName()); + qd.Permission = "objects/modify/" + type->GetName(); Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request); params->Set("type", type->GetName()); - if (request.RequestUrl->GetPath().size() >= 3) { + if (request.RequestUrl->GetPath().size() >= 4) { String attr = type->GetName(); boost::algorithm::to_lower(attr); - params->Set(attr, request.RequestUrl->GetPath()[2]); + params->Set(attr, request.RequestUrl->GetPath()[3]); } std::vector objs = FilterUtility::GetFilterTargets(qd, params); diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp index 31cd6ea96..909dabfb2 100644 --- a/lib/remote/objectqueryhandler.cpp +++ b/lib/remote/objectqueryhandler.cpp @@ -28,17 +28,17 @@ using namespace icinga; -REGISTER_URLHANDLER("/v1", ObjectQueryHandler); +REGISTER_URLHANDLER("/v1/objects", ObjectQueryHandler); bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response) { if (request.RequestMethod != "GET") return false; - if (request.RequestUrl->GetPath().size() < 2) + if (request.RequestUrl->GetPath().size() < 3) return false; - Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]); + Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[2]); if (!type) return false; @@ -60,10 +60,10 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re params->Set("type", type->GetName()); - if (request.RequestUrl->GetPath().size() >= 3) { + if (request.RequestUrl->GetPath().size() >= 4) { String attr = type->GetName(); boost::algorithm::to_lower(attr); - params->Set(attr, request.RequestUrl->GetPath()[2]); + params->Set(attr, request.RequestUrl->GetPath()[3]); } std::vector objs = FilterUtility::GetFilterTargets(qd, params);