Skip to content

Commit 9c42e91

Browse files
committed
Adds support for HTTPS transport, SSL, and Authentication
1 parent 794aa50 commit 9c42e91

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ ELASTICSEARCH_HOST=localhost
106106
ELASTICSEARCH_PORT=9200
107107
ELASTICSEARCH_INDEX=vue_storefront_catalog
108108
109+
// Set transport value to "https" and ssl to "true" when using an ssl connection
110+
ELASTICSEARCH_TRANSPORT=http
111+
ELASTICSEARCH_SSL=false
112+
// Leave blank if authentication is not required
113+
ELASTICSEARCH_USERNAME=
114+
ELASTICSEARCH_PASSWORD=
115+
109116
// Optionally, when using Nelmio CORS Bundle
110117
CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
111118
```

src/Controller/Catalog/GetCatalogAction.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,50 @@ final class GetCatalogAction
3232
/** @var int */
3333
private $port;
3434

35-
public function __construct(ViewHandlerInterface $viewHandler, string $host, int $port)
35+
/** @var string */
36+
private $transport;
37+
38+
/** @var bool */
39+
private $ssl;
40+
41+
/** @var int */
42+
private $username;
43+
44+
/** @var string */
45+
private $password;
46+
47+
public function __construct(
48+
ViewHandlerInterface $viewHandler,
49+
string $host,
50+
int $port,
51+
string $transport,
52+
bool $ssl,
53+
string $username,
54+
string $password
55+
)
3656
{
3757
$this->host = $host;
3858
$this->port = $port;
59+
$this->transport = $transport;
60+
$this->ssl = $ssl;
61+
$this->username = $username;
62+
$this->password = $password;
3963
$this->viewHandler = $viewHandler;
4064
}
4165

4266
public function __invoke(Request $request): Response
4367
{
4468
$client = new Client();
45-
$client->addConnection(new Connection(['host' => $this->host, 'port' => $this->port]));
69+
$connection = new Connection([
70+
'host' => $this->host,
71+
'port' => $this->port,
72+
'transport' => $this->transport,
73+
'ssl' => $this->ssl,
74+
'username' => $this->username,
75+
'password' => $this->password
76+
]);
77+
78+
$client->addConnection($connection);
4679

4780
$index = $request->attributes->get('index');
4881
$type = $request->attributes->get('type');

src/Resources/config/services/api/catalog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<argument type="service" id="fos_rest.view_handler" />
1515
<argument>%env(ELASTICSEARCH_HOST)%</argument>
1616
<argument>%env(ELASTICSEARCH_PORT)%</argument>
17+
<argument>%env(ELASTICSEARCH_TRANSPORT)%</argument>
18+
<argument>%env(ELASTICSEARCH_SSL)%</argument>
19+
<argument>%env(ELASTICSEARCH_USERNAME)%</argument>
20+
<argument>%env(ELASTICSEARCH_PASSWORD)%</argument>
1721
</service>
1822
</services>
1923
</container>

0 commit comments

Comments
 (0)