Skip to content

Commit 5683686

Browse files
authored
Merge pull request #105 from medteck/https-ssl-authentication
Adds support for HTTPS transport, SSL, and Authentication #104
2 parents a42e3ed + bf9b07c commit 5683686

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,14 @@ ELASTICSEARCH_HOST=localhost
114114
ELASTICSEARCH_PORT=9200
115115
ELASTICSEARCH_INDEX=vue_storefront_catalog
116116
117-
# Optionally, when using Nelmio CORS Bundle
117+
// Set transport value to "https" and ssl to "true" when using an ssl connection
118+
ELASTICSEARCH_TRANSPORT=http
119+
ELASTICSEARCH_SSL=false
120+
// Leave blank if authentication is not required
121+
ELASTICSEARCH_USERNAME=
122+
ELASTICSEARCH_PASSWORD=
123+
124+
// Optionally, when using Nelmio CORS Bundle
118125
CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
119126
```
120127

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)