]> granicus.if.org Git - icinga2/commitdiff
Hide internal attributes in the API
authorGunnar Beutner <gunnar@beutner.name>
Tue, 20 Oct 2015 06:20:35 +0000 (08:20 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 20 Oct 2015 06:25:10 +0000 (08:25 +0200)
fixes #10393

21 files changed:
lib/base/configobject.cpp
lib/base/configobject.ti
lib/base/type.hpp
lib/cli/clicommand.cpp
lib/db_ido/dbconnection.ti
lib/icinga/checkable.ti
lib/icinga/host.ti
lib/icinga/hostgroup.ti
lib/icinga/notification.ti
lib/icinga/service.ti
lib/icinga/servicegroup.ti
lib/icinga/timeperiod.ti
lib/icinga/user.ti
lib/icinga/usergroup.ti
lib/remote/apilistener.ti
lib/remote/apiuser.ti
lib/remote/endpoint.ti
lib/remote/objectqueryhandler.cpp
lib/remote/typequeryhandler.cpp
tools/mkclass/class_lexer.ll
tools/mkclass/classcompiler.hpp

index 0cfa71b9343c53553f0dd5152f8b739a97bbb66c..3f0590f79c7aafccbace7690d4456bf3b6112a59 100644 (file)
@@ -130,7 +130,7 @@ 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)
+       if (field.Attributes & FANoUserModify)
                BOOST_THROW_EXCEPTION(std::invalid_argument("Attribute cannot be modified."));
 
        if (field.Attributes & FAConfig) {
index 90a514a1c789a5e27f0bab3d9a10938e320fcb15..ba19b7bc15d8594010abacc6606bb40e07840f3c 100644 (file)
@@ -68,8 +68,8 @@ private:
 
 abstract class ConfigObject : ConfigObjectBase
 {
-       [config, internal, no_modify] String __name (Name);
-       [config, no_modify] String "name" (ShortName) {
+       [config, no_user_modify] String __name (Name);
+       [config, no_user_modify] String "name" (ShortName) {
                get {{{
                        if (m_ShortName.IsEmpty())
                                return GetName();
@@ -77,24 +77,24 @@ abstract class ConfigObject : ConfigObjectBase
                                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] String package;
-       [config, internal, get_protected, no_modify] Array::Ptr templates;
-       [get_protected] bool active;
-       [get_protected] bool paused {
+       [config, no_user_modify] String package;
+       [config, get_protected, no_user_modify] Array::Ptr templates;
+       [get_protected, no_user_modify] bool active;
+       [get_protected, no_user_modify] bool paused {
                default {{{ return true; }}}
        };
-       [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;
+       [get_protected, no_user_view, no_user_modify] bool start_called;
+       [get_protected, no_user_view, no_user_modify] bool stop_called;
+       [get_protected, no_user_view, no_user_modify] bool pause_called;
+       [get_protected, no_user_view, no_user_modify] bool resume_called;
        [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;
-       Dictionary::Ptr original_attributes;
-       [state] double version {
+       [protected, no_user_view, no_user_modify] bool state_loaded;
+       [no_user_modify] Dictionary::Ptr original_attributes;
+       [state, no_user_modify] double version {
                default {{{ return 0; }}}
        };
 };
index dd13d9902f0d2bbce046a3ecccd763172e4ea002..f5687a3754e9c0e2939bfab3b9e05c563961bc0e 100644 (file)
@@ -36,10 +36,10 @@ enum FieldAttribute
        FAEphemeral = 1,
        FAConfig = 2,
        FAState = 4,
-       FAInternal = 64,
-       FARequired = 512,
-       FANavigation = 1024,
-       FANoModify = 2048
+       FARequired = 256,
+       FANavigation = 512,
+       FANoUserModify = 1024,
+       FANoUserView = 2048
 };
 
 class Type;
index 0694c89642bf2f92700975996f7e7edf012cc616..30d52aa285866812b2f50b616774146b23d1dd44 100644 (file)
@@ -73,7 +73,7 @@ std::vector<String> icinga::GetFieldCompletionSuggestions(const Type::Ptr& type,
        for (int i = 0; i < type->GetFieldCount(); i++) {
                Field field = type->GetFieldInfo(i);
 
-               if (!(field.Attributes & FAConfig) || field.Attributes & FAInternal)
+               if (field.Attributes & FANoUserView)
                        continue;
 
                if (strcmp(field.TypeName, "int") != 0 && strcmp(field.TypeName, "double") != 0
index f1f2bef440eaf6be9bc7a8bbeb4488fc01c339b3..57d47c70dc28cad9069a6206e6c40e3bc68b1fd8 100644 (file)
@@ -51,9 +51,9 @@ abstract class DbConnection : ConfigObject
                default {{{ return 60; }}}
        };
 
-       String schema_version;
-       bool connected;
-       bool should_connect {
+       [no_user_modify] String schema_version;
+       [no_user_modify] bool connected;
+       [no_user_modify] bool should_connect {
                default {{{ return true; }}}
        };
 };
index afb5a75940eda31c7a5ae609dac21ac3453b59c7..d6ed943c2e3ae7576703a06d0042c9aefae10654 100644 (file)
@@ -137,10 +137,10 @@ abstract class Checkable : CustomVarObject
                default {{{ return AcknowledgementNone; }}}
        };
        [state] double acknowledgement_expiry;
-       [state] Dictionary::Ptr comments {
+       [state, no_user_modify] Dictionary::Ptr comments {
                default {{{ return new Dictionary(); }}}
        };
-       [state] Dictionary::Ptr downtimes {
+       [state, no_user_modify] Dictionary::Ptr downtimes {
                default {{{ return new Dictionary(); }}}
        };
        [state] bool force_next_notification;
index c183998c9d895ae6cbb67d6be1c0e8f0990c4a5b..37af4343771cb54684c6d621862374f2ad0ca37a 100644 (file)
@@ -27,7 +27,7 @@ namespace icinga
 
 class Host : Checkable
 {
-       [config, no_modify] array(name(HostGroup)) groups {
+       [config, no_user_modify] array(name(HostGroup)) groups {
                default {{{ return new Array(); }}}
        };
 
index 2b8d4175ce76a80ed08e34422aac432261fd8c05..8a8b41774f2246771ccbecce7112f4f75b32cbd8 100644 (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_url;
        [config] String action_url;
index 5df94ed1f61275bfc943093da8be587e95dac63f..06a03f4bac3e0ca72b96f54e1f5abc4ccc0f28eb 100644 (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(); }}}
        };
 
index db09fe9451d80d661bec007bea3c5cdd5cab37d6..224e5fc58031b9d4c7048cfcad7e7d215b7eb8ca 100644 (file)
@@ -40,7 +40,7 @@ class Service : Checkable < ServiceNameComposer
 {
        load_after Host;
 
-       [config, no_modify] array(name(ServiceGroup)) groups {
+       [config, no_user_modify] array(name(ServiceGroup)) groups {
                default {{{ return new Array(); }}}
        };
 
index eb69b56dc5e3fe7d17e234bd7f67d3309ef2e5a6..12b9d738b79be8417463dbc982399dc6828a7a12 100644 (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_url;
        [config] String action_url;
index f7cf8ff4d72e64a05e784340332eb1c824c2999d..5bd6d0885bad341077cf3f2d49b6a325286ce5d4 100644 (file)
@@ -37,9 +37,9 @@ class TimePeriod : CustomVarObject
        };
        [config] Dictionary::Ptr ranges;
        [config, required] Function::Ptr update;
-       [state] Value valid_begin;
-       [state] Value valid_end;
-       [state] Array::Ptr segments;
+       [state, no_user_modify] Value valid_begin;
+       [state, no_user_modify] Value valid_end;
+       [state, no_user_modify] Array::Ptr segments;
        [no_storage] bool is_inside {
                get;
        };
index e6781ade7adc0491083e8a879858f0c88bb3242b..0443eca30d95b19087aa37b4fdf06792cd443e26 100644 (file)
@@ -35,7 +35,7 @@ class User : CustomVarObject
                                return m_DisplayName;
                }}}
        };
-       [config, no_modify] array(name(UserGroup)) groups {
+       [config, no_user_modify] array(name(UserGroup)) groups {
                default {{{ return new Array(); }}}
        };
        [config, navigation] name(TimePeriod) period (PeriodRaw) {
index f1c480a41c090510a06b17b8e39d2f9187ab3d95..1ebcb8b1f805beb61291a7722afe36b9b5a86e2b 100644 (file)
@@ -35,7 +35,7 @@ class UserGroup : CustomVarObject
                }}}
        };
 
-       [config] array(name(UserGroup)) groups;
+       [config, no_user_modify] array(name(UserGroup)) groups;
 };
 
 }
index 2b7e82be2ac0bb54bdce7539ec78e815b321d3d0..9432d6f2f8c39f76da44bd5d39bf45214a32f2ba 100644 (file)
@@ -43,9 +43,9 @@ class ApiListener : ConfigObject
 
        [config] String ticket_salt;
 
-       [state] double log_message_timestamp;
+       [state, no_user_modify] double log_message_timestamp;
 
-       String identity;
+       [no_user_modify] String identity;
 };
 
 }
index ac4666e99c986446eb030a2390699b849845b960..21087c90a3c18abbbf5dff18b3afdedfe9c86cd5 100644 (file)
@@ -27,7 +27,7 @@ namespace icinga
 
 class ApiUser : ConfigObject
 {
-       [config] String password;
+       [config, no_user_view] String password;
        [config] String client_cn (ClientCN);
        [config] array(Value) permissions;
 };
index eab3fb7390a95ad97245a313bc28feb491b81907..f4eccef9956ed89db048ccc9bf176dc4ac8af5eb 100644 (file)
@@ -37,8 +37,8 @@ class Endpoint : ConfigObject
        [state] double local_log_position;
        [state] double remote_log_position;
 
-       bool connecting;
-       bool syncing;
+       [no_user_modify] bool connecting;
+       [no_user_modify] bool syncing;
 };
 
 }
index 888d5a50fe45c7181f402c46ff1d0a652671bc9f..ad85955edb4c6f813455e2f5bceeb680003000a0 100644 (file)
@@ -160,6 +160,10 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
 
                                Value val = joinedObj->GetField(fid);
 
+                               /* hide attributes which shouldn't be user-visible */
+                               if (field.Attributes & FANoUserView)
+                                       continue;
+
                                /* hide internal navigation fields */
                                if (field.Attributes & FANavigation) {
                                        Value nval = joinedObj->NavigateField(fid);
index c278177cbe359e3a1d474c0c970e8ff096546c3b..4e4029665fb08f52829c1bf1885402c140ce2dc5 100644 (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("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("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));
                }
        }
 
