mirror of https://github.com/Icinga/icinga2.git
Allow using more than one %validator rule for the same type
fixes #8829
This commit is contained in:
parent
ae204092cc
commit
e8cee8d5e2
|
@ -372,9 +372,9 @@ type: T_TYPE identifier
|
||||||
context->m_Type->GetRuleList()->AddRules(ruleList);
|
context->m_Type->GetRuleList()->AddRules(ruleList);
|
||||||
context->m_Type->GetRuleList()->AddRequires(ruleList);
|
context->m_Type->GetRuleList()->AddRequires(ruleList);
|
||||||
|
|
||||||
String validator = ruleList->GetValidator();
|
BOOST_FOREACH(const String& validator, ruleList->GetValidators()) {
|
||||||
if (!validator.IsEmpty())
|
context->m_Type->GetRuleList()->AddValidator(validator);
|
||||||
context->m_Type->GetRuleList()->SetValidator(validator);
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ typerule: T_REQUIRE T_STRING
|
||||||
}
|
}
|
||||||
| T_VALIDATOR T_STRING
|
| T_VALIDATOR T_STRING
|
||||||
{
|
{
|
||||||
context->m_RuleLists.top()->SetValidator($2);
|
context->m_RuleLists.top()->AddValidator($2);
|
||||||
free($2);
|
free($2);
|
||||||
}
|
}
|
||||||
| T_ATTRIBUTE type T_STRING
|
| T_ATTRIBUTE type T_STRING
|
||||||
|
|
|
@ -169,9 +169,7 @@ void ConfigType::ValidateObject(const Object::Ptr& object,
|
||||||
locations.pop_back();
|
locations.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
String validator = ruleList->GetValidator();
|
BOOST_FOREACH(const String& validator, ruleList->GetValidators()) {
|
||||||
|
|
||||||
if (!validator.IsEmpty()) {
|
|
||||||
Function::Ptr func = ScriptGlobal::Get(validator, &Empty);
|
Function::Ptr func = ScriptGlobal::Get(validator, &Empty);
|
||||||
|
|
||||||
if (!func)
|
if (!func)
|
||||||
|
@ -226,9 +224,7 @@ void ConfigType::ValidateArray(const Array::Ptr& array,
|
||||||
locations.pop_back();
|
locations.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
String validator = ruleList->GetValidator();
|
BOOST_FOREACH(const String& validator, ruleList->GetValidators()) {
|
||||||
|
|
||||||
if (!validator.IsEmpty()) {
|
|
||||||
Function::Ptr func = ScriptGlobal::Get(validator, &Empty);
|
Function::Ptr func = ScriptGlobal::Get(validator, &Empty);
|
||||||
|
|
||||||
if (!func)
|
if (!func)
|
||||||
|
|
|
@ -24,23 +24,23 @@
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the validator method for a rule list.
|
* Adds a validator method for a rule list.
|
||||||
*
|
*
|
||||||
* @param validator The validator.
|
* @param validator The validator.
|
||||||
*/
|
*/
|
||||||
void TypeRuleList::SetValidator(const String& validator)
|
void TypeRuleList::AddValidator(const String& validator)
|
||||||
{
|
{
|
||||||
m_Validator = validator;
|
m_Validators.push_back(validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the validator method.
|
* Retrieves the validator methods.
|
||||||
*
|
*
|
||||||
* @returns The validator method.
|
* @returns The validator methods.
|
||||||
*/
|
*/
|
||||||
String TypeRuleList::GetValidator(void) const
|
std::vector<String> TypeRuleList::GetValidators(void) const
|
||||||
{
|
{
|
||||||
return m_Validator;
|
return m_Validators;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -50,8 +50,8 @@ class I2_CONFIG_API TypeRuleList : public Object
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(TypeRuleList);
|
DECLARE_PTR_TYPEDEFS(TypeRuleList);
|
||||||
|
|
||||||
void SetValidator(const String& validator);
|
void AddValidator(const String& validator);
|
||||||
String GetValidator(void) const;
|
std::vector<String> GetValidators(void) const;
|
||||||
|
|
||||||
void AddRequire(const String& attr);
|
void AddRequire(const String& attr);
|
||||||
void AddRequires(const TypeRuleList::Ptr& ruleList);
|
void AddRequires(const TypeRuleList::Ptr& ruleList);
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
size_t GetLength(void) const;
|
size_t GetLength(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_Validator;
|
std::vector<String> m_Validators;
|
||||||
std::vector<String> m_Requires;
|
std::vector<String> m_Requires;
|
||||||
std::vector<TypeRule> m_Rules;
|
std::vector<TypeRule> m_Rules;
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,7 +82,7 @@ void Command::ValidateArguments(const String& location, const Command::Ptr& obje
|
||||||
|
|
||||||
String argstr = argval;
|
String argstr = argval;
|
||||||
|
|
||||||
if(!MacroProcessor::ValidateMacroString(argstr)) {
|
if (!MacroProcessor::ValidateMacroString(argstr)) {
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
|
BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
|
||||||
location + ": Closing $ not found in macro format string '" + argstr + "'.", object->GetDebugInfo()));
|
location + ": Closing $ not found in macro format string '" + argstr + "'.", object->GetDebugInfo()));
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ void Command::ValidateEnvironmentVariables(const String& location, const Command
|
||||||
if (!envval.IsString() || envval.IsEmpty())
|
if (!envval.IsString() || envval.IsEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(!MacroProcessor::ValidateMacroString(envval)) {
|
if (!MacroProcessor::ValidateMacroString(envval)) {
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
|
BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
|
||||||
location + ": Closing $ not found in macro format string '" + envval + "'.", object->GetDebugInfo()));
|
location + ": Closing $ not found in macro format string '" + envval + "'.", object->GetDebugInfo()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue