Skip to content

Commit 64c6944

Browse files
committed
Merge pull request #142 from damien-list/master
Allow authentication against protected Elasticsearch server
2 parents 4b7adf9 + 1025c6d commit 64c6944

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

DependencyInjection/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ public function getConfigTreeBuilder()
412412
->scalarNode('id')->end()
413413
->scalarNode('host')->end()
414414
->scalarNode('port')->defaultValue(9200)->end()
415+
->scalarNode('transport')->defaultValue('http')->end()
416+
->scalarNode('user')->defaultNull()->end()
417+
->scalarNode('password')->defaultNull()->end()
415418
->end()
416419
->validate()
417420
->ifTrue(function ($v) {

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.');

Resources/config/schema/monolog-1.0.xsd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,8 @@
144144
<xsd:attribute name="id" type="xsd:string" />
145145
<xsd:attribute name="host" type="xsd:string" />
146146
<xsd:attribute name="port" type="xsd:integer" />
147+
<xsd:attribute name="transport" type="xsd:string" />
148+
<xsd:attribute name="user" type="xsd:string" />
149+
<xsd:attribute name="password" type="xsd:string" />
147150
</xsd:complexType>
148151
</xsd:schema>

0 commit comments

Comments
 (0)