mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 23:54:07 +02:00
parent
6fb1b60c12
commit
143aa13118
@ -54,6 +54,12 @@ void ApiClient::TypesHttpCompletionCallback(HttpRequest& request, HttpResponse&
|
|||||||
while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0)
|
while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0)
|
||||||
body += String(buffer, buffer + count);
|
body += String(buffer, buffer + count);
|
||||||
|
|
||||||
|
if (response.StatusCode < 200 || response.StatusCode > 299) {
|
||||||
|
Log(LogCritical, "ApiClient")
|
||||||
|
<< "Failed HTTP request; Code: " << response.StatusCode << "; Body: " << body;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ApiType::Ptr> types;
|
std::vector<ApiType::Ptr> types;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -83,7 +89,7 @@ void ApiClient::TypesHttpCompletionCallback(HttpRequest& request, HttpResponse&
|
|||||||
void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback,
|
void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback,
|
||||||
const std::vector<String>& names, const std::vector<String>& attrs) const
|
const std::vector<String>& names, const std::vector<String>& attrs) const
|
||||||
{
|
{
|
||||||
String url = "https://" + m_Connection->GetHost() + ":" + m_Connection->GetPort() + "/v1/" + pluralType;
|
String url = "https://" + m_Connection->GetHost() + ":" + m_Connection->GetPort() + "/v1/objects/" + pluralType;
|
||||||
String qp;
|
String qp;
|
||||||
|
|
||||||
BOOST_FOREACH(const String& name, names) {
|
BOOST_FOREACH(const String& name, names) {
|
||||||
@ -119,6 +125,12 @@ void ApiClient::ObjectsHttpCompletionCallback(HttpRequest& request,
|
|||||||
while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0)
|
while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0)
|
||||||
body += String(buffer, buffer + count);
|
body += String(buffer, buffer + count);
|
||||||
|
|
||||||
|
if (response.StatusCode < 200 || response.StatusCode > 299) {
|
||||||
|
Log(LogCritical, "ApiClient")
|
||||||
|
<< "Failed HTTP request; Code: " << response.StatusCode << "; Body: " << body;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ApiObject::Ptr> objects;
|
std::vector<ApiObject::Ptr> objects;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -126,35 +138,37 @@ void ApiClient::ObjectsHttpCompletionCallback(HttpRequest& request,
|
|||||||
|
|
||||||
Array::Ptr results = result->Get("results");
|
Array::Ptr results = result->Get("results");
|
||||||
|
|
||||||
ObjectLock olock(results);
|
if (results) {
|
||||||
BOOST_FOREACH(const Dictionary::Ptr objectInfo, results)
|
ObjectLock olock(results);
|
||||||
{
|
BOOST_FOREACH(const Dictionary::Ptr objectInfo, results)
|
||||||
ApiObject::Ptr object = new ApiObject();
|
|
||||||
|
|
||||||
Dictionary::Ptr attrs = objectInfo->Get("attrs");
|
|
||||||
|
|
||||||
{
|
{
|
||||||
ObjectLock olock(attrs);
|
ApiObject::Ptr object = new ApiObject();
|
||||||
BOOST_FOREACH(const Dictionary::Pair& kv, attrs)
|
|
||||||
|
Dictionary::Ptr attrs = objectInfo->Get("attrs");
|
||||||
|
|
||||||
{
|
{
|
||||||
object->Attrs[kv.first] = kv.second;
|
ObjectLock olock(attrs);
|
||||||
|
BOOST_FOREACH(const Dictionary::Pair& kv, attrs)
|
||||||
|
{
|
||||||
|
object->Attrs[kv.first] = kv.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Array::Ptr used_by = objectInfo->Get("used_by");
|
Array::Ptr used_by = objectInfo->Get("used_by");
|
||||||
|
|
||||||
{
|
|
||||||
ObjectLock olock(used_by);
|
|
||||||
BOOST_FOREACH(const Dictionary::Ptr& refInfo, used_by)
|
|
||||||
{
|
{
|
||||||
ApiObjectReference ref;
|
ObjectLock olock(used_by);
|
||||||
ref.Name = refInfo->Get("name");
|
BOOST_FOREACH(const Dictionary::Ptr& refInfo, used_by)
|
||||||
ref.Type = refInfo->Get("type");
|
{
|
||||||
object->UsedBy.push_back(ref);
|
ApiObjectReference ref;
|
||||||
|
ref.Name = refInfo->Get("name");
|
||||||
|
ref.Type = refInfo->Get("type");
|
||||||
|
object->UsedBy.push_back(ref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
Log(LogCritical, "ApiClient")
|
Log(LogCritical, "ApiClient")
|
||||||
|
@ -49,7 +49,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
pUrl = f.GetUrl();
|
pUrl = f.GetUrl();
|
||||||
url = pUrl->Format();
|
url = pUrl->Format(true);
|
||||||
wUrl = url;
|
wUrl = url;
|
||||||
config.Write("url", wUrl);
|
config.Write("url", wUrl);
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,40 +33,15 @@ MainForm::MainForm(wxWindow *parent, const Url::Ptr& url)
|
|||||||
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
String host, port, user, pass;
|
String port = url->GetPort();
|
||||||
|
|
||||||
std::string authority = url->GetAuthority();
|
if (port.IsEmpty())
|
||||||
|
|
||||||
std::vector<std::string> tokens;
|
|
||||||
boost::algorithm::split(tokens, authority, boost::is_any_of("@"));
|
|
||||||
|
|
||||||
if (tokens.size() > 1) {
|
|
||||||
std::vector<std::string> userinfo;
|
|
||||||
boost::algorithm::split(userinfo, tokens[0], boost::is_any_of(":"));
|
|
||||||
|
|
||||||
user = userinfo[0];
|
|
||||||
pass = userinfo[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> hostport;
|
|
||||||
boost::algorithm::split(hostport, tokens.size() > 1 ? tokens[1] : tokens[0], boost::is_any_of(":"));
|
|
||||||
|
|
||||||
host = hostport[0];
|
|
||||||
|
|
||||||
if (hostport.size() > 1)
|
|
||||||
port = hostport[1];
|
|
||||||
else
|
|
||||||
port = "5665";
|
port = "5665";
|
||||||
|
|
||||||
m_ApiClient = new ApiClient(host, port, user, pass);
|
m_ApiClient = new ApiClient(url->GetHost(), port, url->GetUsername(), url->GetPassword());
|
||||||
m_ApiClient->GetTypes(boost::bind(&MainForm::TypesCompletionHandler, this, _1, true));
|
m_ApiClient->GetTypes(boost::bind(&MainForm::TypesCompletionHandler, this, _1, true));
|
||||||
|
|
||||||
std::string title = host;
|
std::string title = url->Format() + " - Icinga Studio";
|
||||||
|
|
||||||
if (port != "5665")
|
|
||||||
title += +":" + port;
|
|
||||||
|
|
||||||
title += " - Icinga Studio";
|
|
||||||
SetTitle(title);
|
SetTitle(title);
|
||||||
|
|
||||||
m_ObjectsList->InsertColumn(0, "Name", 0, 300);
|
m_ObjectsList->InsertColumn(0, "Name", 0, 300);
|
||||||
|
@ -289,19 +289,18 @@ bool Url::ParseAuthority(const String& authority)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Host = auth.SubStr(0, pos-1);
|
m_Host = auth.SubStr(0, pos);
|
||||||
return ValidateToken(m_Host, ACHOST);
|
return ValidateToken(m_Host, ACHOST);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Url::ParseUserinfo(const String& userinfo)
|
bool Url::ParseUserinfo(const String& userinfo)
|
||||||
{
|
{
|
||||||
size_t pos = userinfo.Find(":");
|
size_t pos = userinfo.Find(":");
|
||||||
m_Username = userinfo.SubStr(0, pos-1);
|
m_Username = userinfo.SubStr(0, pos);
|
||||||
if (!ValidateToken(m_Username, ACUSERINFO))
|
if (!ValidateToken(m_Username, ACUSERINFO))
|
||||||
return false;
|
return false;
|
||||||
m_Username = Utility::UnescapeString(m_Username);
|
m_Username = Utility::UnescapeString(m_Username);
|
||||||
if (pos != String::NPos && pos != userinfo.GetLength() - 1) {
|
if (pos != String::NPos && pos != userinfo.GetLength() - 1) {
|
||||||
//Password
|
|
||||||
m_Password = userinfo.SubStr(pos+1);
|
m_Password = userinfo.SubStr(pos+1);
|
||||||
if (!ValidateToken(m_Username, ACUSERINFO))
|
if (!ValidateToken(m_Username, ACUSERINFO))
|
||||||
return false;
|
return false;
|
||||||
@ -358,7 +357,7 @@ bool Url::ParseQuery(const String& query)
|
|||||||
String key = token.SubStr(0, pHelper);
|
String key = token.SubStr(0, pHelper);
|
||||||
String value = Empty;
|
String value = Empty;
|
||||||
|
|
||||||
if (pHelper != token.GetLength()-1)
|
if (pHelper != token.GetLength() - 1)
|
||||||
value = token.SubStr(pHelper+1);
|
value = token.SubStr(pHelper+1);
|
||||||
|
|
||||||
if (!ValidateToken(value, ACQUERY))
|
if (!ValidateToken(value, ACQUERY))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user