mirror of https://github.com/Icinga/icinga2.git
parent
6fb1b60c12
commit
143aa13118
|
@ -54,6 +54,12 @@ void ApiClient::TypesHttpCompletionCallback(HttpRequest& request, HttpResponse&
|
|||
while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0)
|
||||
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;
|
||||
|
||||
try {
|
||||
|
@ -83,7 +89,7 @@ void ApiClient::TypesHttpCompletionCallback(HttpRequest& request, HttpResponse&
|
|||
void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback,
|
||||
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;
|
||||
|
||||
BOOST_FOREACH(const String& name, names) {
|
||||
|
@ -119,6 +125,12 @@ void ApiClient::ObjectsHttpCompletionCallback(HttpRequest& request,
|
|||
while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0)
|
||||
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;
|
||||
|
||||
try {
|
||||
|
@ -126,35 +138,37 @@ void ApiClient::ObjectsHttpCompletionCallback(HttpRequest& request,
|
|||
|
||||
Array::Ptr results = result->Get("results");
|
||||
|
||||
ObjectLock olock(results);
|
||||
BOOST_FOREACH(const Dictionary::Ptr objectInfo, results)
|
||||
{
|
||||
ApiObject::Ptr object = new ApiObject();
|
||||
|
||||
Dictionary::Ptr attrs = objectInfo->Get("attrs");
|
||||
|
||||
if (results) {
|
||||
ObjectLock olock(results);
|
||||
BOOST_FOREACH(const Dictionary::Ptr objectInfo, results)
|
||||
{
|
||||
ObjectLock olock(attrs);
|
||||
BOOST_FOREACH(const Dictionary::Pair& kv, attrs)
|
||||
ApiObject::Ptr object = new ApiObject();
|
||||
|
||||
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;
|
||||
ref.Name = refInfo->Get("name");
|
||||
ref.Type = refInfo->Get("type");
|
||||
object->UsedBy.push_back(ref);
|
||||
ObjectLock olock(used_by);
|
||||
BOOST_FOREACH(const Dictionary::Ptr& refInfo, used_by)
|
||||
{
|
||||
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) {
|
||||
Log(LogCritical, "ApiClient")
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
return false;
|
||||
|
||||
pUrl = f.GetUrl();
|
||||
url = pUrl->Format();
|
||||
url = pUrl->Format(true);
|
||||
wUrl = url;
|
||||
config.Write("url", wUrl);
|
||||
} else {
|
||||
|
|
|
@ -33,40 +33,15 @@ MainForm::MainForm(wxWindow *parent, const Url::Ptr& url)
|
|||
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
|
||||
#endif /* _WIN32 */
|
||||
|
||||
String host, port, user, pass;
|
||||
String port = url->GetPort();
|
||||
|
||||
std::string authority = url->GetAuthority();
|
||||
|
||||
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
|
||||
if (port.IsEmpty())
|
||||
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));
|
||||
|
||||
std::string title = host;
|
||||
|
||||
if (port != "5665")
|
||||
title += +":" + port;
|
||||
|
||||
title += " - Icinga Studio";
|
||||
std::string title = url->Format() + " - Icinga Studio";
|
||||
SetTitle(title);
|
||||
|
||||
m_ObjectsList->InsertColumn(0, "Name", 0, 300);
|
||||
|
|
|
@ -289,19 +289,18 @@ bool Url::ParseAuthority(const String& authority)
|
|||
return false;
|
||||
}
|
||||
|
||||
m_Host = auth.SubStr(0, pos-1);
|
||||
m_Host = auth.SubStr(0, pos);
|
||||
return ValidateToken(m_Host, ACHOST);
|
||||
}
|
||||
|
||||
bool Url::ParseUserinfo(const String& userinfo)
|
||||
{
|
||||
size_t pos = userinfo.Find(":");
|
||||
m_Username = userinfo.SubStr(0, pos-1);
|
||||
m_Username = userinfo.SubStr(0, pos);
|
||||
if (!ValidateToken(m_Username, ACUSERINFO))
|
||||
return false;
|
||||
m_Username = Utility::UnescapeString(m_Username);
|
||||
if (pos != String::NPos && pos != userinfo.GetLength() - 1) {
|
||||
//Password
|
||||
m_Password = userinfo.SubStr(pos+1);
|
||||
if (!ValidateToken(m_Username, ACUSERINFO))
|
||||
return false;
|
||||
|
@ -358,7 +357,7 @@ bool Url::ParseQuery(const String& query)
|
|||
String key = token.SubStr(0, pHelper);
|
||||
String value = Empty;
|
||||
|
||||
if (pHelper != token.GetLength()-1)
|
||||
if (pHelper != token.GetLength() - 1)
|
||||
value = token.SubStr(pHelper+1);
|
||||
|
||||
if (!ValidateToken(value, ACQUERY))
|
||||
|
|
Loading…
Reference in New Issue