33namespace PDPhilip \Elasticsearch ;
44
55use PDPhilip \Elasticsearch \DSL \Bridge ;
6- use Elastic \ Elasticsearch \ClientBuilder ;
6+ use Elasticsearch \ClientBuilder ;
77use Illuminate \Database \Connection as BaseConnection ;
88use Illuminate \Support \Arr ;
99use Illuminate \Support \Str ;
@@ -142,15 +142,15 @@ protected function buildConnection()
142142 {
143143 $ type = config ('database.connections.elasticsearch.auth_type ' ) ?? null ;
144144 $ type = strtolower ($ type );
145- if (!in_array ($ type , ['https ' , 'cloud ' ,])) {
145+ if (!in_array ($ type , ['http ' , 'cloud ' , ' api ' ])) {
146146 throw new RuntimeException ('Invalid [auth_type] in database config. Must be: http, cloud or api ' );
147147 }
148148
149149 return $ this ->{'_ ' .$ type .'Connection ' }();
150150
151151 }
152152
153- protected function _httpsConnection ()
153+ protected function _httpConnection ()
154154 {
155155 $ hosts = config ('database.connections.elasticsearch.hosts ' ) ?? null ;
156156 $ username = config ('database.connections.elasticsearch.username ' ) ?? null ;
@@ -161,7 +161,7 @@ protected function _httpsConnection()
161161 $ cb ->setBasicAuthentication ($ username , $ pass )->build ();
162162 }
163163 if ($ certPath ) {
164- $ cb ->setCABundle ($ certPath );
164+ $ cb ->setSSLVerification ($ certPath );
165165 }
166166
167167 return $ cb ->build ();
@@ -177,7 +177,7 @@ protected function _cloudConnection()
177177 $ certPath = config ('database.connections.elasticsearch.ssl_cert ' ) ?? null ;
178178 $ cb = ClientBuilder::create ()->setElasticCloudId ($ cloudId );
179179 if ($ apiId && $ apiKey ) {
180- $ cb ->setApiKey ($ apiKey , $ apiId )->build ();
180+ $ cb ->setApiKey ($ apiId , $ apiKey )->build ();
181181 } elseif ($ username && $ pass ) {
182182 $ cb ->setBasicAuthentication ($ username , $ pass )->build ();
183183 }
@@ -189,6 +189,20 @@ protected function _cloudConnection()
189189 }
190190
191191
192+ protected function _apiConnection ()
193+ {
194+ $ apiId = config ('database.connections.elasticsearch.api_id ' ) ?? null ;
195+ $ apiKey = config ('database.connections.elasticsearch.api_key ' ) ?? null ;
196+ $ certPath = config ('database.connections.elasticsearch.ssl_cert ' ) ?? null ;
197+ $ cb = ClientBuilder::create ()->setApiKey ($ apiId , $ apiKey );
198+ if ($ certPath ) {
199+ $ cb ->setSSLVerification ($ certPath );
200+ }
201+
202+ return $ cb ->build ();
203+ }
204+
205+
192206 //----------------------------------------------------------------------
193207 // Dynamic call routing to DSL bridge
194208 //----------------------------------------------------------------------
0 commit comments