@@ -26,9 +26,13 @@ class Connection extends BaseConnection
2626 protected $ rebuild = false ;
2727 protected $ allowIdSort = true ;
2828 protected $ errorLoggingIndex = false ;
29+ protected $ connectionName = 'opensearch ' ;
2930
3031 public function __construct (array $ config )
3132 {
33+
34+ $ this ->connectionName = $ config ['name ' ];
35+
3236 $ this ->config = $ config ;
3337
3438 $ this ->setOptions ($ config );
@@ -202,7 +206,7 @@ public function getAllowIdSort()
202206
203207 protected function buildConnection (): Client
204208 {
205- $ hosts = config ('database.connections.opensearch .hosts ' ) ?? null ;
209+ $ hosts = config ('database.connections. ' . $ this -> connectionName . ' .hosts ' ) ?? null ;
206210
207211 $ builder = ClientBuilder::create ()->setHosts ($ hosts );
208212 $ builder = $ this ->_buildOptions ($ builder );
@@ -217,8 +221,8 @@ protected function buildConnection(): Client
217221 protected function _buildAuth (ClientBuilder $ builder ): ClientBuilder
218222 {
219223
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 ;
222226 if ($ username && $ pass ) {
223227 $ builder ->setBasicAuthentication ($ username , $ pass );
224228 }
@@ -228,9 +232,9 @@ protected function _buildAuth(ClientBuilder $builder): ClientBuilder
228232
229233 protected function _buildSigV4 (ClientBuilder $ builder ): ClientBuilder
230234 {
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 ;
234238 if ($ provider ) {
235239 $ builder ->setSigV4CredentialProvider ($ provider );
236240 }
@@ -246,10 +250,10 @@ protected function _buildSigV4(ClientBuilder $builder): ClientBuilder
246250
247251 protected function _buildSSL (ClientBuilder $ builder ): ClientBuilder
248252 {
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 ;
253257 if ($ sslCert ) {
254258 $ builder ->setSSLCert ($ sslCert , $ sslCertPassword );
255259 }
0 commit comments