Add support for clients requiring basic HTTP authentication
This commit is contained in:
parent
245732781b
commit
0116a6ac4f
4 changed files with 26 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
17
README.md
17
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue