mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Fix: /v1/objects/<type> returns an HTTP error when there are no objects of that type
fixes #10253
This commit is contained in:
parent
08ccb4e323
commit
f3fdcb0f6b
@ -34,9 +34,14 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName)
|
|||||||
String uname = pluralName;
|
String uname = pluralName;
|
||||||
boost::algorithm::to_lower(uname);
|
boost::algorithm::to_lower(uname);
|
||||||
|
|
||||||
BOOST_FOREACH(const ConfigType::Ptr& dtype, ConfigType::GetTypes()) {
|
{
|
||||||
Type::Ptr type = Type::GetByName(dtype->GetName());
|
Dictionary::Ptr globals = ScriptGlobal::GetGlobals();
|
||||||
ASSERT(type);
|
ObjectLock olock(globals);
|
||||||
|
BOOST_FOREACH(const Dictionary::Pair& kv, globals) {
|
||||||
|
if (!kv.second.IsObjectType<Type>())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Type::Ptr type = kv.second;
|
||||||
|
|
||||||
String pname = type->GetPluralName();
|
String pname = type->GetPluralName();
|
||||||
boost::algorithm::to_lower(pname);
|
boost::algorithm::to_lower(pname);
|
||||||
@ -44,6 +49,7 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName)
|
|||||||
if (uname == pname)
|
if (uname == pname)
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Type::Ptr();
|
return Type::Ptr();
|
||||||
}
|
}
|
||||||
@ -51,12 +57,13 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName)
|
|||||||
void ConfigObjectTargetProvider::FindTargets(const String& type, const boost::function<void (const Value&)>& addTarget) const
|
void ConfigObjectTargetProvider::FindTargets(const String& type, const boost::function<void (const Value&)>& addTarget) const
|
||||||
{
|
{
|
||||||
ConfigType::Ptr dtype = ConfigType::GetByName(type);
|
ConfigType::Ptr dtype = ConfigType::GetByName(type);
|
||||||
ASSERT(dtype);
|
|
||||||
|
|
||||||
|
if (dtype) {
|
||||||
BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) {
|
BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) {
|
||||||
addTarget(object);
|
addTarget(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Value ConfigObjectTargetProvider::GetTargetByName(const String& type, const String& name) const
|
Value ConfigObjectTargetProvider::GetTargetByName(const String& type, const String& name) const
|
||||||
{
|
{
|
||||||
@ -70,7 +77,12 @@ Value ConfigObjectTargetProvider::GetTargetByName(const String& type, const Stri
|
|||||||
|
|
||||||
bool ConfigObjectTargetProvider::IsValidType(const String& type) const
|
bool ConfigObjectTargetProvider::IsValidType(const String& type) const
|
||||||
{
|
{
|
||||||
return ConfigType::GetByName(type) != ConfigType::Ptr();
|
Type::Ptr ptype = Type::GetByName(type);
|
||||||
|
|
||||||
|
if (!ptype)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return ConfigObject::TypeInstance->IsAssignableFrom(ptype);
|
||||||
}
|
}
|
||||||
|
|
||||||
String ConfigObjectTargetProvider::GetPluralName(const String& type) const
|
String ConfigObjectTargetProvider::GetPluralName(const String& type) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user