Merge pull request #496 from rayrigam/master

Add support for clients requiring basic HTTP authentication
This commit is contained in:
Tim Nagel 2014-03-19 12:32:48 +11:00
commit 514e63f26f
5 changed files with 28 additions and 2 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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,
)
)
);
@ -100,6 +101,7 @@ class Configuration implements ConfigurationInterface
->children()
->arrayNode('servers')
->prototype('array')
->fixXmlConfig('header')
->children()
->scalarNode('url')
->validate()
@ -114,6 +116,10 @@ class Configuration implements ConfigurationInterface
->treatNullLike('fos_elastica.logger')
->treatTrueLike('fos_elastica.logger')
->end()
->arrayNode('headers')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->scalarNode('timeout')->end()
->end()
->end()

View file

@ -48,7 +48,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())

View file

@ -58,6 +58,24 @@ 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=="
A client configuration can also override the Elastica logger to change the used class ```logger: <your logger class>``` or to simply disable it ```logger: false```. Disabling the logger should be done on production because it can cause a memory leak.
#### Declare a serializer