index 63eaf1ddb6c4327ac7e379f94dc728c84338629b..679a651eb27453bfda38663a5b4394d7ac073477 100644 (file)
@@ -143,10 +143,10 @@ enum                              { yylval->num = FAEnum; return T_FIELD_ATTRIBUTE; }
 get_protected                  { yylval->num = FAGetProtected; return T_FIELD_ATTRIBUTE; }
 set_protected                  { yylval->num = 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_user_modify                 { yylval->num = FANoUserModify; return T_FIELD_ATTRIBUTE; }
+no_user_view                   { yylval->num = FANoUserView; 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; }
index 576cd61ad6bb7be568b38de4a65197ee33858b9d..456b5ffdc1d791eb95fe191f951d0021de613229 100644 (file)
@@ -67,12 +67,12 @@ enum FieldAttribute
        FAEnum = 8,
        FAGetProtected = 16,
        FASetProtected = 32,
-       FAInternal = 64,
-       FANoStorage = 128,
-       FALoadDependency = 256,
-       FARequired = 512,
-       FANavigation = 1024,
-       FANoModify = 2048
+       FANoStorage = 64,
+       FALoadDependency = 128,
+       FARequired = 256,
+       FANavigation = 512,
+       FANoUserModify = 1024,
+       FANoUserView = 2048
 };
 
 struct FieldType