Skip to content

Commit 82ddab0

Browse files
committed
Merge pull request #39 from robertlemke/http-basic-auth
[FEATURE] Support username / password for SaaS Elasticsearch This change adds the two new client settings options "username" and "password" which allows for setting credentials being integrated into the request URL when accessing Elasticsearch instances protected by HTTP Basic Auth.
2 parents 9735f94 + e2f2ca0 commit 82ddab0

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

Classes/Flowpack/ElasticSearch/Domain/Model/Client/ClientConfiguration.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ class ClientConfiguration
3333
*/
3434
protected $scheme = 'http';
3535

36+
/**
37+
* @var string
38+
*/
39+
protected $username = '';
40+
41+
/**
42+
* @var string
43+
*/
44+
protected $password = '';
45+
3646
/**
3747
* @param string $host
3848
*/
@@ -81,6 +91,48 @@ public function getScheme()
8191
return $this->scheme;
8292
}
8393

94+
/**
95+
* Returns username
96+
*
97+
* @return string
98+
*/
99+
public function getUsername()
100+
{
101+
return $this->username;
102+
}
103+
104+
/**
105+
* Sets username
106+
*
107+
* @param string $username
108+
* @return void
109+
*/
110+
public function setUsername($username)
111+
{
112+
$this->username = $username;
113+
}
114+
115+
/**
116+
* Returns password
117+
*
118+
* @return string
119+
*/
120+
public function getPassword()
121+
{
122+
return $this->password;
123+
}
124+
125+
/**
126+
* Sets password
127+
*
128+
* @param string $password
129+
* @return void
130+
*/
131+
public function setPassword($password)
132+
{
133+
$this->password = $password;
134+
}
135+
84136
/**
85137
* @return \TYPO3\Flow\Http\Uri
86138
*/
@@ -90,6 +142,8 @@ public function getUri()
90142
$uri->setScheme($this->scheme);
91143
$uri->setHost($this->host);
92144
$uri->setPort($this->port);
145+
$uri->setUsername($this->username);
146+
$uri->setPassword($this->password);
93147

94148
return $uri;
95149
}

Classes/Flowpack/ElasticSearch/Transfer/RequestService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public function request($method, \Flowpack\ElasticSearch\Domain\Model\Client $cl
6969
$uri->setPath($uri->getPath() . $path);
7070
}
7171

72+
if ($uri->getUsername()) {
73+
$requestEngine = $this->browser->getRequestEngine();
74+
$requestEngine->setOption(CURLOPT_USERPWD, $uri->getUsername() . ':' . $uri->getPassword() );
75+
$requestEngine->setOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
76+
}
77+
7278
$response = $this->browser->request($uri, $method, $arguments, array(), array(),
7379
is_array($content) ? json_encode($content) : $content);
7480

Configuration/Settings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Flowpack:
55
default:
66
- host: localhost
77
port: 9200
8+
username: ''
9+
password: ''
810

911
realtimeIndexing:
1012
enabled: TRUE

Documentation/Index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ have a dedicated server (recommended) for running the Functional Tests, set it u
3333

3434
During runtime, you have to provide the client's name you want to connect to, if it is not `default`.
3535

36+
When access to the Elasticsearch instance is protected through HTTP Basic Auth, you can provide the necessary username
37+
and password in your client settings::
38+
39+
Flowpack:
40+
ElasticSearch:
41+
clients:
42+
# default bundle that will be used if no more specific bundle name was supplied.
43+
default:
44+
- host: localhost
45+
port: 9200
46+
username: john
47+
password: mysecretpassword
48+
3649
Running the Functional Tests
3750
============================
3851

0 commit comments

Comments
 (0)