Skip to content

Commit 9bbe0dc

Browse files
committed
added basic auth config
1 parent 64dee24 commit 9bbe0dc

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/ClientProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public function init(): void
2626
$settings->host() . ':' . $settings->port(),
2727
],
2828
);
29+
30+
if ($settings->username() !== null && $settings->password() !== null) {
31+
$this->clientBuilder->setBasicAuthentication(
32+
$settings->username(),
33+
$settings->password(),
34+
);
35+
}
2936
}
3037

3138

src/DI/SpameriElasticSearchExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public function setConfigOptions(
5757
$neonSettingsProvider = $services['services']['neonSettingsProvider']['factory'];
5858
$neonSettingsProvider->arguments[0] = $config['host'];
5959
$neonSettingsProvider->arguments[1] = $config['port'];
60+
$neonSettingsProvider->arguments[2] = $config['username'] ?? null;
61+
$neonSettingsProvider->arguments[3] = $config['password'] ?? null;
6062

6163
$versionProvider = $services['services']['versionProvider']['factory'];
6264
$versionProvider->arguments[0] = $config['version'];

src/Settings.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
public function __construct(
1212
private string $host,
1313
private int $port,
14+
private string|null $username,
15+
private string|null $password,
1416
private array $headers,
1517
)
1618
{
@@ -29,6 +31,18 @@ public function port(): int
2931
}
3032

3133

34+
public function username(): string|null
35+
{
36+
return $this->username;
37+
}
38+
39+
40+
public function password(): string|null
41+
{
42+
return $this->password;
43+
}
44+
45+
3246
/**
3347
* @return array<mixed>
3448
*/

src/Settings/NeonSettingsProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
public function __construct(
1212
private string $host,
1313
private int $port,
14+
private string|null $username,
15+
private string|null $password,
1416
private array $headers = [],
1517
)
1618
{
@@ -22,6 +24,8 @@ public function provide(): \Spameri\Elastic\Settings
2224
return new \Spameri\Elastic\Settings(
2325
$this->host,
2426
$this->port,
27+
$this->username,
28+
$this->password,
2529
$this->headers,
2630
);
2731
}

0 commit comments

Comments
 (0)