Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
feat(acl): export ACLs
Browse files Browse the repository at this point in the history
Refs: #13
  • Loading branch information
loiclau authored and kduret committed Jul 12, 2018
1 parent a115c83 commit b0ada4e
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/en/Presentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ solution. It also allows not to use WAN interconnections for example.
This interface is not compatible with poller which receives data from
many pollers.

.. warning::
Warning version 1.6 uses a new ACLs management system.
All ACLs initially created on the Centreon Poller Display interface will be removed.
Only the contacts ACLs related to objects supervised by the collector will be synchronized.


Centreon Poller Display allows to build the following architecture:

.. image :: /images/eschema.png
Expand Down
5 changes: 5 additions & 0 deletions doc/fr/Presentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ interface peut être également utilisée comme solution de secours. Cela permet
Cette interface n'est pas compatible avec un poller recevant les données
collectés de plusieurs pollers.

.. warning::
Attention la version 1.6 utilise un nouveau système de gestion des ACLs.
Toutes les ACLs initialement créées sur l'interface Centreon Poller Display vont être supprimées.
Seules les ACLs des contacts liés à des objets supervisés par le collecteur seront synchronisées.

Centreon Poller Display permet alors de mettre en place l’architecture suivante :

.. image :: /images/eschema.png
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/**
* Copyright 2016 Centreon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use \Centreon\Test\Mock\CentreonDB;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclTopologyRelation;


/**
* @package centreon-poller-display-central
* @version 1.0.0
* @author Centreon
*/
class CentreonPollerDisplayCentral_AclTopologyRelation extends PHPUnit_Framework_TestCase
{
protected static $db;
protected static $pollerDisplay;
protected static $acl;
protected static $objectListIn;
protected static $objectListOut;

public function setUp()
{
self::$db = new CentreonDB();
self::$pollerDisplay = 1;
self::$acl = new AclTopologyRelation(self::$db, self::$pollerDisplay);
self::$objectListIn = array(
array(
'acl_topo_id' => '1',
'acl_topo_name' => 'toto'
),
array(
'acl_topo_id' => '4',
'acl_topo_name' => 'tutu'
)
);
self::$objectListOut = array(
array(
'topology_topology_id' => '2',
'acl_topo_id' => '1'
),
array(
'topology_topology_id' => '3',
'acl_topo_id' => '4'
)
);


}

public function tearDown()
{
self::$db = null;
}

public function testGetList()
{
self::$db->addResultSet(
'SELECT * FROM acl_topology_relations WHERE acl_topo_id IN (1,4)',
array(
array(
'topology_topology_id' => '2',
'acl_topo_id' => '1'
),
array(
'topology_topology_id' => '3',
'acl_topo_id' => '4'
)
)
);

$sql = self::$acl->getList(self::$objectListIn);
$this->assertEquals($sql, self::$objectListOut);
}

public function testGenerateSql()
{
self::$db->addResultSet(
'SELECT topology_name, topology_page FROM topology WHERE topology_id = 2',
array(
array(
'topology_page' => '20',
'topology_name' => 'toto'
)
)
);
self::$db->addResultSet(
'SELECT topology_name, topology_page FROM topology WHERE topology_id = 3',
array(
array(
'topology_page' => '30',
'topology_name' => 'tutu'
)
)
);

$expectedResult = 'DELETE FROM acl_topology_relations;
TRUNCATE acl_topology_relations;
INSERT INTO `acl_topology_relations` (`topology_topology_id`,`acl_topo_id`)
SELECT (SELECT topology_id FROM topology WHERE topology_name = "toto" AND topology_page = "20"),\'1\'
WHERE (SELECT topology_id FROM topology WHERE topology_name = "toto" AND topology_page = "20");
INSERT INTO `acl_topology_relations` (`topology_topology_id`,`acl_topo_id`)
SELECT (SELECT topology_id FROM topology WHERE topology_name = "tutu" AND topology_page = "30"),\'4\'
WHERE (SELECT topology_id FROM topology WHERE topology_name = "tutu" AND topology_page = "30");
';

$sql = self::$acl->generateSql(self::$objectListOut);
$this->assertEquals($sql, $expectedResult);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* Copyright 2016 Centreon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use \Centreon\Test\Mock\CentreonDB;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclTopology;


/**
* @package centreon-poller-display-central
* @version 1.0.0
* @author Centreon
*/
class CentreonPollerDisplayCentral_AclTopology extends PHPUnit_Framework_TestCase
{
protected static $db;
protected static $pollerDisplay;
protected static $acl;
protected static $objectListIn;
protected static $objectListOut;

public function setUp()
{
self::$db = new CentreonDB();
self::$pollerDisplay = 1;
self::$acl = new AclTopology(self::$db, self::$pollerDisplay);
self::$objectListIn = array(
array(
'agt_id' => '1',
'acl_group_id' => '1',
'acl_topology_id' => '1'
),
array(
'agt_id' => '2',
'acl_group_id' => '3',
'acl_topology_id' => '4'
)
);

self::$objectListOut = array(
array(
'acl_topo_id' => '1',
'acl_topo_name' => 'toto'
),
array(
'acl_topo_id' => '4',
'acl_topo_name' => 'tutu'
)
);
}

public function tearDown()
{
self::$db = null;
}

public function testGetList()
{
self::$db->addResultSet(
'SELECT * FROM acl_topology WHERE acl_topo_id IN (1,4)',
array(
array(
'acl_topo_id' => '1',
'acl_topo_name' => 'toto'
),
array(
'acl_topo_id' => '4',
'acl_topo_name' => 'tutu'
)
)
);

$sql = self::$acl->getList(self::$objectListIn);
$this->assertEquals($sql, self::$objectListOut);
}

public function testGenerateSql()
{

$expectedResult = 'DELETE FROM acl_topology;
TRUNCATE acl_topology;
INSERT INTO `acl_topology` (`acl_topo_id`,`acl_topo_name`) VALUES (\'1\',\'toto\'),(\'4\',\'tutu\');';

$sql = self::$acl->generateSql(self::$objectListOut);
$this->assertEquals($sql, $expectedResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclGroupContactgroupsRelation;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclGroupContactsRelation;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclGroupTopology;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclTopology;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclTopologyRelation;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclGroups;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclResources;
use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclResourcesGroupRelation;
Expand Down Expand Up @@ -117,6 +119,8 @@ public function generateObjects($poller_id)
$oAclGroupContactgroupsRelation = new AclGroupContactgroupsRelation($db, $poller_id);
$oAclGroupContactsRelation = new AclGroupContactsRelation($db, $poller_id);
$oAclGroupTopology = new AclGroupTopology($db, $poller_id);
$oAclTopology = new AclTopology($db, $poller_id);
$oAclTopologyRelation = new AclTopologyRelation($db, $poller_id);
$oAclGroups = new AclGroups($db, $poller_id);
$oAclResources = new AclResources($db, $poller_id);
$oAclResourcesGroupRelation = new AclResourcesGroupRelation($db, $poller_id);
Expand Down Expand Up @@ -159,8 +163,9 @@ public function generateObjects($poller_id)
$oServicegroup = new Servicegroup($db, $poller_id);
$oServicegroupRelation = new ServicegroupRelation($db, $poller_id);


$sql = '';
$sql .= $this->setForeignKey(0). "\n\n";
$sql .= $this->setForeignKey(0) . "\n\n";

$nagiosServerList = $oNagiosServer->getList();
$sql .= $oNagiosServer->generateSql($nagiosServerList) . "\n\n";
Expand Down Expand Up @@ -288,6 +293,12 @@ public function generateObjects($poller_id)
$aclGroupTopologyList = $oAclGroupTopology->getList($aclGroupsList);
$sql .= $oAclGroupTopology->generateSql($aclGroupTopologyList) . "\n\n";

$aclTopologyList = $oAclTopology->getList($aclGroupTopologyList);
$sql .= $oAclTopology->generateSql($aclTopologyList) . "\n\n";

$aclTopologyRelationList = $oAclTopologyRelation->getList($aclTopologyList);
$sql .= $oAclTopologyRelation->generateSql($aclTopologyRelationList) . "\n\n";

$aclGroupActionsRelationList = $oAclGroupActionsRelation->getList($aclGroupsList);
$sql .= $oAclGroupActionsRelation->generateSql($aclGroupActionsRelationList) . "\n\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,22 @@ public function getList($clauseContactObject = null, $clauseContactgObject = nul

return $list;
}

/**
*
* @param type $objects
* @return string
*/
protected function generateInsertQuery($objects)
{
foreach ($objects as &$object) {
foreach ($object as $key => &$value) {
if ($key == "acl_group_changed") {
$value = 1;
}
}
}

return parent::generateInsertQuery($objects);
}
}
Loading

0 comments on commit b0ada4e

Please sign in to comment.