Disallow modify attribute for certain object attributes

fixes #9095
This commit is contained in:
Michael Friedrich 2015-10-15 16:33:20 +02:00
parent 4fb5329e60
commit 6cc4f85c66
8 changed files with 21 additions and 15 deletions

View File

@ -130,6 +130,9 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
int fid = type->GetFieldId(fieldName);
Field field = type->GetFieldInfo(fid);
if (field.Attributes & FAInternal || field.Attributes & FANoModify)
BOOST_THROW_EXCEPTION(std::invalid_argument("Attribute cannot be modified."));
if (field.Attributes & FAConfig) {
if (!original_attributes) {
original_attributes = new Dictionary();

View File

@ -68,8 +68,8 @@ private:
abstract class ConfigObject : ConfigObjectBase
{
[config, internal] String __name (Name);
[config] String "name" (ShortName) {
[config, internal, no_modify] String __name (Name);
[config, no_modify] String "name" (ShortName) {
get {{{
if (m_ShortName.IsEmpty())
return GetName();
@ -77,22 +77,22 @@ abstract class ConfigObject : ConfigObjectBase
return m_ShortName;
}}}
};
[config, internal, get_protected] String type (TypeNameV);
[config, internal, get_protected, no_modify] String type (TypeNameV);
[config] name(Zone) zone (ZoneName);
[config] String package;
[config, internal, get_protected] Array::Ptr templates;
[config, internal, get_protected, no_modify] Array::Ptr templates;
[get_protected] bool active;
[get_protected] bool paused {
default {{{ return true; }}}
};
[get_protected, internal] bool start_called;
[get_protected, internal] bool stop_called;
[get_protected, internal] bool pause_called;
[get_protected, internal] bool resume_called;
[get_protected, internal, no_modify] bool start_called;
[get_protected, internal, no_modify] bool stop_called;
[get_protected, internal, no_modify] bool pause_called;
[get_protected, internal, no_modify] bool resume_called;
[enum] HAMode ha_mode (HAMode);
[protected] Dictionary::Ptr extensions;
[protected, no_modify] Dictionary::Ptr extensions;
[protected] bool state_loaded;
[protected, no_modify] bool state_loaded;
Dictionary::Ptr original_attributes;
[state] double version {
default {{{ return 0; }}}

View File

@ -38,7 +38,8 @@ enum FieldAttribute
FAState = 4,
FAInternal = 64,
FARequired = 512,
FANavigation = 1024
FANavigation = 1024,
FANoModify = 2048
};
class Type;

View File

@ -27,7 +27,7 @@ namespace icinga
class Host : Checkable
{
[config] array(name(HostGroup)) groups {
[config, no_modify] array(name(HostGroup)) groups {
default {{{ return new Array(); }}}
};

View File

@ -40,7 +40,7 @@ class Service : Checkable < ServiceNameComposer
{
load_after Host;
[config] array(name(ServiceGroup)) groups {
[config, no_modify] array(name(ServiceGroup)) groups {
default {{{ return new Array(); }}}
};

View File

@ -35,7 +35,7 @@ class User : CustomVarObject
return m_DisplayName;
}}}
};
[config] array(name(UserGroup)) groups {
[config, no_modify] array(name(UserGroup)) groups {
default {{{ return new Array(); }}}
};
[config, navigation] name(TimePeriod) period (PeriodRaw) {

View File

@ -146,6 +146,7 @@ protected { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTR
internal { yylval->num = FAInternal; return T_FIELD_ATTRIBUTE; }
no_storage { yylval->num = FANoStorage; return T_FIELD_ATTRIBUTE; }
navigation { return T_NAVIGATION; }
no_modify { yylval->num = FANoModify; return T_FIELD_ATTRIBUTE; }
validator { return T_VALIDATOR; }
required { return T_REQUIRED; }
name { return T_NAME; }

View File

@ -71,7 +71,8 @@ enum FieldAttribute
FANoStorage = 128,
FALoadDependency = 256,
FARequired = 512,
FANavigation = 1024
FANavigation = 1024,
FANoModify = 2048
};
struct FieldType