Add .env variable and checking of variable when logging API events. #374
This commit is contained in:
parent
32b4c8546d
commit
48e95ee581
3 changed files with 20 additions and 0 deletions
|
|
@ -63,3 +63,6 @@ INVENTORY_API_URL=insert_api_url_here
|
|||
INVENTORY_API_OCP=insert_ocp_text_here
|
||||
INVENTORY_API_AUTH_TOKEN_PREFIX=Bearer
|
||||
INVENTORY_API_AUTH_TOKEN=insert_auth_token_here
|
||||
|
||||
# API logging
|
||||
API_LOGGING=set_to_true_or_false
|
||||
|
|
|
|||
|
|
@ -234,3 +234,8 @@ services:
|
|||
$api_ocp_key: "%env(INVENTORY_API_OCP)%"
|
||||
$api_auth_prefix: "%env(INVENTORY_API_AUTH_TOKEN_PREFIX)%"
|
||||
$api_auth_token: "%env(INVENTORY_API_AUTH_TOKEN)%"
|
||||
|
||||
# API logging
|
||||
App\EventSubscriber\LogSubscriber:
|
||||
arguments:
|
||||
$api_log_flag: "%env(API_LOGGING)%"
|
||||
|
|
|
|||
|
|
@ -12,9 +12,18 @@ use Symfony\Component\HttpKernel\KernelEvents;
|
|||
class LogSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
protected $allow;
|
||||
protected $api_log_flag;
|
||||
|
||||
public function __construct($api_log_flag)
|
||||
{
|
||||
$this->api_log_flag = $api_log_flag;
|
||||
}
|
||||
|
||||
public function onKernelController(ControllerEvent $event)
|
||||
{
|
||||
if ($this->api_log_flag == 'false')
|
||||
return;
|
||||
|
||||
$controller = $event->getController();
|
||||
$this->allow = false;
|
||||
|
||||
|
|
@ -40,6 +49,9 @@ class LogSubscriber implements EventSubscriberInterface
|
|||
|
||||
public function onKernelResponse(ResponseEvent $event)
|
||||
{
|
||||
if ($this->api_log_flag == 'false')
|
||||
return;
|
||||
|
||||
if (!$this->allow)
|
||||
return;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue