@@ -26,9 +26,13 @@ class Connection extends BaseConnection
26
26
protected $ rebuild = false ;
27
27
protected $ allowIdSort = true ;
28
28
protected $ errorLoggingIndex = false ;
29
+ protected $ connectionName = 'opensearch ' ;
29
30
30
31
public function __construct (array $ config )
31
32
{
33
+
34
+ $ this ->connectionName = $ config ['name ' ];
35
+
32
36
$ this ->config = $ config ;
33
37
34
38
$ this ->setOptions ($ config );
@@ -202,7 +206,7 @@ public function getAllowIdSort()
202
206
203
207
protected function buildConnection (): Client
204
208
{
205
- $ hosts = config ('database.connections.opensearch .hosts ' ) ?? null ;
209
+ $ hosts = config ('database.connections. ' . $ this -> connectionName . ' .hosts ' ) ?? null ;
206
210
207
211
$ builder = ClientBuilder::create ()->setHosts ($ hosts );
208
212
$ builder = $ this ->_buildOptions ($ builder );
@@ -217,8 +221,8 @@ protected function buildConnection(): Client
217
221
protected function _buildAuth (ClientBuilder $ builder ): ClientBuilder
218
222
{
219
223
220
- $ username = config ('database.connections.opensearch .basic_auth.username ' ) ?? null ;
221
- $ pass = config ('database.connections.opensearch .basic_auth.password ' ) ?? null ;
224
+ $ username = config ('database.connections. ' . $ this -> connectionName . ' .basic_auth.username ' ) ?? null ;
225
+ $ pass = config ('database.connections. ' . $ this -> connectionName . ' .basic_auth.password ' ) ?? null ;
222
226
if ($ username && $ pass ) {
223
227
$ builder ->setBasicAuthentication ($ username , $ pass );
224
228
}
@@ -228,9 +232,9 @@ protected function _buildAuth(ClientBuilder $builder): ClientBuilder
228
232
229
233
protected function _buildSigV4 (ClientBuilder $ builder ): ClientBuilder
230
234
{
231
- $ provider = config ('database.connections.opensearch .sig_v4.provider ' ) ?? null ;
232
- $ region = config ('database.connections.opensearch .sig_v4.region ' ) ?? null ;
233
- $ service = config ('database.connections.opensearch .sig_v4.service ' ) ?? null ;
235
+ $ provider = config ('database.connections. ' . $ this -> connectionName . ' .sig_v4.provider ' ) ?? null ;
236
+ $ region = config ('database.connections. ' . $ this -> connectionName . ' .sig_v4.region ' ) ?? null ;
237
+ $ service = config ('database.connections. ' . $ this -> connectionName . ' .sig_v4.service ' ) ?? null ;
234
238
if ($ provider ) {
235
239
$ builder ->setSigV4CredentialProvider ($ provider );
236
240
}
@@ -246,10 +250,10 @@ protected function _buildSigV4(ClientBuilder $builder): ClientBuilder
246
250
247
251
protected function _buildSSL (ClientBuilder $ builder ): ClientBuilder
248
252
{
249
- $ sslCert = config ('database.connections.opensearch .ssl.cert ' ) ?? null ;
250
- $ sslCertPassword = config ('database.connections.opensearch .ssl.cert_password ' ) ?? null ;
251
- $ sslKey = config ('database.connections.opensearch .ssl.key ' ) ?? null ;
252
- $ sslKeyPassword = config ('database.connections.opensearch .ssl.key_password ' ) ?? null ;
253
+ $ sslCert = config ('database.connections. ' . $ this -> connectionName . ' .ssl.cert ' ) ?? null ;
254
+ $ sslCertPassword = config ('database.connections. ' . $ this -> connectionName . ' .ssl.cert_password ' ) ?? null ;
255
+ $ sslKey = config ('database.connections. ' . $ this -> connectionName . ' .ssl.key ' ) ?? null ;
256
+ $ sslKeyPassword = config ('database.connections. ' . $ this -> connectionName . ' .ssl.key_password ' ) ?? null ;
253
257
if ($ sslCert ) {
254
258
$ builder ->setSSLCert ($ sslCert , $ sslCertPassword );
255
259
}
0 commit comments