From 48e95ee581d128394c9a92b566e4ad42cf29802b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 14 Apr 2020 02:24:52 +0000 Subject: [PATCH] Add .env variable and checking of variable when logging API events. #374 --- .env.dist | 3 +++ config/services.yaml | 5 +++++ src/EventSubscriber/LogSubscriber.php | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/.env.dist b/.env.dist index 831c5f98..b6766d67 100644 --- a/.env.dist +++ b/.env.dist @@ -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 diff --git a/config/services.yaml b/config/services.yaml index d3d6bd5a..4bfaf95a 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -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)%" diff --git a/src/EventSubscriber/LogSubscriber.php b/src/EventSubscriber/LogSubscriber.php index e17d5406..1f62f577 100644 --- a/src/EventSubscriber/LogSubscriber.php +++ b/src/EventSubscriber/LogSubscriber.php @@ -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;