Hide internal attributes in the API

fixes #10393
This commit is contained in:
Gunnar Beutner 2015-10-20 08:20:35 +02:00
parent b77c9edca0
commit d01f09f3ef
21 changed files with 55 additions and 50 deletions

View File

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

View File

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

View File

@ -36,10 +36,10 @@ enum FieldAttribute
FAEphemeral = 1, FAEphemeral = 1,
FAConfig = 2, FAConfig = 2,
FAState = 4, FAState = 4,
FAInternal = 64, FARequired = 256,
FARequired = 512, FANavigation = 512,
FANavigation = 1024, FANoUserModify = 1024,
FANoModify = 2048 FANoUserView = 2048
}; };
class Type; class Type;

View File

@ -73,7 +73,7 @@ std::vector<String> icinga::GetFieldCompletionSuggestions(const Type::Ptr& type,
for (int i = 0; i < type->GetFieldCount(); i++) { for (int i = 0; i < type->GetFieldCount(); i++) {
Field field = type->GetFieldInfo(i); Field field = type->GetFieldInfo(i);
if (!(field.Attributes & FAConfig) || field.Attributes & FAInternal) if (field.Attributes & FANoUserView)
continue; continue;
if (strcmp(field.TypeName, "int") != 0 && strcmp(field.TypeName, "double") != 0 if (strcmp(field.TypeName, "int") != 0 && strcmp(field.TypeName, "double") != 0

View File

@ -51,9 +51,9 @@ abstract class DbConnection : ConfigObject
default {{{ return 60; }}} default {{{ return 60; }}}
}; };
String schema_version; [no_user_modify] String schema_version;
bool connected; [no_user_modify] bool connected;
bool should_connect { [no_user_modify] bool should_connect {
default {{{ return true; }}} default {{{ return true; }}}
}; };
}; };

View File

@ -137,10 +137,10 @@ abstract class Checkable : CustomVarObject
default {{{ return AcknowledgementNone; }}} default {{{ return AcknowledgementNone; }}}
}; };
[state] double acknowledgement_expiry; [state] double acknowledgement_expiry;
[state] Dictionary::Ptr comments { [state, no_user_modify] Dictionary::Ptr comments {
default {{{ return new Dictionary(); }}} default {{{ return new Dictionary(); }}}
}; };
[state] Dictionary::Ptr downtimes { [state, no_user_modify] Dictionary::Ptr downtimes {
default {{{ return new Dictionary(); }}} default {{{ return new Dictionary(); }}}
}; };
[state] bool force_next_notification; [state] bool force_next_notification;

View File

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

View File

@ -35,7 +35,7 @@ class HostGroup : CustomVarObject
}}} }}}
}; };
[config] array(name(HostGroup)) groups; [config, no_user_modify] array(name(HostGroup)) groups;
[config] String notes; [config] String notes;
[config] String notes_url; [config] String notes_url;
[config] String action_url; [config] String action_url;

View File

@ -86,7 +86,7 @@ class Notification : CustomVarObject < NotificationNameComposer
}}} }}}
}; };
[state] Array::Ptr notified_users { [state, no_user_modify] Array::Ptr notified_users {
default {{{ return new Array(); }}} default {{{ return new Array(); }}}
}; };

View File

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

View File

@ -35,7 +35,7 @@ class ServiceGroup : CustomVarObject
}}} }}}
}; };
[config] array(name(ServiceGroup)) groups; [config, no_user_modify] array(name(ServiceGroup)) groups;
[config] String notes; [config] String notes;
[config] String notes_url; [config] String notes_url;
[config] String action_url; [config] String action_url;

View File

@ -37,9 +37,9 @@ class TimePeriod : CustomVarObject
}; };
[config] Dictionary::Ptr ranges; [config] Dictionary::Ptr ranges;
[config, required] Function::Ptr update; [config, required] Function::Ptr update;
[state] Value valid_begin; [state, no_user_modify] Value valid_begin;
[state] Value valid_end; [state, no_user_modify] Value valid_end;
[state] Array::Ptr segments; [state, no_user_modify] Array::Ptr segments;
[no_storage] bool is_inside { [no_storage] bool is_inside {
get; get;
}; };

View File

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

View File

@ -35,7 +35,7 @@ class UserGroup : CustomVarObject
}}} }}}
}; };
[config] array(name(UserGroup)) groups; [config, no_user_modify] array(name(UserGroup)) groups;
}; };
} }

View File

