From 68aa0d5237eb8fa9aa6631ca54ea436339a1299a Mon Sep 17 00:00:00 2001 From: daml Date: Fri, 30 Oct 2015 17:15:09 +0100 Subject: [PATCH 1/3] Allow authentication against protected Elasticsearch server. Add options transport, user and password for Elasticsearch client. Allow to authenticate against a SSL and login/password protected Elasticsearch server with Shield. --- DependencyInjection/MonologExtension.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index 3a4ec01a..65f1e783 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -236,11 +236,25 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler } else { // elastica client new definition $elasticaClient = new Definition('%monolog.elastica.client.class%'); + $elasticaClientArguments = array( + 'host' => $handler['elasticsearch']['host'], + 'port' => $handler['elasticsearch']['port'], + 'transport' => $handler['elasticsearch']['transport'], + ); + + if (isset($handler['elasticsearch']['user']) && isset($handler['elasticsearch']['password'])) { + $elasticaClientArguments = array_merge( + $elasticaClientArguments, + array( + 'headers' => array( + 'Authorization ' => 'Basic ' . base64_encode($handler['elasticsearch']['user'] . ':' . $handler['elasticsearch']['password']) + ) + ) + ); + } + $elasticaClient->setArguments(array( - array( - 'host' => $handler['elasticsearch']['host'], - 'port' => $handler['elasticsearch']['port'], - ), + $elasticaClientArguments )); $clientId = uniqid('monolog.elastica.client.'); From f9cc82e6015e15b66fcc7ff9174bf9a385bc55be Mon Sep 17 00:00:00 2001 From: daml Date: Fri, 30 Oct 2015 17:16:40 +0100 Subject: [PATCH 2/3] Add options transport, user and password for Elasticsearch handler. --- DependencyInjection/Configuration.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e679f674..6aba0861 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -409,6 +409,9 @@ public function getConfigTreeBuilder() ->scalarNode('id')->end() ->scalarNode('host')->end() ->scalarNode('port')->defaultValue(9200)->end() + ->scalarNode('transport')->defaultValue('http')->end() + ->scalarNode('user')->defaultNull()->end() + ->scalarNode('password')->defaultNull()->end() ->end() ->validate() ->ifTrue(function ($v) { From 1025c6d02008ae6949eb91fc4897810c10e5388f Mon Sep 17 00:00:00 2001 From: daml Date: Fri, 30 Oct 2015 21:02:59 +0100 Subject: [PATCH 3/3] Add options transport, user and password for Elasticsearch handler. --- Resources/config/schema/monolog-1.0.xsd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Resources/config/schema/monolog-1.0.xsd b/Resources/config/schema/monolog-1.0.xsd index aa3f1ff4..90d564b9 100644 --- a/Resources/config/schema/monolog-1.0.xsd +++ b/Resources/config/schema/monolog-1.0.xsd @@ -141,5 +141,8 @@ + + +