Skip to content
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

Added support for credentials and disable ssl verification for local development #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="KERNEL_DIR" value="tests/Fixtures/app/"/>
<server name="KERNEL_CLASS" value="AppKernel"/>
<server name="ACTIVITY_LOGS_ELASTIC_URL" value="https://localhost:9200"/>
<server name="ACTIVITY_LOGS_ELASTIC_USER" value="my_user"/>
<server name="ACTIVITY_LOGS_ELASTIC_PASSWORD" value="my_password"/>
<server name="ACTIVITY_LOGS_ELASTIC_SSL_VERIFICATION" value="0"/>
</php>
<testsuites>
<testsuite name="Project Test Suite">
Expand Down
17 changes: 14 additions & 3 deletions src/Bridge/Elasticsearch/ElasticsearchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
9 changes: 9 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions src/DependencyInjection/LocasticLoggasticExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/elastic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/app/config/packages/loggastic.yaml
Original file line number Diff line number Diff line change
@@ -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'
Loading