Fix remaining references to DbUserBackend and refresh the documentation.
refs #4786
This commit is contained in:
parent
ea5daf964b
commit
59d4baff0b
|
@ -31,7 +31,7 @@ namespace Icinga\Form\Config\Authentication;
|
|||
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form\Decorator\HelpText;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
use \Icinga\Web\Form;
|
||||
|
||||
/**
|
||||
|
@ -121,7 +121,7 @@ abstract class BaseBackendForm extends Form
|
|||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null) {
|
||||
return DbAdapterFactory::getResources();
|
||||
return ResourceFactory::getResourceConfigs()->toArray();
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Zend_Config;
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,10 +29,11 @@
|
|||
|
||||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Icinga\Authentication\Backend\LdapUserBackend;
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Authentication\Backend\LdapUserBackend;
|
||||
use \Icinga\Protocol\Ldap\Connection as LdapConnection;
|
||||
|
||||
/**
|
||||
* Form for adding or modifying LDAP authentication backends
|
||||
|
@ -182,8 +183,9 @@ class LdapBackendForm extends BaseBackendForm
|
|||
try {
|
||||
$cfg = $this->getConfig();
|
||||
$backendName = 'backend_' . $this->filterName($this->getBackendName()) . '_name';
|
||||
$backendConfig = new Zend_Config($cfg[$this->getValue($backendName)]);
|
||||
$testConn = new LdapUserBackend(
|
||||
new Zend_Config($cfg[$this->getValue($backendName)])
|
||||
new LdapConnection($backendConfig), $backendConfig
|
||||
);
|
||||
|
||||
if ($testConn->getUserCount() === 0) {
|
||||
|
|
|
@ -35,7 +35,7 @@ use \Zend_Form_Element_Text;
|
|||
use \Zend_Form_Element_Select;
|
||||
use \Zend_View_Helper_DateFormat;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Web\Form\Validator\WritablePathValidator;
|
||||
use \Icinga\Web\Form\Validator\TimeFormatValidator;
|
||||
|
@ -132,7 +132,7 @@ class GeneralForm extends Form
|
|||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null) {
|
||||
return DbAdapterFactory::getResources();
|
||||
return ResourceFactory::getResourceConfigs()->toArray();
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
|
|
106
doc/resources.md
106
doc/resources.md
|
@ -9,13 +9,49 @@ place, avoiding the need to edit several different files, when the connection in
|
|||
Each section represents a resource, with the section name being the identifier used to
|
||||
reference this certain section. Depending on the resource type, each section contains different properties.
|
||||
The property *type* defines the resource type and thus how the properties are going to be interpreted.
|
||||
Currently only the resource type *db* is available.
|
||||
The available resource types are 'db', 'statusdat', 'livestatus' and 'ldap' and are
|
||||
described in detail in the following sections:
|
||||
|
||||
### db
|
||||
|
||||
This resource type describes a SQL database. The property *db* defines the used database vendor, which
|
||||
could be a value like *mysql* or *pgsql*. The other properties like *host*, *password*, *username* and
|
||||
*dbname* are the connection information for the resource.
|
||||
This resource type describes a SQL database on an SQL server. Databases can contain users and groups
|
||||
to handle authentication and permissions, or monitoring data using IDO.
|
||||
|
||||
- *db*: defines the used database vendor, which could be a value like *mysql* or *pgsql*.
|
||||
- *host*: The hostname that is used to connect to the database.
|
||||
- *port*: The port that is used to connect to the database.
|
||||
- *username*: The user name that is used to authenticate.
|
||||
- *password*: The password of the user given in *username*.
|
||||
- *dbname*: The name of the database that contains the resources data.
|
||||
|
||||
### ldap
|
||||
|
||||
The resource is a tree in a ldap domain. This resource type is usually used to fetch users and groups
|
||||
to handle authentication and permissions.
|
||||
|
||||
- *hostname*: The hostname that is used to connect to the ldap server.
|
||||
- *port*: The port that is used to connect to the ldap server.
|
||||
- *root_dn*: The root object of the tree. This is usually an organizational unit like
|
||||
"ou=people, dc=icinga, dc=org".
|
||||
- *bind_dn*: The user on the LDAP server that will be used to access it. Usually something
|
||||
like "cn=admin, cn=config".
|
||||
- *bind_pw*: The password of the user given in *bind_dn*.
|
||||
|
||||
|
||||
### livestatus
|
||||
|
||||
A resource that points to a livestatus socket. This resource type contains monitoring data.
|
||||
|
||||
- *socket*: The livestatus socket. Can be either be a path to a domain socket (like
|
||||
"/usr/local/icinga-mysql/var/rw/live") or to a TCP socket like
|
||||
(tcp://<domain>:<port>)
|
||||
|
||||
### statusdat
|
||||
|
||||
A resource that points to statusdat files. This resource type contains monitoring data.
|
||||
|
||||
- *status_file*: The path to the *status.dat* file, like "/usr/local/icinga-mysql/var/status.dat"
|
||||
- *object_file*: The path to *objects.cache*, like "/usr/local/icinga-mysql/var/objects.cache"
|
||||
|
||||
|
||||
## Factory Implementations
|
||||
|
@ -26,53 +62,35 @@ factory class, that can be used to comfortably create instances of classes that
|
|||
to the data of the resources.
|
||||
|
||||
|
||||
### DbAdapterFactory
|
||||
### ResourceFactory
|
||||
|
||||
The DbAdapterFactory can be used to retrieve instances of Zend_Db_Adapter_Abstract for accessing
|
||||
the data of the SQL database.
|
||||
The ResourceFactory can be used to retrieve objects to access resources. Lets assume
|
||||
for the following examples, that we have an *resources.ini* that looks like this:
|
||||
|
||||
Lets assume for the following examples, that we have an *resources.ini* that looks like this:
|
||||
[statusdat]
|
||||
type = statusdat
|
||||
status_file = /usr/local/icinga-mysql/var/status.dat
|
||||
object_file = /usr/local/icinga-mysql/var/objects.cache
|
||||
|
||||
[resource1]
|
||||
type = "db"
|
||||
db = "mysql"
|
||||
dbname = "resource1"
|
||||
host = "host"
|
||||
username = "username1"
|
||||
password = "password1"
|
||||
|
||||
[resource2]
|
||||
type = "db"
|
||||
db = "pgsql"
|
||||
dbname = "resource2"
|
||||
host = "host"
|
||||
username = "username2"
|
||||
password = "password2"
|
||||
|
||||
[resource3]
|
||||
type = "other"
|
||||
foo = "foo"
|
||||
bar = "bar"
|
||||
[ldap_authentication]
|
||||
type = "ldap"
|
||||
hostname = "localhost"
|
||||
port = "389"
|
||||
root_dn = "ou=people, dc=icinga, dc=org"
|
||||
bind_dn = "cn=admin, cn=config"
|
||||
bind_pw = "admin"
|
||||
|
||||
|
||||
In the most simple use-case you can create an adapter by calling the
|
||||
*getDbAdapter* function. The created adapter will be an instance of
|
||||
Zend_Db_Adapter_Pdo_Mysql
|
||||
|
||||
$adapter = DbAdapterFactory::getDbAdapter('resource1');
|
||||
Here is an example of how to retrieve the resource 'statusdat' from the factory.
|
||||
|
||||
$resource = ResourceFactory::createResource(
|
||||
ResourceFactory::getResourceConfig('statusdat')
|
||||
);
|
||||
|
||||
If you specify a resource that does not exist or has the wrong type,
|
||||
the factory will throw an ConfigurationException. You can make sure
|
||||
a resource exists and has the right type, by calling the function *resourceExists*:
|
||||
|
||||
if (DbAdapterFactory::resourceExists('resource3')) {
|
||||
$adapter = DbAdapterFactory::getDbAdapter('resource3');
|
||||
} else {
|
||||
// This returned false, because resource3 has a different type than "db"
|
||||
echo 'resource does not exist, adapter could not be created...'
|
||||
}
|
||||
the factory will throw an ConfigurationException.
|
||||
|
||||
|
||||
You can retrieve a list of all available resources by calling *getResources*. You will
|
||||
get an array of all resources that have the type 'db'.
|
||||
You can also retrieve a list of all available resources by calling *getResourceConfigs*.
|
||||
|
||||
$resourceConfigs = ResourceFactory::getResourceConfigs();
|
||||
|
|
|
@ -50,19 +50,60 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
self::$resources = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration for a specific resource
|
||||
*
|
||||
* @param $resourceName String The resources name
|
||||
*
|
||||
* @return Zend_Config The configuration of the resource
|
||||
* @throws \Icinga\Exception\ConfigurationError
|
||||
*/
|
||||
public static function getResourceConfig($resourceName)
|
||||
{
|
||||
if (!isset(self::$resources)) {
|
||||
throw new ProgrammingError(
|
||||
"The ResourceFactory must be initialised by setting a config, before it can be used"
|
||||
);
|
||||
}
|
||||
self::assertResourcesExist();
|
||||
if (($resourceConfig = self::$resources->get($resourceName)) === null) {
|
||||
throw new ConfigurationError('Resource "' . $resourceName . '" couldn\'t be retrieved');
|
||||
}
|
||||
return $resourceConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configuration of all existing resources.
|
||||
*
|
||||
* @return Zend_Config The configuration containing all resources
|
||||
*/
|
||||
public static function getResourceConfigs()
|
||||
{
|
||||
self::assertResourcesExist();
|
||||
return self::$resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the existing resources are set. If not, throw an error.
|
||||
*
|
||||
* @throws \Icinga\Exception\ProgrammingError
|
||||
*/
|
||||
private static function assertResourcesExist()
|
||||
{
|
||||
if (!isset(self::$resources)) {
|
||||
throw new ProgrammingError(
|
||||
"The ResourceFactory must be initialised by setting a config, before it can be used"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a single resource from the given configuration.
|
||||
*
|
||||
* NOTE: The factory does not test if the given configuration is valid and the resource is accessible, this
|
||||
* depends entirely on the implementation of the returned resource.
|
||||
*
|
||||
* @param Zend_Config $config The configuration for the created resource.
|
||||
*
|
||||
* @return DbConnection|LdapConnection|LivestatusConnection|StatusdatReader An objects that can be used to access
|
||||
* the given resource. The returned class depends on the configuration property 'type'.
|
||||
* @throws \Icinga\Exception\ConfigurationError When an unsupported type is given
|
||||
*/
|
||||
public static function createResource(Zend_Config $config)
|
||||
{
|
||||
switch (strtolower($config->type)) {
|
||||
|
@ -80,7 +121,6 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
break;
|
||||
default:
|
||||
throw new ConfigurationError('Unsupported resource type "' . $config->type . '"');
|
||||
|
||||
}
|
||||
return $resource;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ namespace Icinga\Test {
|
|||
use Zend_Db_Adapter_Pdo_Mysql;
|
||||
use Zend_Db_Adapter_Pdo_Pgsql;
|
||||
use Zend_Db_Adapter_Pdo_Oci;
|
||||
use Icinga\Application\DbAdapterFactory;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Web\Form;
|
||||
|
@ -113,7 +112,7 @@ namespace Icinga\Test {
|
|||
public static $moduleDir;
|
||||
|
||||
/**
|
||||
* DbAdapterFactory configuration for different database types
|
||||
* Resource configuration for different database types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -210,7 +209,6 @@ namespace Icinga\Test {
|
|||
$this->requireDbLibraries();
|
||||
|
||||
try {
|
||||
//$adapter = DbAdapterFactory::createDbAdapter($this->createDbConfigFor($name));
|
||||
$adapter = ResourceFactory::createResource($this->createDbConfigFor($name))->getConnection();
|
||||
} catch (Exception $e) {
|
||||
$adapter = $e->getMessage();
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Icinga\User\Preferences;
|
|||
use \Zend_Config;
|
||||
use \Icinga\User;
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
|
||||
/**
|
||||
* Create preference stores from zend config
|
||||
|
@ -75,7 +75,7 @@ final class StoreFactory
|
|||
$items = $config->toArray();
|
||||
|
||||
if ($items['type'] == 'db') {
|
||||
$items['dbAdapter'] = DbAdapterFactory::getDbAdapter($items['resource']);
|
||||
$items['dbAdapter'] = ResourceFactory::createResource($items['resource']);
|
||||
}
|
||||
unset($items['type']);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Icinga\Module\Monitoring\Form\Config\Backend;
|
|||
use \Zend_Config;
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
||||
/**
|
||||
* Form for modifying a monitoring backend
|
||||
|
@ -40,7 +40,7 @@ use \Icinga\Application\DbAdapterFactory;
|
|||
class EditBackendForm extends Form
|
||||
{
|
||||
/**
|
||||
* Database resources to use instead of the one's from DBAdapterFactory (used for testing)
|
||||
* Database resources to use instead of the one's from ResourceFactory (used for testing)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -82,7 +82,7 @@ class EditBackendForm extends Form
|
|||
}
|
||||
|
||||
/**
|
||||
* Set a custom array of resources to be used in this form instead of the ones from DbAdapterFactory
|
||||
* Set a custom array of resources to be used in this form instead of the ones from ResourceFactory
|
||||
* (used for testing)
|
||||
*/
|
||||
public function setResources($resources)
|
||||
|
@ -98,7 +98,7 @@ class EditBackendForm extends Form
|
|||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null) {
|
||||
return DbAdapterFactory::getResources();
|
||||
return ResourceFactory::getResourceConfigs()->toArray();
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ use \Zend_Config;
|
|||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use \Icinga\Protocol\Statusdat\Reader;
|
||||
use \Icinga\Web\Controller\ActionController;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
use \Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
|
|
|
@ -56,7 +56,6 @@ use \PDO;
|
|||
use \Zend_Db_Adapter_Pdo_Abstract;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||
use \Icinga\Application\DbAdapterFactory;
|
||||
use \Icinga\Authentication\Credential;
|
||||
use \Icinga\User;
|
||||
use \Icinga\Application\Config;
|
||||
|
|
Loading…
Reference in New Issue