From 08c361462026a6ba3a7956b2870f9b84ff00eaa8 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 17 Dec 2015 14:29:08 +0100 Subject: [PATCH] IcingaApiUser: introduce a new object type --- library/Director/Objects/IcingaApiUser.php | 19 +++++++++++++++++++ library/Director/Objects/IcingaEndpoint.php | 9 ++++++++- schema/mysql-changes/upgrade_57.sql | 20 ++++++++++++++++++++ schema/mysql.sql | 16 ++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 library/Director/Objects/IcingaApiUser.php create mode 100644 schema/mysql-changes/upgrade_57.sql diff --git a/library/Director/Objects/IcingaApiUser.php b/library/Director/Objects/IcingaApiUser.php new file mode 100644 index 00000000..7c41feb2 --- /dev/null +++ b/library/Director/Objects/IcingaApiUser.php @@ -0,0 +1,19 @@ + null, + 'object_name' => null, + 'object_type' => null, + 'password' => null, + 'client_dn' => null, + 'permissions' => null, + ); +} diff --git a/library/Director/Objects/IcingaEndpoint.php b/library/Director/Objects/IcingaEndpoint.php index 52f285bf..4d073d4d 100644 --- a/library/Director/Objects/IcingaEndpoint.php +++ b/library/Director/Objects/IcingaEndpoint.php @@ -16,14 +16,21 @@ class IcingaEndpoint extends IcingaObject 'port' => null, 'log_duration' => null, 'object_type' => null, + 'apiuser_id' => null, ); protected $relations = array( - 'zone' => 'IcingaZone', + 'zone' => 'IcingaZone', + 'apiuser' => 'IcingaApiUser', ); protected function renderLog_duration() { return $this->renderPropertyAsSeconds('log_duration'); } + + protected function renderApiuser_id() + { + return ''; + } } diff --git a/schema/mysql-changes/upgrade_57.sql b/schema/mysql-changes/upgrade_57.sql new file mode 100644 index 00000000..3b2f7562 --- /dev/null +++ b/schema/mysql-changes/upgrade_57.sql @@ -0,0 +1,20 @@ + +CREATE TABLE icinga_apiuser ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(255) NOT NULL, + object_type ENUM('object', 'template', 'external_object') NOT NULL, + password VARCHAR(255) DEFAULT NULL, + client_dn VARCHAR(64) DEFAULT NULL, + permissions TEXT DEFAULT NULL COMMENT 'JSON-encoded permissions', + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE icinga_endpoint + ADD COLUMN apiuser_id INT(10) UNSIGNED DEFAULT NULL, + ADD CONSTRAINT icinga_apiuser + FOREIGN KEY apiuser (apiuser_id) + REFERENCES icinga_apiuser (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + diff --git a/schema/mysql.sql b/schema/mysql.sql index c7c7cecc..ad08c833 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -320,6 +320,16 @@ CREATE TABLE icinga_command_var ( ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE icinga_apiuser ( + id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, + object_name VARCHAR(255) NOT NULL, + object_type ENUM('object', 'template', 'external_object') NOT NULL, + password VARCHAR(255) DEFAULT NULL, + client_dn VARCHAR(64) DEFAULT NULL, + permissions TEXT DEFAULT NULL COMMENT 'JSON-encoded permissions', + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE icinga_endpoint ( id INT(10) UNSIGNED AUTO_INCREMENT NOT NULL, zone_id INT(10) UNSIGNED DEFAULT NULL, @@ -328,12 +338,18 @@ CREATE TABLE icinga_endpoint ( port SMALLINT UNSIGNED DEFAULT NULL COMMENT '5665 if not set', log_duration VARCHAR(32) DEFAULT NULL COMMENT '1d if not set', object_type ENUM('object', 'template', 'external_object') NOT NULL, + apiuser_id INT(10) UNSIGNED DEFAULT NULL, PRIMARY KEY (id), UNIQUE INDEX object_name (object_name), CONSTRAINT icinga_endpoint_zone FOREIGN KEY zone (zone_id) REFERENCES icinga_zone (id) ON DELETE RESTRICT + ON UPDATE CASCADE, + CONSTRAINT icinga_apiuser + FOREIGN KEY apiuser (apiuser_id) + REFERENCES icinga_apiuser (id) + ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;