Merge pull request #6410 from Icinga/remove-dead-code

Remove unused code
This commit is contained in:
Michael Friedrich 2018-07-27 15:56:52 +02:00 committed by GitHub
commit 1d22b6e176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 256 deletions

View File

@ -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<HttpRequest> 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<ApiType::Ptr>());
}
}
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<ApiType::Ptr> 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<ApiType::Ptr>());
}
}
void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback,
const std::vector<String>& names, const std::vector<String>& attrs, const std::vector<String>& 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<String, std::vector<String> > 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<HttpRequest> 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<ApiObject::Ptr>());
}
}
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<ApiObject::Ptr> 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<ApiObject::Ptr>());
}
}
void ApiClient::ExecuteScript(const String& session, const String& command, bool sandboxed,
const ExecuteScriptCompletionCallback& callback) const
{

View File

@ -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<ApiType> Type;
};
class ApiType final : public Object
{
public:
DECLARE_PTR_TYPEDEFS(ApiType);
String Name;
String PluralName;
String BaseName;
ApiType::Ptr Base;
bool Abstract;
std::map<String, ApiField> Fields;
std::vector<String> PrototypeKeys;
};
struct ApiObjectReference
{
public:
String Name;
String Type;
};
struct ApiObject : public Object
{
public:
DECLARE_PTR_TYPEDEFS(ApiObject);
String Name;
String Type;
std::map<String, Value> Attrs;
std::vector<ApiObjectReference> 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<void(boost::exception_ptr, const std::vector<ApiType::Ptr>&)> TypesCompletionCallback;
void GetTypes(const TypesCompletionCallback& callback) const;
typedef std::function<void(boost::exception_ptr, const std::vector<ApiObject::Ptr>&)> ObjectsCompletionCallback;
void GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback,
const std::vector<String>& names = std::vector<String>(),
const std::vector<String>& attrs = std::vector<String>(),
const std::vector<String>& joins = std::vector<String>(), bool all_joins = false) const;
typedef std::function<void(boost::exception_ptr, const Value&)> 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,