From 0116a6ac4f88da2210660c0e6ca55515b0450656 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 6 Mar 2014 12:38:23 -0430 Subject: [PATCH 1/3] Add support for clients requiring basic HTTP authentication --- Client.php | 1 + DependencyInjection/Configuration.php | 8 +++++++- Logger/ElasticaLogger.php | 2 +- README.md | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Client.php b/Client.php index 7719095..601fc77 100644 --- a/Client.php +++ b/Client.php @@ -25,6 +25,7 @@ class Client extends ElasticaClient 'host' => $connection->getHost(), 'port' => $connection->getPort(), 'transport' => $connection->getTransport(), + 'headers' => $connection->getConfig('headers'), ); $this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 4488bf2..a01d1cb 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -78,7 +78,8 @@ class Configuration implements ConfigurationInterface array( 'host' => $v['host'], 'port' => $v['port'], - 'logger' => isset($v['logger']) ? $v['logger'] : null + 'logger' => isset($v['logger']) ? $v['logger'] : null, + 'headers' => isset($v['headers']) ? $v['headers'] : null, ) ) ); @@ -114,6 +115,11 @@ class Configuration implements ConfigurationInterface ->treatNullLike('fos_elastica.logger') ->treatTrueLike('fos_elastica.logger') ->end() + ->arrayNode('headers') + ->children() + ->scalarNode('Authorization')->end() + ->end() + ->end() ->scalarNode('timeout')->end() ->end() ->end() diff --git a/Logger/ElasticaLogger.php b/Logger/ElasticaLogger.php index 0e0a9c0..85acf70 100644 --- a/Logger/ElasticaLogger.php +++ b/Logger/ElasticaLogger.php @@ -38,7 +38,7 @@ class ElasticaLogger implements LoggerInterface * @param string $method Rest method to use (GET, POST, DELETE, PUT) * @param array $data arguments * @param float $time execution time - * @param array $connection host, port and transport of the query + * @param array $connection host, port, transport and headers of the query * @param array $query arguments */ public function logQuery($path, $method, $data, $time, $connection = array(), $query = array()) diff --git a/README.md b/README.md index f78c97f..cd1a1ba 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,23 @@ Most of the time, you will need only one. clients: default: { host: localhost, port: 9200 } +If your client requires Basic HTTP Authentication, you can specify an Authorization Header to +include in HTTP requests. The Authorization Header value is a ``base64`` encoded string that +includes the authentication username and password, and can be obtained by running the following +command in your terminal: + + php -r "Print 'Basic ' . base64_encode('your_auth_username' . ':' . 'your_auth_password');" + +A sample configuration with Basic HTTP Authentication is: + + #app/config/config.yml + fos_elastica: + clients: + default: + host: example.com + port: 80 + headers: + Authorization: "Basic jdumrGK7rY9TMuQOPng7GZycmxyMHNoir==" #### Declare a serializer From de70e78b5370f6f9f014351e3169dfb035ed8415 Mon Sep 17 00:00:00 2001 From: rayrigam Date: Tue, 18 Mar 2014 18:14:03 -0430 Subject: [PATCH 2/3] Update Configuration.php Updated to support any HTTP request header type in the "headers" section. --- DependencyInjection/Configuration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a01d1cb..d629ea6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -101,6 +101,7 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('servers') ->prototype('array') + ->fixXmlConfig('header') ->children() ->scalarNode('url') ->validate() @@ -116,9 +117,8 @@ class Configuration implements ConfigurationInterface ->treatTrueLike('fos_elastica.logger') ->end() ->arrayNode('headers') - ->children() - ->scalarNode('Authorization')->end() - ->end() + ->useAttributeAsKey('name') + ->prototype('scalar')->end() ->end() ->scalarNode('timeout')->end() ->end() From 4dc08cd006f3260411d7bb26e74c61ec6268d959 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 18 Mar 2014 20:07:30 -0430 Subject: [PATCH 3/3] Added notice about added support for HTTP headers. --- CHANGELOG-3.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-3.0.md b/CHANGELOG-3.0.md index a80d09d..fd2ecd5 100644 --- a/CHANGELOG-3.0.md +++ b/CHANGELOG-3.0.md @@ -17,6 +17,7 @@ To generate a changelog summary since the last version, run * #463: allowing hot swappable reindexing * #415: BC BREAK: document indexing occurs in postFlush rather than the pre* events previously. * 7d13823: Dropped (broken) support for Symfony <2.3 + * #496: Added support for HTTP headers * 3.0.0-ALPHA2 (2014-03-17)