Add option to disable API via configuration setting

This commit is contained in:
Thibaud Fabre
2016-09-26 17:32:44 +02:00
parent 154c2616a7
commit c13e086120
4 changed files with 25 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ main:
maintenance: false maintenance: false
languages: [] languages: []
key: '' key: ''
api_disable: false
api_require_ssl: true api_require_ssl: true
api_disabled: true api_disabled: true
database: database:

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Api;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Api\OAuth2Controller; use Alchemy\Phrasea\Controller\Api\OAuth2Controller;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Silex\Application; use Silex\Application;
use Silex\ControllerCollection; use Silex\ControllerCollection;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
@@ -34,6 +35,13 @@ class OAuth2 implements ControllerProviderInterface, ServiceProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
/** @var PropertyAccess $config */
$config = $app['conf'];
if ($config->get('api_disable', false) == true) {
return $app['controllers_factory'];
}
/** @var ControllerCollection $controllers */ /** @var ControllerCollection $controllers */
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Api;
use Alchemy\Phrasea\Application as PhraseaApplication; use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Api\V1Controller; use Alchemy\Phrasea\Controller\Api\V1Controller;
use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Core\Event\Listener\OAuthListener; use Alchemy\Phrasea\Core\Event\Listener\OAuthListener;
use Silex\Application; use Silex\Application;
use Silex\ControllerCollection; use Silex\ControllerCollection;
@@ -46,6 +47,13 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
/** @var PropertyAccess $config */
$config = $app['conf'];
if ($config->get('api_disable', false) == true) {
return $app['controllers_factory'];
}
/** @var ControllerCollection $controllers */ /** @var ControllerCollection $controllers */
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Controller\Api\LazaretController;
use Alchemy\Phrasea\Controller\Api\SearchController; use Alchemy\Phrasea\Controller\Api\SearchController;
use Alchemy\Phrasea\Controller\LazyLocator; use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Core\Event\Listener\OAuthListener; use Alchemy\Phrasea\Core\Event\Listener\OAuthListener;
use Alchemy\Phrasea\Order\Controller\ApiOrderController; use Alchemy\Phrasea\Order\Controller\ApiOrderController;
use Silex\Application; use Silex\Application;
@@ -70,6 +71,13 @@ class V2 implements ControllerProviderInterface, ServiceProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
/** @var PropertyAccess $config */
$config = $app['conf'];
if ($config->get('api_disable', false) == true) {
return $app['controllers_factory'];
}
$controllers = $this->createCollection($app); $controllers = $this->createCollection($app);
$controllers->before(new OAuthListener()); $controllers->before(new OAuthListener());