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