@ -43,9 +43,9 @@ class ApiListener : ConfigObject
[config] String ticket_salt; [config] String ticket_salt;
[state] double log_message_timestamp; [state, no_user_modify] double log_message_timestamp;
String identity; [no_user_modify] String identity;
}; };
} }

View File

@ -27,7 +27,7 @@ namespace icinga
class ApiUser : ConfigObject class ApiUser : ConfigObject
{ {
[config] String password; [config, no_user_view] String password;
[config] String client_cn (ClientCN); [config] String client_cn (ClientCN);
[config] array(Value) permissions; [config] array(Value) permissions;
}; };

View File

@ -37,8 +37,8 @@ class Endpoint : ConfigObject
[state] double local_log_position; [state] double local_log_position;
[state] double remote_log_position; [state] double remote_log_position;
bool connecting; [no_user_modify] bool connecting;
bool syncing; [no_user_modify] bool syncing;
}; };
} }

View File

@ -160,6 +160,10 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
Value val = joinedObj->GetField(fid); Value val = joinedObj->GetField(fid);
/* hide attributes which shouldn't be user-visible */
if (field.Attributes & FANoUserView)
continue;
/* hide internal navigation fields */ /* hide internal navigation fields */
if (field.Attributes & FANavigation) { if (field.Attributes & FANavigation) {
Value nval = joinedObj->NavigateField(fid); Value nval = joinedObj->NavigateField(fid);

View File

@ -148,9 +148,10 @@ bool TypeQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& requ
attributeInfo->Set("config", static_cast<bool>(field.Attributes & FAConfig)); attributeInfo->Set("config", static_cast<bool>(field.Attributes & FAConfig));
attributeInfo->Set("state", static_cast<bool>(field.Attributes & FAState)); attributeInfo->Set("state", static_cast<bool>(field.Attributes & FAState));
attributeInfo->Set("internal", static_cast<bool>(field.Attributes & FAInternal));
attributeInfo->Set("required", static_cast<bool>(field.Attributes & FARequired)); attributeInfo->Set("required", static_cast<bool>(field.Attributes & FARequired));
attributeInfo->Set("navigation", static_cast<bool>(field.Attributes & FANavigation)); attributeInfo->Set("navigation", static_cast<bool>(field.Attributes & FANavigation));
attributeInfo->Set("no_user_modify", static_cast<bool>(field.Attributes & FANoUserModify));
attributeInfo->Set("no_user_view", static_cast<bool>(field.Attributes & FANoUserView));
} }
} }

View File

@ -143,10 +143,10 @@ enum { yylval->num = FAEnum; return T_FIELD_ATTRIBUTE; }
get_protected { yylval->num = FAGetProtected; return T_FIELD_ATTRIBUTE; } get_protected { yylval->num = FAGetProtected; return T_FIELD_ATTRIBUTE; }
set_protected { yylval->num = FASetProtected; return T_FIELD_ATTRIBUTE; } set_protected { yylval->num = FASetProtected; return T_FIELD_ATTRIBUTE; }
protected { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTRIBUTE; } protected { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTRIBUTE; }
internal { yylval->num = FAInternal; return T_FIELD_ATTRIBUTE; }
no_storage { yylval->num = FANoStorage; return T_FIELD_ATTRIBUTE; } no_storage { yylval->num = FANoStorage; return T_FIELD_ATTRIBUTE; }
no_user_modify { yylval->num = FANoUserModify; return T_FIELD_ATTRIBUTE; }
no_user_view { yylval->num = FANoUserView; return T_FIELD_ATTRIBUTE; }
navigation { return T_NAVIGATION; } navigation { return T_NAVIGATION; }
no_modify { yylval->num = FANoModify; return T_FIELD_ATTRIBUTE; }
validator { return T_VALIDATOR; } validator { return T_VALIDATOR; }
required { return T_REQUIRED; } required { return T_REQUIRED; }
name { return T_NAME; } name { return T_NAME; }

View File

@ -67,12 +67,12 @@ enum FieldAttribute
FAEnum = 8, FAEnum = 8,
FAGetProtected = 16, FAGetProtected = 16,
FASetProtected = 32, FASetProtected = 32,
FAInternal = 64, FANoStorage = 64,
FANoStorage = 128, FALoadDependency = 128,
FALoadDependency = 256, FARequired = 256,
FARequired = 512, FANavigation = 512,
FANavigation = 1024, FANoUserModify = 1024,
FANoModify = 2048 FANoUserView = 2048
}; };
struct FieldType struct FieldType