From 4159682cf808ca433e862992329b71d0945ab512 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Mon, 25 Jun 2018 10:09:30 +0200 Subject: [PATCH] Remove unused code These methods and types were used only by the Icinga Studio --- lib/remote/apiclient.cpp | 187 --------------------------------------- lib/remote/apiclient.hpp | 69 --------------- 2 files changed, 256 deletions(-) diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index b0d0a63da..6e507b029 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -33,193 +33,6 @@ ApiClient::ApiClient(const String& host, const String& port, m_Connection->Start(); } -void ApiClient::GetTypes(const TypesCompletionCallback& callback) const -{ - Url::Ptr url = new Url(); - url->SetScheme("https"); - url->SetHost(m_Connection->GetHost()); - url->SetPort(m_Connection->GetPort()); - url->SetPath({ "v1", "types" }); - - try { - std::shared_ptr req = m_Connection->NewRequest(); - req->RequestMethod = "GET"; - req->RequestUrl = url; - req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password)); - req->AddHeader("Accept", "application/json"); - m_Connection->SubmitRequest(req, std::bind(TypesHttpCompletionCallback, _1, _2, callback)); - } catch (const std::exception&) { - callback(boost::current_exception(), std::vector()); - } -} - -void ApiClient::TypesHttpCompletionCallback(HttpRequest& request, HttpResponse& response, - const TypesCompletionCallback& callback) -{ - Dictionary::Ptr result; - - String body; - char buffer[1024]; - size_t count; - - while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0) - body += String(buffer, buffer + count); - - try { - if (response.StatusCode < 200 || response.StatusCode > 299) { - std::string message = "HTTP request failed; Code: " + Convert::ToString(response.StatusCode) + "; Body: " + body; - - BOOST_THROW_EXCEPTION(ScriptError(message)); - } - - std::vector types; - - result = JsonDecode(body); - - Array::Ptr results = result->Get("results"); - - ObjectLock olock(results); - for (const Dictionary::Ptr typeInfo : results) - { - ApiType::Ptr type = new ApiType(); - type->Abstract = typeInfo->Get("abstract"); - type->BaseName = typeInfo->Get("base"); - type->Name = typeInfo->Get("name"); - type->PluralName = typeInfo->Get("plural_name"); - // TODO: attributes - types.emplace_back(std::move(type)); - } - - callback(boost::exception_ptr(), types); - } catch (const std::exception& ex) { - Log(LogCritical, "ApiClient") - << "Error while decoding response: " << DiagnosticInformation(ex); - callback(boost::current_exception(), std::vector()); - } - -} - -void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback, - const std::vector& names, const std::vector& attrs, const std::vector& joins, bool all_joins) const -{ - Url::Ptr url = new Url(); - url->SetScheme("https"); - url->SetHost(m_Connection->GetHost()); - url->SetPort(m_Connection->GetPort()); - url->SetPath({ "v1", "objects", pluralType }); - - std::map > params; - - for (const String& name : names) { - params[pluralType.ToLower()].push_back(name); - } - - for (const String& attr : attrs) { - params["attrs"].push_back(attr); - } - - for (const String& join : joins) { - params["joins"].push_back(join); - } - - params["all_joins"].emplace_back(all_joins ? "1" : "0"); - - url->SetQuery(params); - - try { - std::shared_ptr req = m_Connection->NewRequest(); - req->RequestMethod = "GET"; - req->RequestUrl = url; - req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password)); - req->AddHeader("Accept", "application/json"); - m_Connection->SubmitRequest(req, std::bind(ObjectsHttpCompletionCallback, _1, _2, callback)); - } catch (const std::exception&) { - callback(boost::current_exception(), std::vector()); - } -} - -void ApiClient::ObjectsHttpCompletionCallback(HttpRequest& request, - HttpResponse& response, const ObjectsCompletionCallback& callback) -{ - Dictionary::Ptr result; - - String body; - char buffer[1024]; - size_t count; - - while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0) - body += String(buffer, buffer + count); - - try { - if (response.StatusCode < 200 || response.StatusCode > 299) { - std::string message = "HTTP request failed; Code: " + Convert::ToString(response.StatusCode) + "; Body: " + body; - - BOOST_THROW_EXCEPTION(ScriptError(message)); - } - - std::vector objects; - - result = JsonDecode(body); - - Array::Ptr results = result->Get("results"); - - if (results) { - ObjectLock olock(results); - for (const Dictionary::Ptr objectInfo : results) { - ApiObject::Ptr object = new ApiObject(); - - object->Name = objectInfo->Get("name"); - object->Type = objectInfo->Get("type"); - - Dictionary::Ptr attrs = objectInfo->Get("attrs"); - - if (attrs) { - ObjectLock olock(attrs); - for (const Dictionary::Pair& kv : attrs) { - object->Attrs[object->Type.ToLower() + "." + kv.first] = kv.second; - } - } - - Dictionary::Ptr joins = objectInfo->Get("joins"); - - if (joins) { - ObjectLock olock(joins); - for (const Dictionary::Pair& kv : joins) { - Dictionary::Ptr attrs = kv.second; - - if (attrs) { - ObjectLock olock(attrs); - for (const Dictionary::Pair& kv2 : attrs) { - object->Attrs[kv.first + "." + kv2.first] = kv2.second; - } - } - } - } - - Array::Ptr used_by = objectInfo->Get("used_by"); - - if (used_by) { - ObjectLock olock(used_by); - for (const Dictionary::Ptr& refInfo : used_by) { - ApiObjectReference ref; - ref.Name = refInfo->Get("name"); - ref.Type = refInfo->Get("type"); - object->UsedBy.emplace_back(std::move(ref)); - } - } - - objects.push_back(object); - } - } - - callback(boost::exception_ptr(), objects); - } catch (const std::exception& ex) { - Log(LogCritical, "ApiClient") - << "Error while decoding response: " << DiagnosticInformation(ex); - callback(boost::current_exception(), std::vector()); - } -} - void ApiClient::ExecuteScript(const String& session, const String& command, bool sandboxed, const ExecuteScriptCompletionCallback& callback) const { diff --git a/lib/remote/apiclient.hpp b/lib/remote/apiclient.hpp index 7507765a0..c6814c02b 100644 --- a/lib/remote/apiclient.hpp +++ b/lib/remote/apiclient.hpp @@ -28,62 +28,6 @@ namespace icinga { -struct ApiFieldAttributes -{ -public: - bool Config; - bool Navigation; - bool NoUserModify; - bool NouserView; - bool Required; - bool State; -}; - -class ApiType; - -struct ApiField -{ -public: - String Name; - int ID; - int ArrayRank; - ApiFieldAttributes FieldAttributes; - String TypeName; - intrusive_ptr Type; -}; - -class ApiType final : public Object -{ -public: - DECLARE_PTR_TYPEDEFS(ApiType); - - String Name; - String PluralName; - String BaseName; - ApiType::Ptr Base; - bool Abstract; - std::map Fields; - std::vector PrototypeKeys; -}; - -struct ApiObjectReference -{ -public: - String Name; - String Type; -}; - -struct ApiObject : public Object -{ -public: - DECLARE_PTR_TYPEDEFS(ApiObject); - - String Name; - String Type; - std::map Attrs; - std::vector UsedBy; -}; - class ApiClient : public Object { public: @@ -92,15 +36,6 @@ public: ApiClient(const String& host, const String& port, String user, String password); - typedef std::function&)> TypesCompletionCallback; - void GetTypes(const TypesCompletionCallback& callback) const; - - typedef std::function&)> ObjectsCompletionCallback; - void GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback, - const std::vector& names = std::vector(), - const std::vector& attrs = std::vector(), - const std::vector& joins = std::vector(), bool all_joins = false) const; - typedef std::function ExecuteScriptCompletionCallback; void ExecuteScript(const String& session, const String& command, bool sandboxed, const ExecuteScriptCompletionCallback& callback) const; @@ -114,10 +49,6 @@ private: String m_User; String m_Password; - static void TypesHttpCompletionCallback(HttpRequest& request, - HttpResponse& response, const TypesCompletionCallback& callback); - static void ObjectsHttpCompletionCallback(HttpRequest& request, - HttpResponse& response, const ObjectsCompletionCallback& callback); static void ExecuteScriptHttpCompletionCallback(HttpRequest& request, HttpResponse& response, const ExecuteScriptCompletionCallback& callback); static void AutocompleteScriptHttpCompletionCallback(HttpRequest& request,