Open fmarchalemisys opened 2 years ago
As far as I can tell, dbrumann's PR fix the same issue but only for the level.
I'm faced with the issue on the user name and password.
I have the same issue.
In the meantime you can register a CompilerPass to fix this:
<?php
declare(strict_types=1);
namespace App\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use function array_merge;
use function base64_encode;
class MonologElasticFixingCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$configs = $container->getExtensionConfig('monolog');
$config = array_merge(...$configs);
if (!isset($config['handlers'])) {
return;
}
foreach ($config['handlers'] as $name => $handler) {
if (isset($handler['elasticsearch']['id'])) {
continue;
}
if (!isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) {
continue;
}
$definition = $container->getDefinition('monolog.handler.' . $name);
/** @var Definition $clientDefinition */
$clientDefinition = $definition->getArgument(0);
$arg = $container->resolveEnvPlaceholders($clientDefinition->getArgument(0), true);
/** @noinspection SlowArrayOperationsInLoopInspection */
$arg = array_merge($arg, [
'headers' => [
'Authorization' => 'Basic ' . base64_encode($container->resolveEnvPlaceholders($handler['elasticsearch']['user'], true) . ':' . $container->resolveEnvPlaceholders($handler['elasticsearch']['password'], true))
],
]);
$clientDefinition->setArgument(0, $arg);
}
}
}
Note that this will compile all the Elastica Client arguments into your Container, which might change behavior slightly (changing env vars without rebuilding the container will not change the actual connection arguments), and it also exposes the hostname, port (and password, but that is true if you directly use the config as well) in the built container.
(Sorry for posting this for like the third time, I managed to botch the code before).
This is not working in
monolog.yaml
:The error message is
It works if the user and password are used in plain instead of environment variables.
Dumping the two variables here shows:
I believe the Authorization string should be build using:
Or am I missing something?