-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for basic auth and api key in combi with cloud id
- Loading branch information
Showing
5 changed files
with
135 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
use Elasticsearch\Serializers\SerializerInterface; | ||
use Elasticsearch\ConnectionPool\Selectors; | ||
use Elasticsearch\Serializers\SmartSerializer; | ||
use Elasticsearch\Helper\ElasticCloudIdParser; | ||
use GuzzleHttp\Ring\Client\CurlHandler; | ||
use GuzzleHttp\Ring\Client\CurlMultiHandler; | ||
use GuzzleHttp\Ring\Client\Middleware; | ||
|
@@ -372,23 +373,43 @@ public function setConnectionParams(array $params): ClientBuilder | |
} | ||
|
||
/** | ||
* Set Elastic Cloud's best Practices Connection Parameters | ||
* Set Elastic Cloud ID to connect to Elastic Cloud | ||
* | ||
* <i>Add custom/additional Params as parameter</i> | ||
* <b>No authentication is provided</b> | ||
* | ||
* @param array $additional | ||
* - set Hostname | ||
* - set best practices for the connection | ||
* | ||
* @param string $cloudId | ||
* @param string $username, optional if using Basic Authentication | ||
* @param string $password, optional if using Basic Authentication | ||
* | ||
* @throws Elasticsearch\Common\Exceptions\ElasticCloudIdParseException | ||
*/ | ||
public function setElasticCloudConnectionParams(array $additional = []) | ||
public function setElasticCloudId(string $cloudId, ?string $username = null, ?string $password = null) | ||
{ | ||
$this->setConnectionParams( | ||
$cloud = new ElasticCloudIdParser($cloudId); | ||
$hosts = [ | ||
[ | ||
'client' => [ | ||
'curl' => [ | ||
CURLOPT_ENCODING => 1, | ||
], | ||
] | ||
] + $additional | ||
); | ||
'host' => $cloud->getClusterDns(), | ||
'port' => '', | ||
'scheme' => 'https', | ||
'user' => $username, | ||
'pass' => $password, | ||
] | ||
]; | ||
|
||
// Register the Hosts array | ||
$this->setHosts($hosts); | ||
|
||
// Merge best practices for the connection | ||
$this->setConnectionParams([ | ||
'client' => [ | ||
'curl' => [ | ||
CURLOPT_ENCODING => 1, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
philkra
Author
Contributor
|
||
], | ||
] | ||
]); | ||
|
||
return $this; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,15 @@ | |
use Elasticsearch\Common\Exceptions\ElasticCloudIdParseException; | ||
|
||
/** | ||
* Class ElasticCloudHelper | ||
* Class ElasticCloudIdParser | ||
* | ||
* @category Elasticsearch | ||
* @package Elasticsearch\Helper | ||
* @author Philip Krauss <[email protected]> | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2 | ||
* @link http://elastic.co | ||
*/ | ||
class ElasticCloudHelper | ||
class ElasticCloudIdParser | ||
{ | ||
|
||
/** | ||
|
@@ -35,11 +35,6 @@ class ElasticCloudHelper | |
*/ | ||
private $clusterDns; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $basicAuth = []; | ||
|
||
/** | ||
* @param string $cloudId | ||
*/ | ||
|
@@ -79,40 +74,6 @@ public function getClusterDns(): string | |
return $this->clusterDns; | ||
} | ||
|
||
/** | ||
* Get Elastic Cloud Host Array | ||
* | ||
* @link https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/configuration.html#_extended_host_configuration | ||
* | ||
* @return array | ||
*/ | ||
public function getHost(): array | ||
{ | ||
return [ | ||
[ | ||
'host' => $this->clusterDns, | ||
'port' => '', | ||
'scheme' => 'https', | ||
] + $this->basicAuth | ||
]; | ||
} | ||
|
||
/** | ||
* Set the Basic Authentication Credentials | ||
* | ||
* @param string $username | ||
* @param string $password | ||
* | ||
* @return void | ||
*/ | ||
public function setBasicAuthentication(string $username, string $password): void | ||
{ | ||
$this->basicAuth = [ | ||
'user' => $username, | ||
'pass' => $password, | ||
]; | ||
} | ||
|
||
/** | ||
* Parse the Elastic Cloud Params from the CloudId | ||
* | ||
|
157 changes: 0 additions & 157 deletions
157
tests/Elasticsearch/Tests/Helper/ElasticCloudHelperTest.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
I didn't find any information about
CURLOPT_ENCODING = 1
, what value is it, e.g.gzip
?