From: Michael Friedrich Date: Fri, 6 Apr 2018 10:32:27 +0000 (+0200) Subject: API: Check if objects exists and return proper error message X-Git-Tag: v2.9.0~100^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd7598cb1bbe58fda538069ca683b97a3b4b4f87;p=icinga2 API: Check if objects exists and return proper error message --- diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index 38fda3824..b5026114a 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -110,6 +110,13 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full } } + ConfigItem::Ptr item = ConfigItem::GetByTypeAndName(type, fullName); + + if (item) { + errors->Add("Object '" + fullName + "' already exists."); + return false; + } + String path = GetObjectConfigPath(type, fullName); Utility::MkDirP(Utility::DirName(path), 0700);