Skip to content

Commit 68aa0d5

Browse files
committed
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.
1 parent b930783 commit 68aa0d5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

DependencyInjection/MonologExtension.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,25 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
236236
} else {
237237
// elastica client new definition
238238
$elasticaClient = new Definition('%monolog.elastica.client.class%');
239+
$elasticaClientArguments = array(
240+
'host' => $handler['elasticsearch']['host'],
241+
'port' => $handler['elasticsearch']['port'],
242+
'transport' => $handler['elasticsearch']['transport'],
243+
);
244+
245+
if (isset($handler['elasticsearch']['user']) && isset($handler['elasticsearch']['password'])) {
246+
$elasticaClientArguments = array_merge(
247+
$elasticaClientArguments,
248+
array(
249+
'headers' => array(
250+
'Authorization ' => 'Basic ' . base64_encode($handler['elasticsearch']['user'] . ':' . $handler['elasticsearch']['password'])
251+
)
252+
)
253+
);
254+
}
255+
239256
$elasticaClient->setArguments(array(
240-
array(
241-
'host' => $handler['elasticsearch']['host'],
242-
'port' => $handler['elasticsearch']['port'],
243-
),
257+
$elasticaClientArguments
244258
));
245259

246260
$clientId = uniqid('monolog.elastica.client.');

0 commit comments

Comments
 (0)