-
-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Env var not usable with elasticsearch user and password #426
Comments
this may fix the issue here check on dbrumann solution. |
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?
The text was updated successfully, but these errors were encountered: