diff --git a/.env.dist b/.env.dist
new file mode 100644
index 0000000..35227f9
--- /dev/null
+++ b/.env.dist
@@ -0,0 +1,5 @@
+APP_SECRET=your_test_secret
+ACTIVITY_LOGS_ELASTIC_URL=https://localhost:9200
+ACTIVITY_LOGS_ELASTIC_USER=my_user
+ACTIVITY_LOGS_ELASTIC_PASSWORD=my_password
+ACTIVITY_LOGS_ELASTIC_SSL_VERIFICATION=0
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index da43e2d..82268c1 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -9,6 +9,10 @@
+
+
+
+
diff --git a/src/Bridge/Elasticsearch/ElasticsearchClient.php b/src/Bridge/Elasticsearch/ElasticsearchClient.php
index 05a9ed8..2481c63 100644
--- a/src/Bridge/Elasticsearch/ElasticsearchClient.php
+++ b/src/Bridge/Elasticsearch/ElasticsearchClient.php
@@ -7,12 +7,23 @@
final class ElasticsearchClient
{
- public function __construct(private readonly string $activityLogElasticHost)
- {
+ public function __construct(
+ private readonly string $activityLogElasticHost,
+ private readonly ?string $activityLogElasticUser = null,
+ private readonly ?string $activityLogElasticPassword = null,
+ private readonly bool $activityLogElasticUseSSLVerification = true,
+ ) {
}
public function getClient(): Client
{
- return ClientBuilder::create()->setHosts([$this->activityLogElasticHost])->build();
+ $client = ClientBuilder::create()->setHosts([$this->activityLogElasticHost])
+ ->setSSLVerification($this->activityLogElasticUseSSLVerification);
+
+ if ($this->activityLogElasticUser !== null && $this->activityLogElasticPassword !== null) {
+ $client->setBasicAuthentication($this->activityLogElasticUser, $this->activityLogElasticPassword);
+ }
+
+ return $client->build();
}
}
diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php
index a6eb5f6..d457c16 100644
--- a/src/DependencyInjection/Configuration.php
+++ b/src/DependencyInjection/Configuration.php
@@ -35,6 +35,15 @@ public function getConfigTreeBuilder(): TreeBuilder
->cannotBeEmpty()
->defaultValue('http://localhost:9200')
->end()
+ ->scalarNode('elastic_user')
+ ->defaultValue(null)
+ ->end()
+ ->scalarNode('elastic_password')
+ ->defaultValue(null)
+ ->end()
+ ->scalarNode('elastic_ssl_verification')
+ ->defaultValue(true)
+ ->end()
->arrayNode('loggable_paths')
->prototype('scalar')->end()
->end()
diff --git a/src/DependencyInjection/LocasticLoggasticExtension.php b/src/DependencyInjection/LocasticLoggasticExtension.php
index bf6676d..259913b 100644
--- a/src/DependencyInjection/LocasticLoggasticExtension.php
+++ b/src/DependencyInjection/LocasticLoggasticExtension.php
@@ -35,6 +35,9 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('locastic_activity_log.identifier_extractor', $config['identifier_extractor'] ?? true);
$container->setParameter('locastic_activity_log.elasticsearch_host', $config['elastic_host']);
+ $container->setParameter('locastic_activity_log.elasticsearch_user', $config['elastic_user']);
+ $container->setParameter('locastic_activity_log.elasticsearch_password', $config['elastic_password']);
+ $container->setParameter('locastic_activity_log.elasticsearch_ssl_verification', $config['elastic_ssl_verification']);
$container->setParameter('locastic_activity_log.elastic_date_detection', $config['elastic_date_detection']);
$container->setParameter('locastic_activity_log.elastic_dynamic_date_formats', $config['elastic_dynamic_date_formats']);
diff --git a/src/Resources/config/elastic.yaml b/src/Resources/config/elastic.yaml
index a9161b4..900b761 100644
--- a/src/Resources/config/elastic.yaml
+++ b/src/Resources/config/elastic.yaml
@@ -2,6 +2,9 @@ services:
Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchClient:
arguments:
$activityLogElasticHost: '%locastic_activity_log.elasticsearch_host%'
+ $activityLogElasticUser: '%locastic_activity_log.elasticsearch_user%'
+ $activityLogElasticPassword: '%locastic_activity_log.elasticsearch_password%'
+ $activityLogElasticUseSSLVerification: '%locastic_activity_log.elasticsearch_ssl_verification%'
Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService:
arguments:
diff --git a/tests/Fixtures/app/config/packages/loggastic.yaml b/tests/Fixtures/app/config/packages/loggastic.yaml
index b06eafc..c8577b4 100644
--- a/tests/Fixtures/app/config/packages/loggastic.yaml
+++ b/tests/Fixtures/app/config/packages/loggastic.yaml
@@ -1,5 +1,8 @@
locastic_loggastic:
-# elastic_host: "%env(ACTIVITY_LOGS_ELASTIC_URL)%"
+ elastic_host: "%env(ACTIVITY_LOGS_ELASTIC_URL)%"
+ elastic_user: "%env(ACTIVITY_LOGS_ELASTIC_USER)%"
+ elastic_password: "%env(ACTIVITY_LOGS_ELASTIC_PASSWORD)%"
+ elastic_ssl_verification: "%env(ACTIVITY_LOGS_ELASTIC_SSL_VERIFICATION)%"
loggable_paths:
- '%kernel.project_dir%/Resources'
- '%kernel.project_dir%/Model'